1. Packages
  2. Hetzner Cloud
  3. API Docs
  4. getSshKey
Hetzner Cloud v1.18.0 published on Wednesday, Mar 27, 2024 by Pulumi

hcloud.getSshKey

Explore with Pulumi AI

hcloud logo
Hetzner Cloud v1.18.0 published on Wednesday, Mar 27, 2024 by Pulumi

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as hcloud from "@pulumi/hcloud";
    
    const sshKey1 = hcloud.getSshKey({
        id: 1234,
    });
    const sshKey2 = hcloud.getSshKey({
        name: "my-ssh-key",
    });
    const sshKey3 = hcloud.getSshKey({
        fingerprint: "43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8",
    });
    const sshKey4 = hcloud.getSshKey({
        withSelector: "key=value",
    });
    const main = new hcloud.Server("main", {sshKeys: [
        sshKey1.then(sshKey1 => sshKey1.id),
        sshKey2.then(sshKey2 => sshKey2.id),
        sshKey3.then(sshKey3 => sshKey3.id),
    ]});
    
    import pulumi
    import pulumi_hcloud as hcloud
    
    ssh_key1 = hcloud.get_ssh_key(id=1234)
    ssh_key2 = hcloud.get_ssh_key(name="my-ssh-key")
    ssh_key3 = hcloud.get_ssh_key(fingerprint="43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8")
    ssh_key4 = hcloud.get_ssh_key(with_selector="key=value")
    main = hcloud.Server("main", ssh_keys=[
        ssh_key1.id,
        ssh_key2.id,
        ssh_key3.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 {
    		sshKey1, err := hcloud.LookupSshKey(ctx, &hcloud.LookupSshKeyArgs{
    			Id: pulumi.IntRef(1234),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		sshKey2, err := hcloud.LookupSshKey(ctx, &hcloud.LookupSshKeyArgs{
    			Name: pulumi.StringRef("my-ssh-key"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		sshKey3, err := hcloud.LookupSshKey(ctx, &hcloud.LookupSshKeyArgs{
    			Fingerprint: pulumi.StringRef("43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = hcloud.LookupSshKey(ctx, &hcloud.LookupSshKeyArgs{
    			WithSelector: pulumi.StringRef("key=value"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = hcloud.NewServer(ctx, "main", &hcloud.ServerArgs{
    			SshKeys: pulumi.StringArray{
    				pulumi.Int(sshKey1.Id),
    				pulumi.Int(sshKey2.Id),
    				pulumi.Int(sshKey3.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 sshKey1 = HCloud.GetSshKey.Invoke(new()
        {
            Id = 1234,
        });
    
        var sshKey2 = HCloud.GetSshKey.Invoke(new()
        {
            Name = "my-ssh-key",
        });
    
        var sshKey3 = HCloud.GetSshKey.Invoke(new()
        {
            Fingerprint = "43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8",
        });
    
        var sshKey4 = HCloud.GetSshKey.Invoke(new()
        {
            WithSelector = "key=value",
        });
    
        var main = new HCloud.Server("main", new()
        {
            SshKeys = new[]
            {
                sshKey1.Apply(getSshKeyResult => getSshKeyResult.Id),
                sshKey2.Apply(getSshKeyResult => getSshKeyResult.Id),
                sshKey3.Apply(getSshKeyResult => getSshKeyResult.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.GetSshKeyArgs;
    import com.pulumi.hcloud.Server;
    import com.pulumi.hcloud.ServerArgs;
    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 sshKey1 = HcloudFunctions.getSshKey(GetSshKeyArgs.builder()
                .id("1234")
                .build());
    
            final var sshKey2 = HcloudFunctions.getSshKey(GetSshKeyArgs.builder()
                .name("my-ssh-key")
                .build());
    
            final var sshKey3 = HcloudFunctions.getSshKey(GetSshKeyArgs.builder()
                .fingerprint("43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8")
                .build());
    
            final var sshKey4 = HcloudFunctions.getSshKey(GetSshKeyArgs.builder()
                .withSelector("key=value")
                .build());
    
            var main = new Server("main", ServerArgs.builder()        
                .sshKeys(            
                    sshKey1.applyValue(getSshKeyResult -> getSshKeyResult.id()),
                    sshKey2.applyValue(getSshKeyResult -> getSshKeyResult.id()),
                    sshKey3.applyValue(getSshKeyResult -> getSshKeyResult.id()))
                .build());
    
        }
    }
    
    resources:
      main:
        type: hcloud:Server
        properties:
          sshKeys:
            - ${sshKey1.id}
            - ${sshKey2.id}
            - ${sshKey3.id}
    variables:
      sshKey1:
        fn::invoke:
          Function: hcloud:getSshKey
          Arguments:
            id: '1234'
      sshKey2:
        fn::invoke:
          Function: hcloud:getSshKey
          Arguments:
            name: my-ssh-key
      sshKey3:
        fn::invoke:
          Function: hcloud:getSshKey
          Arguments:
            fingerprint: 43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8
      sshKey4:
        fn::invoke:
          Function: hcloud:getSshKey
          Arguments:
            withSelector: key=value
    

    Using getSshKey

    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 getSshKey(args: GetSshKeyArgs, opts?: InvokeOptions): Promise<GetSshKeyResult>
    function getSshKeyOutput(args: GetSshKeyOutputArgs, opts?: InvokeOptions): Output<GetSshKeyResult>
    def get_ssh_key(fingerprint: Optional[str] = None,
                    id: Optional[int] = None,
                    labels: Optional[Mapping[str, str]] = None,
                    name: Optional[str] = None,
                    public_key: Optional[str] = None,
                    selector: Optional[str] = None,
                    with_selector: Optional[str] = None,
                    opts: Optional[InvokeOptions] = None) -> GetSshKeyResult
    def get_ssh_key_output(fingerprint: Optional[pulumi.Input[str]] = None,
                    id: Optional[pulumi.Input[int]] = None,
                    labels: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                    name: Optional[pulumi.Input[str]] = None,
                    public_key: Optional[pulumi.Input[str]] = None,
                    selector: Optional[pulumi.Input[str]] = None,
                    with_selector: Optional[pulumi.Input[str]] = None,
                    opts: Optional[InvokeOptions] = None) -> Output[GetSshKeyResult]
    func LookupSshKey(ctx *Context, args *LookupSshKeyArgs, opts ...InvokeOption) (*LookupSshKeyResult, error)
    func LookupSshKeyOutput(ctx *Context, args *LookupSshKeyOutputArgs, opts ...InvokeOption) LookupSshKeyResultOutput

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

    public static class GetSshKey 
    {
        public static Task<GetSshKeyResult> InvokeAsync(GetSshKeyArgs args, InvokeOptions? opts = null)
        public static Output<GetSshKeyResult> Invoke(GetSshKeyInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetSshKeyResult> getSshKey(GetSshKeyArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: hcloud:index/getSshKey:getSshKey
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Fingerprint string
    Fingerprint of the SSH Key.
    Id int
    ID of the SSH Key.
    Labels Dictionary<string, string>
    Name string
    Name of the SSH Key.
    PublicKey string
    (string) Public Key of the SSH Key.
    Selector string

    Deprecated:Please use the with_selector property instead.

    WithSelector string
    Label selector
    Fingerprint string
    Fingerprint of the SSH Key.
    Id int
    ID of the SSH Key.
    Labels map[string]string
    Name string
    Name of the SSH Key.
    PublicKey string
    (string) Public Key of the SSH Key.
    Selector string

    Deprecated:Please use the with_selector property instead.

    WithSelector string
    Label selector
    fingerprint String
    Fingerprint of the SSH Key.
    id Integer
    ID of the SSH Key.
    labels Map<String,String>
    name String
    Name of the SSH Key.
    publicKey String
    (string) Public Key of the SSH Key.
    selector String

    Deprecated:Please use the with_selector property instead.

    withSelector String
    Label selector
    fingerprint string
    Fingerprint of the SSH Key.
    id number
    ID of the SSH Key.
    labels {[key: string]: string}
    name string
    Name of the SSH Key.
    publicKey string
    (string) Public Key of the SSH Key.
    selector string

    Deprecated:Please use the with_selector property instead.

    withSelector string
    Label selector
    fingerprint str
    Fingerprint of the SSH Key.
    id int
    ID of the SSH Key.
    labels Mapping[str, str]
    name str
    Name of the SSH Key.
    public_key str
    (string) Public Key of the SSH Key.
    selector str

    Deprecated:Please use the with_selector property instead.

    with_selector str
    Label selector
    fingerprint String
    Fingerprint of the SSH Key.
    id Number
    ID of the SSH Key.
    labels Map<String>
    name String
    Name of the SSH Key.
    publicKey String
    (string) Public Key of the SSH Key.
    selector String

    Deprecated:Please use the with_selector property instead.

    withSelector String
    Label selector

    getSshKey Result

    The following output properties are available:

    Fingerprint string
    (string) Fingerprint of the SSH Key.
    Id int
    (int) Unique ID of the SSH Key.
    Labels Dictionary<string, string>
    Name string
    (string) Name of the SSH Key.
    PublicKey string
    (string) Public Key of the SSH Key.
    Selector string

    Deprecated:Please use the with_selector property instead.

    WithSelector string
    Fingerprint string
    (string) Fingerprint of the SSH Key.
    Id int
    (int) Unique ID of the SSH Key.
    Labels map[string]string
    Name string
    (string) Name of the SSH Key.
    PublicKey string
    (string) Public Key of the SSH Key.
    Selector string

    Deprecated:Please use the with_selector property instead.

    WithSelector string
    fingerprint String
    (string) Fingerprint of the SSH Key.
    id Integer
    (int) Unique ID of the SSH Key.
    labels Map<String,String>
    name String
    (string) Name of the SSH Key.
    publicKey String
    (string) Public Key of the SSH Key.
    selector String

    Deprecated:Please use the with_selector property instead.

    withSelector String
    fingerprint string
    (string) Fingerprint of the SSH Key.
    id number
    (int) Unique ID of the SSH Key.
    labels {[key: string]: string}
    name string
    (string) Name of the SSH Key.
    publicKey string
    (string) Public Key of the SSH Key.
    selector string

    Deprecated:Please use the with_selector property instead.

    withSelector string
    fingerprint str
    (string) Fingerprint of the SSH Key.
    id int
    (int) Unique ID of the SSH Key.
    labels Mapping[str, str]
    name str
    (string) Name of the SSH Key.
    public_key str
    (string) Public Key of the SSH Key.
    selector str

    Deprecated:Please use the with_selector property instead.

    with_selector str
    fingerprint String
    (string) Fingerprint of the SSH Key.
    id Number
    (int) Unique ID of the SSH Key.
    labels Map<String>
    name String
    (string) Name of the SSH Key.
    publicKey String
    (string) Public Key of the SSH Key.
    selector String

    Deprecated:Please use the with_selector property instead.

    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.18.0 published on Wednesday, Mar 27, 2024 by Pulumi