hcloud logo
Hetzner Cloud v1.10.3, Mar 8 23

hcloud.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 System.Collections.Generic;
using Pulumi;
using HCloud = Pulumi.HCloud;

return await Deployment.RunAsync(() => 
{
    var ip1 = HCloud.GetPrimaryIp.Invoke(new()
    {
        IpAddress = "1.2.3.4",
    });

    var ip2 = HCloud.GetPrimaryIp.Invoke(new()
    {
        Name = "primary_ip_1",
    });

    var ip3 = HCloud.GetPrimaryIp.Invoke(new()
    {
        WithSelector = "key=value",
    });

    // Link a server to an existing primary IP
    var serverTest = new HCloud.Server("serverTest", new()
    {
        Image = "ubuntu-20.04",
        ServerType = "cx11",
        Datacenter = "fsn1-dc14",
        Labels = 
        {
            { "test", "tessst1" },
        },
        PublicNets = new[]
        {
            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, &hcloud.LookupPrimaryIpArgs{
			IpAddress: pulumi.StringRef("1.2.3.4"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = hcloud.LookupPrimaryIp(ctx, &hcloud.LookupPrimaryIpArgs{
			Name: pulumi.StringRef("primary_ip_1"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = hcloud.LookupPrimaryIp(ctx, &hcloud.LookupPrimaryIpArgs{
			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: hcloud.ServerPublicNetArray{
				&hcloud.ServerPublicNetArgs{
					Ipv4: pulumi.Any(hcloud_primary_ip.Ip_1.Id),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
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.inputs.GetPrimaryIpArgs;
import com.pulumi.hcloud.Server;
import com.pulumi.hcloud.ServerArgs;
import com.pulumi.hcloud.inputs.ServerPublicNetArgs;
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) {
        final var ip1 = HcloudFunctions.getPrimaryIp(GetPrimaryIpArgs.builder()
            .ipAddress("1.2.3.4")
            .build());

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

        final var ip3 = 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:
  # Link a server to an existing primary IP
  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

(bool) Whether auto delete is enabled.

Datacenter string

(string) The datacenter name of the Primary IP.

DeleteProtection bool

(bool) 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

(bool) Whether auto delete is enabled.

Datacenter string

(string) The datacenter name of the Primary IP.

DeleteProtection bool

(bool) 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

(bool) Whether auto delete is enabled.

datacenter String

(string) The datacenter name of the Primary IP.

deleteProtection Boolean

(bool) 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

(bool) Whether auto delete is enabled.

datacenter string

(string) The datacenter name of the Primary IP.

deleteProtection boolean

(bool) 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

(bool) Whether auto delete is enabled.

datacenter str

(string) The datacenter name of the Primary IP.

delete_protection bool

(bool) 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

(bool) Whether auto delete is enabled.

datacenter String

(string) The datacenter name of the Primary IP.

deleteProtection Boolean

(bool) 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
Hetzner Cloud pulumi/pulumi-hcloud
License
Apache-2.0
Notes

This Pulumi package is based on the hcloud Terraform Provider.