1. Packages
  2. Hcloud Provider
  3. API Docs
  4. SshKey
Hetzner Cloud v1.22.0 published on Wednesday, Feb 26, 2025 by Pulumi

hcloud.SshKey

Explore with Pulumi AI

Provides a Hetzner Cloud SSH Key resource to manage SSH Keys for server access.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as hcloud from "@pulumi/hcloud";
import * as std from "@pulumi/std";

const main = new hcloud.SshKey("main", {
    name: "my-ssh-key",
    publicKey: std.file({
        input: "~/.ssh/id_ed25519.pub",
    }).then(invoke => invoke.result),
});
Copy
import pulumi
import pulumi_hcloud as hcloud
import pulumi_std as std

main = hcloud.SshKey("main",
    name="my-ssh-key",
    public_key=std.file(input="~/.ssh/id_ed25519.pub").result)
Copy
package main

import (
	"github.com/pulumi/pulumi-hcloud/sdk/go/hcloud"
	"github.com/pulumi/pulumi-std/sdk/go/std"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		invokeFile, err := std.File(ctx, &std.FileArgs{
			Input: "~/.ssh/id_ed25519.pub",
		}, nil)
		if err != nil {
			return err
		}
		_, err = hcloud.NewSshKey(ctx, "main", &hcloud.SshKeyArgs{
			Name:      pulumi.String("my-ssh-key"),
			PublicKey: pulumi.String(invokeFile.Result),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using HCloud = Pulumi.HCloud;
using Std = Pulumi.Std;

return await Deployment.RunAsync(() => 
{
    var main = new HCloud.SshKey("main", new()
    {
        Name = "my-ssh-key",
        PublicKey = Std.File.Invoke(new()
        {
            Input = "~/.ssh/id_ed25519.pub",
        }).Apply(invoke => invoke.Result),
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.hcloud.SshKey;
import com.pulumi.hcloud.SshKeyArgs;
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) {
        var main = new SshKey("main", SshKeyArgs.builder()
            .name("my-ssh-key")
            .publicKey(StdFunctions.file(FileArgs.builder()
                .input("~/.ssh/id_ed25519.pub")
                .build()).result())
            .build());

    }
}
Copy
resources:
  main:
    type: hcloud:SshKey
    properties:
      name: my-ssh-key
      publicKey:
        fn::invoke:
          function: std:file
          arguments:
            input: ~/.ssh/id_ed25519.pub
          return: result
Copy

Create SshKey Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new SshKey(name: string, args: SshKeyArgs, opts?: CustomResourceOptions);
@overload
def SshKey(resource_name: str,
           args: SshKeyArgs,
           opts: Optional[ResourceOptions] = None)

@overload
def SshKey(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           public_key: Optional[str] = None,
           labels: Optional[Mapping[str, str]] = None,
           name: Optional[str] = None)
func NewSshKey(ctx *Context, name string, args SshKeyArgs, opts ...ResourceOption) (*SshKey, error)
public SshKey(string name, SshKeyArgs args, CustomResourceOptions? opts = null)
public SshKey(String name, SshKeyArgs args)
public SshKey(String name, SshKeyArgs args, CustomResourceOptions options)
type: hcloud:SshKey
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var sshKeyResource = new HCloud.SshKey("sshKeyResource", new()
{
    PublicKey = "string",
    Labels = 
    {
        { "string", "string" },
    },
    Name = "string",
});
Copy
example, err := hcloud.NewSshKey(ctx, "sshKeyResource", &hcloud.SshKeyArgs{
	PublicKey: pulumi.String("string"),
	Labels: pulumi.StringMap{
		"string": pulumi.String("string"),
	},
	Name: pulumi.String("string"),
})
Copy
var sshKeyResource = new SshKey("sshKeyResource", SshKeyArgs.builder()
    .publicKey("string")
    .labels(Map.of("string", "string"))
    .name("string")
    .build());
Copy
ssh_key_resource = hcloud.SshKey("sshKeyResource",
    public_key="string",
    labels={
        "string": "string",
    },
    name="string")
Copy
const sshKeyResource = new hcloud.SshKey("sshKeyResource", {
    publicKey: "string",
    labels: {
        string: "string",
    },
    name: "string",
});
Copy
type: hcloud:SshKey
properties:
    labels:
        string: string
    name: string
    publicKey: string
Copy

SshKey Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The SshKey resource accepts the following input properties:

PublicKey This property is required. string
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
Labels Dictionary<string, string>
User-defined labels (key-value pairs) for the resource.
Name string
Name of the SSH Key.
PublicKey This property is required. string
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
Labels map[string]string
User-defined labels (key-value pairs) for the resource.
Name string
Name of the SSH Key.
publicKey This property is required. String
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
labels Map<String,String>
User-defined labels (key-value pairs) for the resource.
name String
Name of the SSH Key.
publicKey This property is required. string
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
labels {[key: string]: string}
User-defined labels (key-value pairs) for the resource.
name string
Name of the SSH Key.
public_key This property is required. str
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
labels Mapping[str, str]
User-defined labels (key-value pairs) for the resource.
name str
Name of the SSH Key.
publicKey This property is required. String
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
labels Map<String>
User-defined labels (key-value pairs) for the resource.
name String
Name of the SSH Key.

Outputs

All input properties are implicitly available as output properties. Additionally, the SshKey resource produces the following output properties:

Fingerprint string
Fingerprint of the SSH public key.
Id string
The provider-assigned unique ID for this managed resource.
Fingerprint string
Fingerprint of the SSH public key.
Id string
The provider-assigned unique ID for this managed resource.
fingerprint String
Fingerprint of the SSH public key.
id String
The provider-assigned unique ID for this managed resource.
fingerprint string
Fingerprint of the SSH public key.
id string
The provider-assigned unique ID for this managed resource.
fingerprint str
Fingerprint of the SSH public key.
id str
The provider-assigned unique ID for this managed resource.
fingerprint String
Fingerprint of the SSH public key.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing SshKey Resource

Get an existing SshKey resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SshKeyState, opts?: CustomResourceOptions): SshKey
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        fingerprint: Optional[str] = None,
        labels: Optional[Mapping[str, str]] = None,
        name: Optional[str] = None,
        public_key: Optional[str] = None) -> SshKey
func GetSshKey(ctx *Context, name string, id IDInput, state *SshKeyState, opts ...ResourceOption) (*SshKey, error)
public static SshKey Get(string name, Input<string> id, SshKeyState? state, CustomResourceOptions? opts = null)
public static SshKey get(String name, Output<String> id, SshKeyState state, CustomResourceOptions options)
resources:  _:    type: hcloud:SshKey    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Fingerprint string
Fingerprint of the SSH public key.
Labels Dictionary<string, string>
User-defined labels (key-value pairs) for the resource.
Name string
Name of the SSH Key.
PublicKey string
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
Fingerprint string
Fingerprint of the SSH public key.
Labels map[string]string
User-defined labels (key-value pairs) for the resource.
Name string
Name of the SSH Key.
PublicKey string
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
fingerprint String
Fingerprint of the SSH public key.
labels Map<String,String>
User-defined labels (key-value pairs) for the resource.
name String
Name of the SSH Key.
publicKey String
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
fingerprint string
Fingerprint of the SSH public key.
labels {[key: string]: string}
User-defined labels (key-value pairs) for the resource.
name string
Name of the SSH Key.
publicKey string
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
fingerprint str
Fingerprint of the SSH public key.
labels Mapping[str, str]
User-defined labels (key-value pairs) for the resource.
name str
Name of the SSH Key.
public_key str
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.
fingerprint String
Fingerprint of the SSH public key.
labels Map<String>
User-defined labels (key-value pairs) for the resource.
name String
Name of the SSH Key.
publicKey String
Public key of the SSH Key pair. If this is a file, it can be read using the file interpolation function.

Import

$ pulumi import hcloud:index/sshKey:SshKey example "$SSH_KEY_ID"
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Hetzner Cloud pulumi/pulumi-hcloud
License
Apache-2.0
Notes
This Pulumi package is based on the hcloud Terraform Provider.