1. Packages
  2. Hcloud Provider
  3. API Docs
  4. getPrimaryIp
Hetzner Cloud v1.20.4 published on Tuesday, Sep 24, 2024 by Pulumi

hcloud.getPrimaryIp

Explore with Pulumi AI

hcloud logo
Hetzner Cloud v1.20.4 published on Tuesday, Sep 24, 2024 by Pulumi

    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

    Data Source: hcloud.PrimaryIp

    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.

    Additional Examples

    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-20.04",
        serverType: "cx22",
        datacenter: "fsn1-dc14",
        labels: {
            test: "tessst1",
        },
        publicNets: [{
            ipv4: 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-20.04",
        server_type="cx22",
        datacenter="fsn1-dc14",
        labels={
            "test": "tessst1",
        },
        public_nets=[{
            "ipv4": 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.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
    		}
    		// 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-20.04"),
    			ServerType: pulumi.String("cx22"),
    			Datacenter: pulumi.String("fsn1-dc14"),
    			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-20.04",
            ServerType = "cx22",
            Datacenter = "fsn1-dc14",
            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.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());
    
            // Link a server to an existing primary IP
            var serverTest = new Server("serverTest", ServerArgs.builder()
                .name("test-server")
                .image("ubuntu-20.04")
                .serverType("cx22")
                .datacenter("fsn1-dc14")
                .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-20.04
          serverType: cx22
          datacenter: fsn1-dc14
          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
    

    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
    (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if type is ipv6)
    Labels Dictionary<string, string>
    (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
    (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if type is ipv6)
    Labels map[string]string
    (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
    (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if type is ipv6)
    labels Map<String,String>
    (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
    (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if type is ipv6)
    labels {[key: string]: string}
    (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
    (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if type is ipv6)
    labels Mapping[str, str]
    (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
    (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if type is ipv6)
    labels Map<String>
    (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.
    hcloud logo
    Hetzner Cloud v1.20.4 published on Tuesday, Sep 24, 2024 by Pulumi