Hetzner Cloud

Pulumi Official
Package maintained by Pulumi
v1.10.1 published on Wednesday, Aug 3, 2022 by Pulumi

getPrimaryIp

Provides details about a Hetzner Cloud Primary IP.

This resource can be useful when you need to determine a Primary IP ID based on the IP address.

Side note:

If a server is getting created, it has to have a primary ip. If a server is getting created without defining primary ips, two of them (one ipv4 and one ipv6) getting created & attached. Currently, Primary IPs can be only attached to servers.

Example Usage

Additional Examples

using Pulumi;
using HCloud = Pulumi.HCloud;

class MyStack : Stack
{
    public MyStack()
    {
        var ip1 = Output.Create(HCloud.GetPrimaryIp.InvokeAsync(new HCloud.GetPrimaryIpArgs
        {
            IpAddress = "1.2.3.4",
        }));
        var ip2 = Output.Create(HCloud.GetPrimaryIp.InvokeAsync(new HCloud.GetPrimaryIpArgs
        {
            Name = "primary_ip_1",
        }));
        var ip3 = Output.Create(HCloud.GetPrimaryIp.InvokeAsync(new HCloud.GetPrimaryIpArgs
        {
            WithSelector = "key=value",
        }));
        // Link a server to an existing primary IP
        var serverTest = new HCloud.Server("serverTest", new HCloud.ServerArgs
        {
            Image = "ubuntu-20.04",
            ServerType = "cx11",
            Datacenter = "fsn1-dc14",
            Labels = 
            {
                { "test", "tessst1" },
            },
            PublicNets = 
            {
                new HCloud.Inputs.ServerPublicNetArgs
                {
                    Ipv4 = hcloud_primary_ip.Ip_1.Id,
                },
            },
        });
    }

}
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 {
		_, err := hcloud.LookupPrimaryIp(ctx, &GetPrimaryIpArgs{
			IpAddress: pulumi.StringRef("1.2.3.4"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = hcloud.LookupPrimaryIp(ctx, &GetPrimaryIpArgs{
			Name: pulumi.StringRef("primary_ip_1"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = hcloud.LookupPrimaryIp(ctx, &GetPrimaryIpArgs{
			WithSelector: pulumi.StringRef("key=value"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = hcloud.NewServer(ctx, "serverTest", &hcloud.ServerArgs{
			Image:      pulumi.String("ubuntu-20.04"),
			ServerType: pulumi.String("cx11"),
			Datacenter: pulumi.String("fsn1-dc14"),
			Labels: pulumi.AnyMap{
				"test": pulumi.Any("tessst1"),
			},
			PublicNets: ServerPublicNetArray{
				&ServerPublicNetArgs{
					Ipv4: pulumi.Any(hcloud_primary_ip.Ip_1.Id),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var ip1 = Output.of(HcloudFunctions.getPrimaryIp(GetPrimaryIpArgs.builder()
            .ipAddress("1.2.3.4")
            .build()));

        final var ip2 = Output.of(HcloudFunctions.getPrimaryIp(GetPrimaryIpArgs.builder()
            .name("primary_ip_1")
            .build()));

        final var ip3 = Output.of(HcloudFunctions.getPrimaryIp(GetPrimaryIpArgs.builder()
            .withSelector("key=value")
            .build()));

        var serverTest = new Server("serverTest", ServerArgs.builder()        
            .image("ubuntu-20.04")
            .serverType("cx11")
            .datacenter("fsn1-dc14")
            .labels(Map.of("test", "tessst1"))
            .publicNets(ServerPublicNetArgs.builder()
                .ipv4(hcloud_primary_ip.ip_1().id())
                .build())
            .build());

    }
}
import pulumi
import pulumi_hcloud as hcloud

ip1 = hcloud.get_primary_ip(ip_address="1.2.3.4")
ip2 = hcloud.get_primary_ip(name="primary_ip_1")
ip3 = hcloud.get_primary_ip(with_selector="key=value")
# Link a server to an existing primary IP
server_test = hcloud.Server("serverTest",
    image="ubuntu-20.04",
    server_type="cx11",
    datacenter="fsn1-dc14",
    labels={
        "test": "tessst1",
    },
    public_nets=[hcloud.ServerPublicNetArgs(
        ipv4=hcloud_primary_ip["ip_1"]["id"],
    )])
import * as pulumi from "@pulumi/pulumi";
import * as hcloud from "@pulumi/hcloud";

const ip1 = hcloud.getPrimaryIp({
    ipAddress: "1.2.3.4",
});
const ip2 = hcloud.getPrimaryIp({
    name: "primary_ip_1",
});
const ip3 = hcloud.getPrimaryIp({
    withSelector: "key=value",
});
// Link a server to an existing primary IP
const serverTest = new hcloud.Server("serverTest", {
    image: "ubuntu-20.04",
    serverType: "cx11",
    datacenter: "fsn1-dc14",
    labels: {
        test: "tessst1",
    },
    publicNets: [{
        ipv4: hcloud_primary_ip.ip_1.id,
    }],
});
resources:
  serverTest:
    type: hcloud:Server
    properties:
      image: ubuntu-20.04
      serverType: cx11
      datacenter: fsn1-dc14
      labels:
        test: tessst1
      publicNets:
        - ipv4: ${hcloud_primary_ip.ip_1.id}
variables:
  ip1:
    Fn::Invoke:
      Function: hcloud:getPrimaryIp
      Arguments:
        ipAddress: 1.2.3.4
  ip2:
    Fn::Invoke:
      Function: hcloud:getPrimaryIp
      Arguments:
        name: primary_ip_1
  ip3:
    Fn::Invoke:
      Function: hcloud:getPrimaryIp
      Arguments:
        withSelector: key=value

Using getPrimaryIp

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 getPrimaryIp(args: GetPrimaryIpArgs, opts?: InvokeOptions): Promise<GetPrimaryIpResult>
function getPrimaryIpOutput(args: GetPrimaryIpOutputArgs, opts?: InvokeOptions): Output<GetPrimaryIpResult>
def get_primary_ip(assignee_id: Optional[int] = None,
                   id: Optional[int] = None,
                   ip_address: Optional[str] = None,
                   name: Optional[str] = None,
                   with_selector: Optional[str] = None,
                   opts: Optional[InvokeOptions] = None) -> GetPrimaryIpResult
def get_primary_ip_output(assignee_id: Optional[pulumi.Input[int]] = None,
                   id: Optional[pulumi.Input[int]] = None,
                   ip_address: Optional[pulumi.Input[str]] = None,
                   name: Optional[pulumi.Input[str]] = None,
                   with_selector: Optional[pulumi.Input[str]] = None,
                   opts: Optional[InvokeOptions] = None) -> Output[GetPrimaryIpResult]
func LookupPrimaryIp(ctx *Context, args *LookupPrimaryIpArgs, opts ...InvokeOption) (*LookupPrimaryIpResult, error)
func LookupPrimaryIpOutput(ctx *Context, args *LookupPrimaryIpOutputArgs, opts ...InvokeOption) LookupPrimaryIpResultOutput

> Note: This function is named LookupPrimaryIp in the Go SDK.

public static class GetPrimaryIp 
{
    public static Task<GetPrimaryIpResult> InvokeAsync(GetPrimaryIpArgs args, InvokeOptions? opts = null)
    public static Output<GetPrimaryIpResult> Invoke(GetPrimaryIpInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetPrimaryIpResult> getPrimaryIp(GetPrimaryIpArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
Fn::Invoke:
  Function: hcloud:index/getPrimaryIp:getPrimaryIp
  Arguments:
    # Arguments dictionary

The following arguments are supported:

AssigneeId int

(int) ID of the assigned resource

Id int

ID of the Primary IP.

IpAddress string

IP address of the Primary IP.

Name string

Name of the Primary IP.

WithSelector string

Label selector

AssigneeId int

(int) ID of the assigned resource

Id int

ID of the Primary IP.

IpAddress string

IP address of the Primary IP.

Name string

Name of the Primary IP.

WithSelector string

Label selector

assigneeId Integer

(int) ID of the assigned resource

id Integer

ID of the Primary IP.

ipAddress String

IP address of the Primary IP.

name String

Name of the Primary IP.

withSelector String

Label selector

assigneeId number

(int) ID of the assigned resource

id number

ID of the Primary IP.

ipAddress string

IP address of the Primary IP.

name string

Name of the Primary IP.

withSelector string

Label selector

assignee_id int

(int) ID of the assigned resource

id int

ID of the Primary IP.

ip_address str

IP address of the Primary IP.

name str

Name of the Primary IP.

with_selector str

Label selector

assigneeId Number

(int) ID of the assigned resource

id Number

ID of the Primary IP.

ipAddress String

IP address of the Primary IP.

name String

Name of the Primary IP.

withSelector String

Label selector

getPrimaryIp Result

The following output properties are available:

AssigneeId int

(int) ID of the assigned resource

AssigneeType string

(string) The type of the assigned resource.

AutoDelete bool

(boolean) Whether auto delete is enabled.

Datacenter string
DeleteProtection bool

(boolean) Whether delete protection is enabled.

Id int

(int) Unique ID of the Primary IP.

IpAddress string

(string) IP Address of the Primary IP.

IpNetwork string
Labels Dictionary<string, object>

(string) Description of the Primary IP.

Type string

(string) Type of the Primary IP.

Name string

(string) Name of the Primary IP.

WithSelector string
AssigneeId int

(int) ID of the assigned resource

AssigneeType string

(string) The type of the assigned resource.

AutoDelete bool

(boolean) Whether auto delete is enabled.

Datacenter string
DeleteProtection bool

(boolean) Whether delete protection is enabled.

Id int

(int) Unique ID of the Primary IP.

IpAddress string

(string) IP Address of the Primary IP.

IpNetwork string
Labels map[string]interface{}

(string) Description of the Primary IP.

Type string

(string) Type of the Primary IP.

Name string

(string) Name of the Primary IP.

WithSelector string
assigneeId Integer

(int) ID of the assigned resource

assigneeType String

(string) The type of the assigned resource.

autoDelete Boolean

(boolean) Whether auto delete is enabled.

datacenter String
deleteProtection Boolean

(boolean) Whether delete protection is enabled.

id Integer

(int) Unique ID of the Primary IP.

ipAddress String

(string) IP Address of the Primary IP.

ipNetwork String
labels Map<String,Object>

(string) Description of the Primary IP.

type String

(string) Type of the Primary IP.

name String

(string) Name of the Primary IP.

withSelector String
assigneeId number

(int) ID of the assigned resource

assigneeType string

(string) The type of the assigned resource.

autoDelete boolean

(boolean) Whether auto delete is enabled.

datacenter string
deleteProtection boolean

(boolean) Whether delete protection is enabled.

id number

(int) Unique ID of the Primary IP.

ipAddress string

(string) IP Address of the Primary IP.

ipNetwork string
labels {[key: string]: any}

(string) Description of the Primary IP.

type string

(string) Type of the Primary IP.

name string

(string) Name of the Primary IP.

withSelector string
assignee_id int

(int) ID of the assigned resource

assignee_type str

(string) The type of the assigned resource.

auto_delete bool

(boolean) Whether auto delete is enabled.

datacenter str
delete_protection bool

(boolean) Whether delete protection is enabled.

id int

(int) Unique ID of the Primary IP.

ip_address str

(string) IP Address of the Primary IP.

ip_network str
labels Mapping[str, Any]

(string) Description of the Primary IP.

type str

(string) Type of the Primary IP.

name str

(string) Name of the Primary IP.

with_selector str
assigneeId Number

(int) ID of the assigned resource

assigneeType String

(string) The type of the assigned resource.

autoDelete Boolean

(boolean) Whether auto delete is enabled.

datacenter String
deleteProtection Boolean

(boolean) Whether delete protection is enabled.

id Number

(int) Unique ID of the Primary IP.

ipAddress String

(string) IP Address of the Primary IP.

ipNetwork String
labels Map<Any>

(string) Description of the Primary IP.

type String

(string) Type of the Primary IP.

name String

(string) Name of the Primary IP.

withSelector String

Package Details

Repository
https://github.com/pulumi/pulumi-hcloud
License
Apache-2.0
Notes

This Pulumi package is based on the hcloud Terraform Provider.