1. Registry
  2. Packages
  3. Hcloud Provider
  4. API Docs
  5. getPrimaryIp
Viewing docs for Hetzner Cloud v1.42.0
published on Saturday, Sep 12, 2026 by Pulumi
hcloud logo
Viewing docs for Hetzner Cloud v1.42.0
published on Saturday, Sep 12, 2026 by Pulumi

    Provides details about a Hetzner Cloud Primary IP.

    See the Primary IPs API documentation for more details.

    Deprecations

    datacenter attribute

    The datacenter attribute is marked for removal since v1.67.0, you must use the location attribute instead.

    See our deprecation and removal changelog for more details.

    Example Usage

    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("server_test", {
        name: "test-server",
        image: "ubuntu-24.04",
        serverType: "cx23",
        location: "fsn1",
        labels: {
            test: "tessst1",
        },
        publicNets: [{
            ipv4: Number(ip1HcloudPrimaryIp.id),
        }],
    });
    
    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("server_test",
        name="test-server",
        image="ubuntu-24.04",
        server_type="cx23",
        location="fsn1",
        labels={
            "test": "tessst1",
        },
        public_nets=[{
            "ipv4": int(ip1_hcloud_primary_ip["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.GetPrimaryIp(ctx, &hcloud.LookupPrimaryIpArgs{
    			IpAddress: pulumi.StringRef("1.2.3.4"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = hcloud.GetPrimaryIp(ctx, &hcloud.LookupPrimaryIpArgs{
    			Name: pulumi.StringRef("primary_ip_1"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = hcloud.GetPrimaryIp(ctx, &hcloud.LookupPrimaryIpArgs{
    			WithSelector: pulumi.StringRef("key=value"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Link a server to an existing primary IP
    		_, err = hcloud.NewServer(ctx, "server_test", &hcloud.ServerArgs{
    			Name:       pulumi.String("test-server"),
    			Image:      pulumi.String("ubuntu-24.04"),
    			ServerType: pulumi.String("cx23"),
    			Location:   pulumi.String("fsn1"),
    			Labels: pulumi.StringMap{
    				"test": pulumi.String("tessst1"),
    			},
    			PublicNets: hcloud.ServerPublicNetArray{
    				&hcloud.ServerPublicNetArgs{
    					Ipv4: pulumi.Any(ip1HcloudPrimaryIp.Id),
    				},
    			},
    		})
    		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 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("server_test", new()
        {
            Name = "test-server",
            Image = "ubuntu-24.04",
            ServerType = "cx23",
            Location = "fsn1",
            Labels = 
            {
                { "test", "tessst1" },
            },
            PublicNets = new[]
            {
                new HCloud.Inputs.ServerPublicNetArgs
                {
                    Ipv4 = ip1HcloudPrimaryIp.Id,
                },
            },
        });
    
    });
    
    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.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 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());
    
            // Link a server to an existing primary IP
            var serverTest = new Server("serverTest", ServerArgs.builder()
                .name("test-server")
                .image("ubuntu-24.04")
                .serverType("cx23")
                .location("fsn1")
                .labels(Map.of("test", "tessst1"))
                .publicNets(ServerPublicNetArgs.builder()
                    .ipv4(ip1HcloudPrimaryIp.id())
                    .build())
                .build());
    
        }
    }
    
    resources:
      # Link a server to an existing primary IP
      serverTest:
        type: hcloud:Server
        name: server_test
        properties:
          name: test-server
          image: ubuntu-24.04
          serverType: cx23
          location: fsn1
          labels:
            test: tessst1
          publicNets:
            - ipv4: ${ip1HcloudPrimaryIp.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
    
    pulumi {
      required_providers {
        hcloud = {
          source = "pulumi/hcloud"
        }
      }
    }
    
    data "hcloud_getprimaryip" "ip1" {
      ip_address = "1.2.3.4"
    }
    data "hcloud_getprimaryip" "ip2" {
      name = "primary_ip_1"
    }
    data "hcloud_getprimaryip" "ip3" {
      with_selector = "key=value"
    }
    
    // Link a server to an existing primary IP
    resource "hcloud_server" "server_test" {
      name        = "test-server"
      image       = "ubuntu-24.04"
      server_type = "cx23"
      location    = "fsn1"
      labels = {
        "test" = "tessst1"
      }
      public_nets {
        ipv4 = ip1HcloudPrimaryIp.id
      }
    }
    

    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?: InvokeOutputOptions): Output<GetPrimaryIpResult>
    def get_primary_ip(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(id: pulumi.Input[Optional[int]] = None,
                       ip_address: pulumi.Input[Optional[str]] = None,
                       name: pulumi.Input[Optional[str]] = None,
                       with_selector: pulumi.Input[Optional[str]] = None,
                       opts: Optional[InvokeOutputOptions] = 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 Output<GetPrimaryIpResult> Invoke(GetPrimaryIpInvokeArgs args, InvokeOutputOptions opts)
    }
    public static CompletableFuture<GetPrimaryIpResult> getPrimaryIp(GetPrimaryIpArgs args, InvokeOptions options)
    public static Output<GetPrimaryIpResult> getPrimaryIp(GetPrimaryIpArgs args, InvokeOptions options)
    public static Output<GetPrimaryIpResult> getPrimaryIp(GetPrimaryIpArgs args, InvokeOutputOptions options)
    
    fn::invoke:
      function: hcloud:index/getPrimaryIp:getPrimaryIp
      arguments:
        # arguments dictionary
    data "hcloud_get_primary_ip" "name" {
        # arguments
    }

    The following arguments are supported:

    Id int
    ID of the Primary IP.
    IpAddress string
    IP address of the Primary IP.
    Name string
    Name of the Primary IP.
    WithSelector string
    Filter results using a Label Selector.
    Id int
    ID of the Primary IP.
    IpAddress string
    IP address of the Primary IP.
    Name string
    Name of the Primary IP.
    WithSelector string
    Filter results using a Label Selector.
    id number
    ID of the Primary IP.
    ip_address string
    IP address of the Primary IP.
    name string
    Name of the Primary IP.
    with_selector string
    Filter results using a Label Selector.
    id Integer
    ID of the Primary IP.
    ipAddress String
    IP address of the Primary IP.
    name String
    Name of the Primary IP.
    withSelector String
    Filter results using a Label Selector.
    id number
    ID of the Primary IP.
    ipAddress string
    IP address of the Primary IP.
    name string
    Name of the Primary IP.
    withSelector string
    Filter results using a Label Selector.
    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
    Filter results using a Label Selector.
    id Number
    ID of the Primary IP.
    ipAddress String
    IP address of the Primary IP.
    name String
    Name of the Primary IP.
    withSelector String
    Filter results using a Label Selector.

    getPrimaryIp Result

    The following output properties are available:

    AssigneeId int
    ID of the resource the Primary IP is assigned to.
    AssigneeType string
    Type of the resource the Primary IP is assigned to.
    AutoDelete bool
    Whether auto delete is enabled.
    Datacenter string
    Name of the Datacenter of the Primary IP.

    Deprecated: The datacenter attribute is marked for removal, you must use the location attribute instead. See https://docs.hetzner.cloud/changelog#2026-07-01-removing-datacenters.

    DeleteProtection bool
    Whether delete protection is enabled.
    IpNetwork string
    IP network of the Primary IP for IPv6 addresses. Only set if type is ipv6.
    Labels Dictionary<string, string>
    User-defined labels (key-value pairs) for the resource.
    Location string
    Name of the Location of the Primary IP.
    Type string
    Type of the Primary IP (ipv4 or ipv6).
    Id int
    ID of the Primary IP.
    IpAddress string
    IP address of the Primary IP.
    Name string
    Name of the Primary IP.
    WithSelector string
    Filter results using a Label Selector.
    AssigneeId int
    ID of the resource the Primary IP is assigned to.
    AssigneeType string
    Type of the resource the Primary IP is assigned to.
    AutoDelete bool
    Whether auto delete is enabled.
    Datacenter string
    Name of the Datacenter of the Primary IP.

    Deprecated: The datacenter attribute is marked for removal, you must use the location attribute instead. See https://docs.hetzner.cloud/changelog#2026-07-01-removing-datacenters.

    DeleteProtection bool
    Whether delete protection is enabled.
    IpNetwork string
    IP network of the Primary IP for IPv6 addresses. Only set if type is ipv6.
    Labels map[string]string
    User-defined labels (key-value pairs) for the resource.
    Location string
    Name of the Location of the Primary IP.
    Type string
    Type of the Primary IP (ipv4 or ipv6).
    Id int
    ID of the Primary IP.
    IpAddress string
    IP address of the Primary IP.
    Name string
    Name of the Primary IP.
    WithSelector string
    Filter results using a Label Selector.
    assignee_id number
    ID of the resource the Primary IP is assigned to.
    assignee_type string
    Type of the resource the Primary IP is assigned to.
    auto_delete bool
    Whether auto delete is enabled.
    datacenter string
    Name of the Datacenter of the Primary IP.

    Deprecated: The datacenter attribute is marked for removal, you must use the location attribute instead. See https://docs.hetzner.cloud/changelog#2026-07-01-removing-datacenters.

    delete_protection bool
    Whether delete protection is enabled.
    ip_network string
    IP network of the Primary IP for IPv6 addresses. Only set if type is ipv6.
    labels map(string)
    User-defined labels (key-value pairs) for the resource.
    location string
    Name of the Location of the Primary IP.
    type string
    Type of the Primary IP (ipv4 or ipv6).
    id number
    ID of the Primary IP.
    ip_address string
    IP address of the Primary IP.
    name string
    Name of the Primary IP.
    with_selector string
    Filter results using a Label Selector.
    assigneeId Integer
    ID of the resource the Primary IP is assigned to.
    assigneeType String
    Type of the resource the Primary IP is assigned to.
    autoDelete Boolean
    Whether auto delete is enabled.
    datacenter String
    Name of the Datacenter of the Primary IP.

    Deprecated: The datacenter attribute is marked for removal, you must use the location attribute instead. See https://docs.hetzner.cloud/changelog#2026-07-01-removing-datacenters.

    deleteProtection Boolean
    Whether delete protection is enabled.
    ipNetwork String
    IP network of the Primary IP for IPv6 addresses. Only set if type is ipv6.
    labels Map<String,String>
    User-defined labels (key-value pairs) for the resource.
    location String
    Name of the Location of the Primary IP.
    type String
    Type of the Primary IP (ipv4 or ipv6).
    id Integer
    ID of the Primary IP.
    ipAddress String
    IP address of the Primary IP.
    name String
    Name of the Primary IP.
    withSelector String
    Filter results using a Label Selector.
    assigneeId number
    ID of the resource the Primary IP is assigned to.
    assigneeType string
    Type of the resource the Primary IP is assigned to.
    autoDelete boolean
    Whether auto delete is enabled.
    datacenter string
    Name of the Datacenter of the Primary IP.

    Deprecated: The datacenter attribute is marked for removal, you must use the location attribute instead. See https://docs.hetzner.cloud/changelog#2026-07-01-removing-datacenters.

    deleteProtection boolean
    Whether delete protection is enabled.
    ipNetwork string
    IP network of the Primary IP for IPv6 addresses. Only set if type is ipv6.
    labels {[key: string]: string}
    User-defined labels (key-value pairs) for the resource.
    location string
    Name of the Location of the Primary IP.
    type string
    Type of the Primary IP (ipv4 or ipv6).
    id number
    ID of the Primary IP.
    ipAddress string
    IP address of the Primary IP.
    name string
    Name of the Primary IP.
    withSelector string
    Filter results using a Label Selector.
    assignee_id int
    ID of the resource the Primary IP is assigned to.
    assignee_type str
    Type of the resource the Primary IP is assigned to.
    auto_delete bool
    Whether auto delete is enabled.
    datacenter str
    Name of the Datacenter of the Primary IP.

    Deprecated: The datacenter attribute is marked for removal, you must use the location attribute instead. See https://docs.hetzner.cloud/changelog#2026-07-01-removing-datacenters.

    delete_protection bool
    Whether delete protection is enabled.
    ip_network str
    IP network of the Primary IP for IPv6 addresses. Only set if type is ipv6.
    labels Mapping[str, str]
    User-defined labels (key-value pairs) for the resource.
    location str
    Name of the Location of the Primary IP.
    type str
    Type of the Primary IP (ipv4 or ipv6).
    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
    Filter results using a Label Selector.
    assigneeId Number
    ID of the resource the Primary IP is assigned to.
    assigneeType String
    Type of the resource the Primary IP is assigned to.
    autoDelete Boolean
    Whether auto delete is enabled.
    datacenter String
    Name of the Datacenter of the Primary IP.

    Deprecated: The datacenter attribute is marked for removal, you must use the location attribute instead. See https://docs.hetzner.cloud/changelog#2026-07-01-removing-datacenters.

    deleteProtection Boolean
    Whether delete protection is enabled.
    ipNetwork String
    IP network of the Primary IP for IPv6 addresses. Only set if type is ipv6.
    labels Map<String>
    User-defined labels (key-value pairs) for the resource.
    location String
    Name of the Location of the Primary IP.
    type String
    Type of the Primary IP (ipv4 or ipv6).
    id Number
    ID of the Primary IP.
    ipAddress String
    IP address of the Primary IP.
    name String
    Name of the Primary IP.
    withSelector String
    Filter results using a Label Selector.

    Package Details

    Repository
    Hetzner Cloud pulumi/pulumi-hcloud
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the hcloud Terraform Provider.
    hcloud logo
    Viewing docs for Hetzner Cloud v1.42.0
    published on Saturday, Sep 12, 2026 by Pulumi

      Try Pulumi Cloud free.
      Your team will thank you.

      Start free trial