1. Packages
  2. Hcloud Provider
  3. API Docs
  4. ServerNetwork
Hetzner Cloud v1.22.0 published on Wednesday, Feb 26, 2025 by Pulumi

hcloud.ServerNetwork

Explore with Pulumi AI

Provides a Hetzner Cloud Server Network to represent a private network on a server in the Hetzner Cloud.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as hcloud from "@pulumi/hcloud";

const node1 = new hcloud.Server("node1", {
    name: "node1",
    image: "debian-11",
    serverType: "cx22",
});
const mynet = new hcloud.Network("mynet", {
    name: "my-net",
    ipRange: "10.0.0.0/8",
});
const foonet = new hcloud.NetworkSubnet("foonet", {
    networkId: mynet.id,
    type: "cloud",
    networkZone: "eu-central",
    ipRange: "10.0.1.0/24",
});
const srvnetwork = new hcloud.ServerNetwork("srvnetwork", {
    serverId: node1.id,
    networkId: mynet.id,
    ip: "10.0.1.5",
});
Copy
import pulumi
import pulumi_hcloud as hcloud

node1 = hcloud.Server("node1",
    name="node1",
    image="debian-11",
    server_type="cx22")
mynet = hcloud.Network("mynet",
    name="my-net",
    ip_range="10.0.0.0/8")
foonet = hcloud.NetworkSubnet("foonet",
    network_id=mynet.id,
    type="cloud",
    network_zone="eu-central",
    ip_range="10.0.1.0/24")
srvnetwork = hcloud.ServerNetwork("srvnetwork",
    server_id=node1.id,
    network_id=mynet.id,
    ip="10.0.1.5")
Copy
package main

import (
	"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 {
		node1, err := hcloud.NewServer(ctx, "node1", &hcloud.ServerArgs{
			Name:       pulumi.String("node1"),
			Image:      pulumi.String("debian-11"),
			ServerType: pulumi.String("cx22"),
		})
		if err != nil {
			return err
		}
		mynet, err := hcloud.NewNetwork(ctx, "mynet", &hcloud.NetworkArgs{
			Name:    pulumi.String("my-net"),
			IpRange: pulumi.String("10.0.0.0/8"),
		})
		if err != nil {
			return err
		}
		_, err = hcloud.NewNetworkSubnet(ctx, "foonet", &hcloud.NetworkSubnetArgs{
			NetworkId:   mynet.ID(),
			Type:        pulumi.String("cloud"),
			NetworkZone: pulumi.String("eu-central"),
			IpRange:     pulumi.String("10.0.1.0/24"),
		})
		if err != nil {
			return err
		}
		_, err = hcloud.NewServerNetwork(ctx, "srvnetwork", &hcloud.ServerNetworkArgs{
			ServerId:  node1.ID(),
			NetworkId: mynet.ID(),
			Ip:        pulumi.String("10.0.1.5"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using HCloud = Pulumi.HCloud;

return await Deployment.RunAsync(() => 
{
    var node1 = new HCloud.Server("node1", new()
    {
        Name = "node1",
        Image = "debian-11",
        ServerType = "cx22",
    });

    var mynet = new HCloud.Network("mynet", new()
    {
        Name = "my-net",
        IpRange = "10.0.0.0/8",
    });

    var foonet = new HCloud.NetworkSubnet("foonet", new()
    {
        NetworkId = mynet.Id,
        Type = "cloud",
        NetworkZone = "eu-central",
        IpRange = "10.0.1.0/24",
    });

    var srvnetwork = new HCloud.ServerNetwork("srvnetwork", new()
    {
        ServerId = node1.Id,
        NetworkId = mynet.Id,
        Ip = "10.0.1.5",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.hcloud.Server;
import com.pulumi.hcloud.ServerArgs;
import com.pulumi.hcloud.Network;
import com.pulumi.hcloud.NetworkArgs;
import com.pulumi.hcloud.NetworkSubnet;
import com.pulumi.hcloud.NetworkSubnetArgs;
import com.pulumi.hcloud.ServerNetwork;
import com.pulumi.hcloud.ServerNetworkArgs;
import java.util.List;
import java.util.ArrayList;
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) {
        var node1 = new Server("node1", ServerArgs.builder()
            .name("node1")
            .image("debian-11")
            .serverType("cx22")
            .build());

        var mynet = new Network("mynet", NetworkArgs.builder()
            .name("my-net")
            .ipRange("10.0.0.0/8")
            .build());

        var foonet = new NetworkSubnet("foonet", NetworkSubnetArgs.builder()
            .networkId(mynet.id())
            .type("cloud")
            .networkZone("eu-central")
            .ipRange("10.0.1.0/24")
            .build());

        var srvnetwork = new ServerNetwork("srvnetwork", ServerNetworkArgs.builder()
            .serverId(node1.id())
            .networkId(mynet.id())
            .ip("10.0.1.5")
            .build());

    }
}
Copy
resources:
  node1:
    type: hcloud:Server
    properties:
      name: node1
      image: debian-11
      serverType: cx22
  mynet:
    type: hcloud:Network
    properties:
      name: my-net
      ipRange: 10.0.0.0/8
  foonet:
    type: hcloud:NetworkSubnet
    properties:
      networkId: ${mynet.id}
      type: cloud
      networkZone: eu-central
      ipRange: 10.0.1.0/24
  srvnetwork:
    type: hcloud:ServerNetwork
    properties:
      serverId: ${node1.id}
      networkId: ${mynet.id}
      ip: 10.0.1.5
Copy

Create ServerNetwork Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new ServerNetwork(name: string, args: ServerNetworkArgs, opts?: CustomResourceOptions);
@overload
def ServerNetwork(resource_name: str,
                  args: ServerNetworkInitArgs,
                  opts: Optional[ResourceOptions] = None)

@overload
def ServerNetwork(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  server_id: Optional[int] = None,
                  alias_ips: Optional[Sequence[str]] = None,
                  ip: Optional[str] = None,
                  network_id: Optional[int] = None,
                  subnet_id: Optional[str] = None)
func NewServerNetwork(ctx *Context, name string, args ServerNetworkArgs, opts ...ResourceOption) (*ServerNetwork, error)
public ServerNetwork(string name, ServerNetworkArgs args, CustomResourceOptions? opts = null)
public ServerNetwork(String name, ServerNetworkArgs args)
public ServerNetwork(String name, ServerNetworkArgs args, CustomResourceOptions options)
type: hcloud:ServerNetwork
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. ServerNetworkArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. ServerNetworkInitArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. ServerNetworkArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. ServerNetworkArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. ServerNetworkArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var serverNetworkResource = new HCloud.ServerNetwork("serverNetworkResource", new()
{
    ServerId = 0,
    AliasIps = new[]
    {
        "string",
    },
    Ip = "string",
    NetworkId = 0,
    SubnetId = "string",
});
Copy
example, err := hcloud.NewServerNetwork(ctx, "serverNetworkResource", &hcloud.ServerNetworkArgs{
	ServerId: pulumi.Int(0),
	AliasIps: pulumi.StringArray{
		pulumi.String("string"),
	},
	Ip:        pulumi.String("string"),
	NetworkId: pulumi.Int(0),
	SubnetId:  pulumi.String("string"),
})
Copy
var serverNetworkResource = new ServerNetwork("serverNetworkResource", ServerNetworkArgs.builder()
    .serverId(0)
    .aliasIps("string")
    .ip("string")
    .networkId(0)
    .subnetId("string")
    .build());
Copy
server_network_resource = hcloud.ServerNetwork("serverNetworkResource",
    server_id=0,
    alias_ips=["string"],
    ip="string",
    network_id=0,
    subnet_id="string")
Copy
const serverNetworkResource = new hcloud.ServerNetwork("serverNetworkResource", {
    serverId: 0,
    aliasIps: ["string"],
    ip: "string",
    networkId: 0,
    subnetId: "string",
});
Copy
type: hcloud:ServerNetwork
properties:
    aliasIps:
        - string
    ip: string
    networkId: 0
    serverId: 0
    subnetId: string
Copy

ServerNetwork Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The ServerNetwork resource accepts the following input properties:

ServerId
This property is required.
Changes to this property will trigger replacement.
int
ID of the server.
AliasIps List<string>
Additional IPs to be assigned to this server.
Ip Changes to this property will trigger replacement. string
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
NetworkId Changes to this property will trigger replacement. int
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
SubnetId Changes to this property will trigger replacement. string
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
ServerId
This property is required.
Changes to this property will trigger replacement.
int
ID of the server.
AliasIps []string
Additional IPs to be assigned to this server.
Ip Changes to this property will trigger replacement. string
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
NetworkId Changes to this property will trigger replacement. int
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
SubnetId Changes to this property will trigger replacement. string
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
serverId
This property is required.
Changes to this property will trigger replacement.
Integer
ID of the server.
aliasIps List<String>
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. String
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
networkId Changes to this property will trigger replacement. Integer
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
subnetId Changes to this property will trigger replacement. String
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
serverId
This property is required.
Changes to this property will trigger replacement.
number
ID of the server.
aliasIps string[]
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. string
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
networkId Changes to this property will trigger replacement. number
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
subnetId Changes to this property will trigger replacement. string
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
server_id
This property is required.
Changes to this property will trigger replacement.
int
ID of the server.
alias_ips Sequence[str]
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. str
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
network_id Changes to this property will trigger replacement. int
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
subnet_id Changes to this property will trigger replacement. str
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
serverId
This property is required.
Changes to this property will trigger replacement.
Number
ID of the server.
aliasIps List<String>
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. String
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
networkId Changes to this property will trigger replacement. Number
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
subnetId Changes to this property will trigger replacement. String
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.

Outputs

All input properties are implicitly available as output properties. Additionally, the ServerNetwork resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
MacAddress string
Id string
The provider-assigned unique ID for this managed resource.
MacAddress string
id String
The provider-assigned unique ID for this managed resource.
macAddress String
id string
The provider-assigned unique ID for this managed resource.
macAddress string
id str
The provider-assigned unique ID for this managed resource.
mac_address str
id String
The provider-assigned unique ID for this managed resource.
macAddress String

Look up Existing ServerNetwork Resource

Get an existing ServerNetwork resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: ServerNetworkState, opts?: CustomResourceOptions): ServerNetwork
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        alias_ips: Optional[Sequence[str]] = None,
        ip: Optional[str] = None,
        mac_address: Optional[str] = None,
        network_id: Optional[int] = None,
        server_id: Optional[int] = None,
        subnet_id: Optional[str] = None) -> ServerNetwork
func GetServerNetwork(ctx *Context, name string, id IDInput, state *ServerNetworkState, opts ...ResourceOption) (*ServerNetwork, error)
public static ServerNetwork Get(string name, Input<string> id, ServerNetworkState? state, CustomResourceOptions? opts = null)
public static ServerNetwork get(String name, Output<String> id, ServerNetworkState state, CustomResourceOptions options)
resources:  _:    type: hcloud:ServerNetwork    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AliasIps List<string>
Additional IPs to be assigned to this server.
Ip Changes to this property will trigger replacement. string
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
MacAddress string
NetworkId Changes to this property will trigger replacement. int
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
ServerId Changes to this property will trigger replacement. int
ID of the server.
SubnetId Changes to this property will trigger replacement. string
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
AliasIps []string
Additional IPs to be assigned to this server.
Ip Changes to this property will trigger replacement. string
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
MacAddress string
NetworkId Changes to this property will trigger replacement. int
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
ServerId Changes to this property will trigger replacement. int
ID of the server.
SubnetId Changes to this property will trigger replacement. string
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
aliasIps List<String>
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. String
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
macAddress String
networkId Changes to this property will trigger replacement. Integer
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
serverId Changes to this property will trigger replacement. Integer
ID of the server.
subnetId Changes to this property will trigger replacement. String
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
aliasIps string[]
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. string
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
macAddress string
networkId Changes to this property will trigger replacement. number
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
serverId Changes to this property will trigger replacement. number
ID of the server.
subnetId Changes to this property will trigger replacement. string
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
alias_ips Sequence[str]
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. str
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
mac_address str
network_id Changes to this property will trigger replacement. int
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
server_id Changes to this property will trigger replacement. int
ID of the server.
subnet_id Changes to this property will trigger replacement. str
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.
aliasIps List<String>
Additional IPs to be assigned to this server.
ip Changes to this property will trigger replacement. String
IP to request to be assigned to this server. If you do not provide this then you will be auto assigned an IP address.
macAddress String
networkId Changes to this property will trigger replacement. Number
ID of the network which should be added to the server. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between server and subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud.ServerNetwork and the existence of a subnet.
serverId Changes to this property will trigger replacement. Number
ID of the server.
subnetId Changes to this property will trigger replacement. String
ID of the sub-network which should be added to the Server. Required if network_id is not set. Note: if the ip property is missing, the Server is currently added to the last created subnet.

Import

Server Network entries can be imported using a compound ID with the following format:

<server-id>-<network-id>

$ pulumi import hcloud:index/serverNetwork:ServerNetwork example "$SERVER_ID-$NETWORK_ID"
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Hetzner Cloud pulumi/pulumi-hcloud
License
Apache-2.0
Notes
This Pulumi package is based on the hcloud Terraform Provider.