Manage the attachment of a Server in a Network 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-12",
serverType: "cx23",
});
const network = new hcloud.Network("network", {
name: "network",
ipRange: "10.0.0.0/16",
});
const subnet1 = new hcloud.NetworkSubnet("subnet1", {
networkId: network.id,
type: "cloud",
networkZone: "eu-central",
ipRange: "10.0.1.0/24",
});
const node1Subnet1 = new hcloud.ServerNetwork("node1_subnet1", {
serverId: node1.id,
subnetId: subnet1.id,
ip: "10.0.1.5",
aliasIps: ["10.0.1.10"],
});
import pulumi
import pulumi_hcloud as hcloud
node1 = hcloud.Server("node1",
name="node1",
image="debian-12",
server_type="cx23")
network = hcloud.Network("network",
name="network",
ip_range="10.0.0.0/16")
subnet1 = hcloud.NetworkSubnet("subnet1",
network_id=network.id,
type="cloud",
network_zone="eu-central",
ip_range="10.0.1.0/24")
node1_subnet1 = hcloud.ServerNetwork("node1_subnet1",
server_id=node1.id,
subnet_id=subnet1.id,
ip="10.0.1.5",
alias_ips=["10.0.1.10"])
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-12"),
ServerType: pulumi.String("cx23"),
})
if err != nil {
return err
}
network, err := hcloud.NewNetwork(ctx, "network", &hcloud.NetworkArgs{
Name: pulumi.String("network"),
IpRange: pulumi.String("10.0.0.0/16"),
})
if err != nil {
return err
}
subnet1, err := hcloud.NewNetworkSubnet(ctx, "subnet1", &hcloud.NetworkSubnetArgs{
NetworkId: network.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, "node1_subnet1", &hcloud.ServerNetworkArgs{
ServerId: node1.ID(),
SubnetId: subnet1.ID(),
Ip: pulumi.String("10.0.1.5"),
AliasIps: pulumi.StringArray{
pulumi.String("10.0.1.10"),
},
})
if err != nil {
return err
}
return nil
})
}
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-12",
ServerType = "cx23",
});
var network = new HCloud.Network("network", new()
{
Name = "network",
IpRange = "10.0.0.0/16",
});
var subnet1 = new HCloud.NetworkSubnet("subnet1", new()
{
NetworkId = network.Id,
Type = "cloud",
NetworkZone = "eu-central",
IpRange = "10.0.1.0/24",
});
var node1Subnet1 = new HCloud.ServerNetwork("node1_subnet1", new()
{
ServerId = node1.Id,
SubnetId = subnet1.Id,
Ip = "10.0.1.5",
AliasIps = new[]
{
"10.0.1.10",
},
});
});
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-12")
.serverType("cx23")
.build());
var network = new Network("network", NetworkArgs.builder()
.name("network")
.ipRange("10.0.0.0/16")
.build());
var subnet1 = new NetworkSubnet("subnet1", NetworkSubnetArgs.builder()
.networkId(network.id())
.type("cloud")
.networkZone("eu-central")
.ipRange("10.0.1.0/24")
.build());
var node1Subnet1 = new ServerNetwork("node1Subnet1", ServerNetworkArgs.builder()
.serverId(node1.id())
.subnetId(subnet1.id())
.ip("10.0.1.5")
.aliasIps("10.0.1.10")
.build());
}
}
resources:
node1:
type: hcloud:Server
properties:
name: node1
image: debian-12
serverType: cx23
network:
type: hcloud:Network
properties:
name: network
ipRange: 10.0.0.0/16
subnet1:
type: hcloud:NetworkSubnet
properties:
networkId: ${network.id}
type: cloud
networkZone: eu-central
ipRange: 10.0.1.0/24
node1Subnet1:
type: hcloud:ServerNetwork
name: node1_subnet1
properties:
serverId: ${node1.id}
subnetId: ${subnet1.id}
ip: 10.0.1.5
aliasIps:
- 10.0.1.10
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 string
- The unique name of the resource.
- args ServerNetworkArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args 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 string
- The unique name of the resource.
- args ServerNetworkArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args ServerNetworkArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args 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",
});
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"),
})
var serverNetworkResource = new ServerNetwork("serverNetworkResource", ServerNetworkArgs.builder()
.serverId(0)
.aliasIps("string")
.ip("string")
.networkId(0)
.subnetId("string")
.build());
server_network_resource = hcloud.ServerNetwork("serverNetworkResource",
server_id=0,
alias_ips=["string"],
ip="string",
network_id=0,
subnet_id="string")
const serverNetworkResource = new hcloud.ServerNetwork("serverNetworkResource", {
serverId: 0,
aliasIps: ["string"],
ip: "string",
networkId: 0,
subnetId: "string",
});
type: hcloud:ServerNetwork
properties:
aliasIps:
- string
ip: string
networkId: 0
serverId: 0
subnetId: string
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:
- Server
Id int - ID of the Server.
- Alias
Ips List<string> - Additional IPs to assign to the Server.
- Ip string
- IP to assign to the Server.
- Network
Id int - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - Subnet
Id string - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- Server
Id int - ID of the Server.
- Alias
Ips []string - Additional IPs to assign to the Server.
- Ip string
- IP to assign to the Server.
- Network
Id int - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - Subnet
Id string - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- server
Id Integer - ID of the Server.
- alias
Ips List<String> - Additional IPs to assign to the Server.
- ip String
- IP to assign to the Server.
- network
Id Integer - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - subnet
Id String - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- server
Id number - ID of the Server.
- alias
Ips string[] - Additional IPs to assign to the Server.
- ip string
- IP to assign to the Server.
- network
Id number - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - subnet
Id string - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- server_
id int - ID of the Server.
- alias_
ips Sequence[str] - Additional IPs to assign to the Server.
- ip str
- IP to assign to the Server.
- network_
id int - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - subnet_
id str - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- server
Id Number - ID of the Server.
- alias
Ips List<String> - Additional IPs to assign to the Server.
- ip String
- IP to assign to the Server.
- network
Id Number - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - subnet
Id String - ID of the Subnet to attach the Server to. Required if
network_idis not set.
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.
- Mac
Address string - MAC address of the Server on the Network.
- Id string
- The provider-assigned unique ID for this managed resource.
- Mac
Address string - MAC address of the Server on the Network.
- id String
- The provider-assigned unique ID for this managed resource.
- mac
Address String - MAC address of the Server on the Network.
- id string
- The provider-assigned unique ID for this managed resource.
- mac
Address string - MAC address of the Server on the Network.
- id str
- The provider-assigned unique ID for this managed resource.
- mac_
address str - MAC address of the Server on the Network.
- id String
- The provider-assigned unique ID for this managed resource.
- mac
Address String - MAC address of the Server on the Network.
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) -> ServerNetworkfunc 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
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- 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.
- Alias
Ips List<string> - Additional IPs to assign to the Server.
- Ip string
- IP to assign to the Server.
- Mac
Address string - MAC address of the Server on the Network.
- Network
Id int - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - Server
Id int - ID of the Server.
- Subnet
Id string - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- Alias
Ips []string - Additional IPs to assign to the Server.
- Ip string
- IP to assign to the Server.
- Mac
Address string - MAC address of the Server on the Network.
- Network
Id int - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - Server
Id int - ID of the Server.
- Subnet
Id string - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- alias
Ips List<String> - Additional IPs to assign to the Server.
- ip String
- IP to assign to the Server.
- mac
Address String - MAC address of the Server on the Network.
- network
Id Integer - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - server
Id Integer - ID of the Server.
- subnet
Id String - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- alias
Ips string[] - Additional IPs to assign to the Server.
- ip string
- IP to assign to the Server.
- mac
Address string - MAC address of the Server on the Network.
- network
Id number - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - server
Id number - ID of the Server.
- subnet
Id string - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- alias_
ips Sequence[str] - Additional IPs to assign to the Server.
- ip str
- IP to assign to the Server.
- mac_
address str - MAC address of the Server on the Network.
- network_
id int - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - server_
id int - ID of the Server.
- subnet_
id str - ID of the Subnet to attach the Server to. Required if
network_idis not set.
- alias
Ips List<String> - Additional IPs to assign to the Server.
- ip String
- IP to assign to the Server.
- mac
Address String - MAC address of the Server on the Network.
- network
Id Number - ID of the Network to attach the Server to. Using
subnet_idis preferred. Required ifsubnet_idis not set. Ifsubnet_idoripare not set, the Server will be attached to the last subnet (ordered byip_range). - server
Id Number - ID of the Server.
- subnet
Id String - ID of the Subnet to attach the Server to. Required if
network_idis not set.
Import
The pulumi import command can be used, for example:
$ pulumi import hcloud:index/serverNetwork:ServerNetwork example "$SERVER_ID-$NETWORK_ID"
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
hcloudTerraform Provider.
