published on Wednesday, Jun 24, 2026 by Pulumi
published on Wednesday, Jun 24, 2026 by Pulumi
Provides a list of available Hetzner Cloud Datacenters.
This resource may be useful to create highly available infrastructure, distributed across several Datacenters.
The
hcloud.getDatacentersdata source is deprecated, and will be removed after 1 Oct. 2026. After this date, requests to the datacenters API endpoints will returnHTTP 410 Gone. Please use thehcloud.getLocationsdata source instead. See the changelog for more details.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as hcloud from "@pulumi/hcloud";
const all = hcloud.getDatacenters({});
const workers: hcloud.Server[] = [];
for (const range = {value: 0}; range.value < 5; range.value++) {
workers.push(new hcloud.Server(`workers-${range.value}`, {
name: `node${range.value}`,
image: "debian-12",
serverType: "cx23",
datacenter: all.then(all => all.datacenters)[range.value].name,
}));
}
import pulumi
from typing import Any
import pulumi_hcloud as hcloud
all = hcloud.get_datacenters()
workers: list[Any] = []
for range in [{"value": i} for i in range(0, 5)]:
workers.append(hcloud.Server(f"workers-{range['value']}",
name=f"node{range['value']}",
image="debian-12",
server_type="cx23",
datacenter=all.datacenters[range["value"]]["name"]))
package main
import (
"fmt"
"github.com/pulumi/pulumi-hcloud/sdk/go/hcloud"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
all, err := hcloud.GetDatacenters(ctx, map[string]interface{}{}, nil)
if err != nil {
return err
}
var workers []*hcloud.Server
for index := 0; index < 5; index++ {
key0 := index
val0 := index
__res, err := hcloud.NewServer(ctx, fmt.Sprintf("workers-%v", key0), &hcloud.ServerArgs{
Name: pulumi.Sprintf("node%v", val0),
Image: pulumi.String("debian-12"),
ServerType: pulumi.String("cx23"),
Datacenter: all.Datacenters[val0].Name,
})
if err != nil {
return err
}
workers = append(workers, __res)
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using HCloud = Pulumi.HCloud;
return await Deployment.RunAsync(() =>
{
var all = HCloud.GetDatacenters.Invoke();
var workers = new List<HCloud.Server>();
for (var rangeIndex = 0; rangeIndex < 5; rangeIndex++)
{
var range = new { Value = rangeIndex };
workers.Add(new HCloud.Server($"workers-{range.Value}", new()
{
Name = $"node{range.Value}",
Image = "debian-12",
ServerType = "cx23",
Datacenter = all.Apply(getDatacentersResult => getDatacentersResult.Datacenters)[range.Value].Name,
}));
}
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.hcloud.HcloudFunctions;
import com.pulumi.hcloud.Server;
import com.pulumi.hcloud.ServerArgs;
import com.pulumi.codegen.internal.KeyedValue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var all = HcloudFunctions.getDatacenters(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference);
for (var i = 0; i < 5; i++) {
new Server("workers-" + i, ServerArgs.builder()
.name(String.format("node%s", range.value()))
.image("debian-12")
.serverType("cx23")
.datacenter(all.datacenters()[range.value()].name())
.build());
}
}
}
Example coming soon!
pulumi {
required_providers {
hcloud = {
source = "pulumi/hcloud"
}
}
}
data "hcloud_getdatacenters" "all" {
}
resource "hcloud_server" "workers" {
count = 5
name ="node${count.index}"
image = "debian-12"
server_type = "cx23"
datacenter = element(data.hcloud_getdatacenters.all.datacenters, count.index).name
}
Using getDatacenters
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getDatacenters(opts?: InvokeOptions): Promise<GetDatacentersResult>
function getDatacentersOutput(opts?: InvokeOptions): Output<GetDatacentersResult>def get_datacenters(opts: Optional[InvokeOptions] = None) -> GetDatacentersResult
def get_datacenters_output(opts: Optional[InvokeOptions] = None) -> Output[GetDatacentersResult]func GetDatacenters(ctx *Context, opts ...InvokeOption) (*GetDatacentersResult, error)
func GetDatacentersOutput(ctx *Context, opts ...InvokeOption) GetDatacentersResultOutput> Note: This function is named GetDatacenters in the Go SDK.
public static class GetDatacenters
{
public static Task<GetDatacentersResult> InvokeAsync(InvokeOptions? opts = null)
public static Output<GetDatacentersResult> Invoke(InvokeOptions? opts = null)
}public static CompletableFuture<GetDatacentersResult> getDatacenters(InvokeOptions options)
public static Output<GetDatacentersResult> getDatacenters(InvokeOptions options)
fn::invoke:
function: hcloud:index/getDatacenters:getDatacenters
arguments:
# arguments dictionarydata "hcloud_getdatacenters" "name" {
# arguments
}getDatacenters Result
The following output properties are available:
- Datacenter
Ids List<string> - Datacenters
List<Pulumi.
HCloud. Outputs. Get Datacenters Datacenter> - Descriptions List<string>
- Id string
- The ID of this resource.
- Names List<string>
- Datacenter
Ids []string - Datacenters
[]Get
Datacenters Datacenter - Descriptions []string
- Id string
- The ID of this resource.
- Names []string
- datacenter_
ids list(string) - datacenters list(object)
- descriptions list(string)
- id string
- The ID of this resource.
- names list(string)
- datacenter
Ids List<String> - datacenters
List<Get
Datacenters Datacenter> - descriptions List<String>
- id String
- The ID of this resource.
- names List<String>
- datacenter
Ids string[] - datacenters
Get
Datacenters Datacenter[] - descriptions string[]
- id string
- The ID of this resource.
- names string[]
- datacenter_
ids Sequence[str] - datacenters
Sequence[Get
Datacenters Datacenter] - descriptions Sequence[str]
- id str
- The ID of this resource.
- names Sequence[str]
- datacenter
Ids List<String> - datacenters List<Property Map>
- descriptions List<String>
- id String
- The ID of this resource.
- names List<String>
Supporting Types
GetDatacentersDatacenter
- Available
Server List<int>Type Ids - List of currently available Server Types in the Datacenter.
- Description string
- Description of the Datacenter.
- Id int
- ID of the Datacenter.
- Location Dictionary<string, string>
- Location of the Datacenter. See the Hetzner Docs for more details about locations.
- Name string
- Name of the Datacenter.
- Supported
Server List<int>Type Ids - List of supported Server Types in the Datacenter.
- Available
Server []intType Ids - List of currently available Server Types in the Datacenter.
- Description string
- Description of the Datacenter.
- Id int
- ID of the Datacenter.
- Location map[string]string
- Location of the Datacenter. See the Hetzner Docs for more details about locations.
- Name string
- Name of the Datacenter.
- Supported
Server []intType Ids - List of supported Server Types in the Datacenter.
- available_
server_ list(number)type_ ids - List of currently available Server Types in the Datacenter.
- description string
- Description of the Datacenter.
- id number
- ID of the Datacenter.
- location map(string)
- Location of the Datacenter. See the Hetzner Docs for more details about locations.
- name string
- Name of the Datacenter.
- supported_
server_ list(number)type_ ids - List of supported Server Types in the Datacenter.
- available
Server List<Integer>Type Ids - List of currently available Server Types in the Datacenter.
- description String
- Description of the Datacenter.
- id Integer
- ID of the Datacenter.
- location Map<String,String>
- Location of the Datacenter. See the Hetzner Docs for more details about locations.
- name String
- Name of the Datacenter.
- supported
Server List<Integer>Type Ids - List of supported Server Types in the Datacenter.
- available
Server number[]Type Ids - List of currently available Server Types in the Datacenter.
- description string
- Description of the Datacenter.
- id number
- ID of the Datacenter.
- location {[key: string]: string}
- Location of the Datacenter. See the Hetzner Docs for more details about locations.
- name string
- Name of the Datacenter.
- supported
Server number[]Type Ids - List of supported Server Types in the Datacenter.
- available_
server_ Sequence[int]type_ ids - List of currently available Server Types in the Datacenter.
- description str
- Description of the Datacenter.
- id int
- ID of the Datacenter.
- location Mapping[str, str]
- Location of the Datacenter. See the Hetzner Docs for more details about locations.
- name str
- Name of the Datacenter.
- supported_
server_ Sequence[int]type_ ids - List of supported Server Types in the Datacenter.
- available
Server List<Number>Type Ids - List of currently available Server Types in the Datacenter.
- description String
- Description of the Datacenter.
- id Number
- ID of the Datacenter.
- location Map<String>
- Location of the Datacenter. See the Hetzner Docs for more details about locations.
- name String
- Name of the Datacenter.
- supported
Server List<Number>Type Ids - List of supported Server Types in the Datacenter.
Package Details
- Repository
- Hetzner Cloud pulumi/pulumi-hcloud
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
hcloudTerraform Provider.
published on Wednesday, Jun 24, 2026 by Pulumi