hcloud.getPrimaryIp
Explore with Pulumi AI
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:
- Assignee
Id int - (int) ID of the assigned resource.
- Id int
- ID of the Primary IP.
- Ip
Address string - IP address of the Primary IP.
- Name string
- Name of the Primary IP.
- With
Selector string - Label selector
- Assignee
Id int - (int) ID of the assigned resource.
- Id int
- ID of the Primary IP.
- Ip
Address string - IP address of the Primary IP.
- Name string
- Name of the Primary IP.
- With
Selector string - Label selector
- assignee
Id Integer - (int) ID of the assigned resource.
- id Integer
- ID of the Primary IP.
- ip
Address String - IP address of the Primary IP.
- name String
- Name of the Primary IP.
- with
Selector String - Label selector
- assignee
Id number - (int) ID of the assigned resource.
- 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 - 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
- assignee
Id Number - (int) ID of the assigned resource.
- 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 - Label selector
getPrimaryIp Result
The following output properties are available:
- Assignee
Id int - (int) ID of the assigned resource.
- Assignee
Type string - (string) The type of the assigned resource.
- Auto
Delete bool - (bool) Whether auto delete is enabled.
- Datacenter string
- (string) The datacenter name of the Primary IP. See the Hetzner Docs for more details about datacenters.
- Delete
Protection bool - (bool) Whether delete protection is enabled.
- Id int
- (int) Unique ID of the Primary IP.
- Ip
Address string - (string) IP Address of the Primary IP.
- Ip
Network string - (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if
type
isipv6
) - Labels Dictionary<string, string>
- (map) User-defined labels (key-value pairs).
- Type string
- (string) Type of the Primary IP.
- Name string
- (string) Name of the Primary IP.
- With
Selector string
- Assignee
Id int - (int) ID of the assigned resource.
- Assignee
Type string - (string) The type of the assigned resource.
- Auto
Delete bool - (bool) Whether auto delete is enabled.
- Datacenter string
- (string) The datacenter name of the Primary IP. See the Hetzner Docs for more details about datacenters.
- Delete
Protection bool - (bool) Whether delete protection is enabled.
- Id int
- (int) Unique ID of the Primary IP.
- Ip
Address string - (string) IP Address of the Primary IP.
- Ip
Network string - (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if
type
isipv6
) - Labels map[string]string
- (map) User-defined labels (key-value pairs).
- Type string
- (string) Type of the Primary IP.
- Name string
- (string) Name of the Primary IP.
- With
Selector string
- assignee
Id Integer - (int) ID of the assigned resource.
- assignee
Type String - (string) The type of the assigned resource.
- auto
Delete Boolean - (bool) Whether auto delete is enabled.
- datacenter String
- (string) The datacenter name of the Primary IP. See the Hetzner Docs for more details about datacenters.
- delete
Protection Boolean - (bool) Whether delete protection is enabled.
- id Integer
- (int) Unique ID of the Primary IP.
- ip
Address String - (string) IP Address of the Primary IP.
- ip
Network String - (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if
type
isipv6
) - labels Map<String,String>
- (map) User-defined labels (key-value pairs).
- type String
- (string) Type of the Primary IP.
- name String
- (string) Name of the Primary IP.
- with
Selector String
- assignee
Id number - (int) ID of the assigned resource.
- assignee
Type string - (string) The type of the assigned resource.
- auto
Delete boolean - (bool) Whether auto delete is enabled.
- datacenter string
- (string) The datacenter name of the Primary IP. See the Hetzner Docs for more details about datacenters.
- delete
Protection boolean - (bool) Whether delete protection is enabled.
- id number
- (int) Unique ID of the Primary IP.
- ip
Address string - (string) IP Address of the Primary IP.
- ip
Network string - (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if
type
isipv6
) - labels {[key: string]: string}
- (map) User-defined labels (key-value pairs).
- type string
- (string) Type of the Primary IP.
- name string
- (string) Name of the Primary IP.
- with
Selector 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. See the Hetzner Docs for more details about datacenters.
- 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
isipv6
) - labels Mapping[str, str]
- (map) User-defined labels (key-value pairs).
- type str
- (string) Type of the Primary IP.
- name str
- (string) Name of the Primary IP.
- with_
selector str
- assignee
Id Number - (int) ID of the assigned resource.
- assignee
Type String - (string) The type of the assigned resource.
- auto
Delete Boolean - (bool) Whether auto delete is enabled.
- datacenter String
- (string) The datacenter name of the Primary IP. See the Hetzner Docs for more details about datacenters.
- delete
Protection Boolean - (bool) Whether delete protection is enabled.
- id Number
- (int) Unique ID of the Primary IP.
- ip
Address String - (string) IP Address of the Primary IP.
- ip
Network String - (string) IPv6 subnet of the Primary IP for IPv6 addresses. (Only set if
type
isipv6
) - labels Map<String>
- (map) User-defined labels (key-value pairs).
- type String
- (string) Type of the Primary IP.
- name String
- (string) Name of the Primary IP.
- with
Selector String
Package Details
- Repository
- Hetzner Cloud pulumi/pulumi-hcloud
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
hcloud
Terraform Provider.