1. Packages
  2. DigitalOcean Provider
  3. API Docs
  4. getSshKey
DigitalOcean v4.42.0 published on Thursday, Apr 17, 2025 by Pulumi

digitalocean.getSshKey

Explore with Pulumi AI

DigitalOcean v4.42.0 published on Thursday, Apr 17, 2025 by Pulumi

Get information on a ssh key. This data source provides the name, public key, and fingerprint as configured on your DigitalOcean account. This is useful if the ssh key in question is not managed by the provider or you need to utilize any of the keys data.

An error is triggered if the provided ssh key name does not exist.

Example Usage

Get the ssh key:

import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const example = digitalocean.getSshKey({
    name: "example",
});
const exampleDroplet = new digitalocean.Droplet("example", {
    image: "ubuntu-18-04-x64",
    name: "example-1",
    region: digitalocean.Region.NYC2,
    size: digitalocean.DropletSlug.DropletS1VCPU1GB,
    sshKeys: [example.then(example => example.id)],
});
Copy
import pulumi
import pulumi_digitalocean as digitalocean

example = digitalocean.get_ssh_key(name="example")
example_droplet = digitalocean.Droplet("example",
    image="ubuntu-18-04-x64",
    name="example-1",
    region=digitalocean.Region.NYC2,
    size=digitalocean.DropletSlug.DROPLET_S1_VCPU1_GB,
    ssh_keys=[example.id])
Copy
package main

import (
	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := digitalocean.LookupSshKey(ctx, &digitalocean.LookupSshKeyArgs{
			Name: "example",
		}, nil)
		if err != nil {
			return err
		}
		_, err = digitalocean.NewDroplet(ctx, "example", &digitalocean.DropletArgs{
			Image:  pulumi.String("ubuntu-18-04-x64"),
			Name:   pulumi.String("example-1"),
			Region: pulumi.String(digitalocean.RegionNYC2),
			Size:   pulumi.String(digitalocean.DropletSlugDropletS1VCPU1GB),
			SshKeys: pulumi.StringArray{
				pulumi.Int(example.Id),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;

return await Deployment.RunAsync(() => 
{
    var example = DigitalOcean.GetSshKey.Invoke(new()
    {
        Name = "example",
    });

    var exampleDroplet = new DigitalOcean.Droplet("example", new()
    {
        Image = "ubuntu-18-04-x64",
        Name = "example-1",
        Region = DigitalOcean.Region.NYC2,
        Size = DigitalOcean.DropletSlug.DropletS1VCPU1GB,
        SshKeys = new[]
        {
            example.Apply(getSshKeyResult => getSshKeyResult.Id),
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.digitalocean.DigitaloceanFunctions;
import com.pulumi.digitalocean.inputs.GetSshKeyArgs;
import com.pulumi.digitalocean.Droplet;
import com.pulumi.digitalocean.DropletArgs;
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 example = DigitaloceanFunctions.getSshKey(GetSshKeyArgs.builder()
            .name("example")
            .build());

        var exampleDroplet = new Droplet("exampleDroplet", DropletArgs.builder()
            .image("ubuntu-18-04-x64")
            .name("example-1")
            .region("nyc2")
            .size("s-1vcpu-1gb")
            .sshKeys(example.id())
            .build());

    }
}
Copy
resources:
  exampleDroplet:
    type: digitalocean:Droplet
    name: example
    properties:
      image: ubuntu-18-04-x64
      name: example-1
      region: nyc2
      size: s-1vcpu-1gb
      sshKeys:
        - ${example.id}
variables:
  example:
    fn::invoke:
      function: digitalocean:getSshKey
      arguments:
        name: example
Copy

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>
Copy
def get_ssh_key(name: Optional[str] = None,
                opts: Optional[InvokeOptions] = None) -> GetSshKeyResult
def get_ssh_key_output(name: Optional[pulumi.Input[str]] = None,
                opts: Optional[InvokeOptions] = None) -> Output[GetSshKeyResult]
Copy
func LookupSshKey(ctx *Context, args *LookupSshKeyArgs, opts ...InvokeOption) (*LookupSshKeyResult, error)
func LookupSshKeyOutput(ctx *Context, args *LookupSshKeyOutputArgs, opts ...InvokeOption) LookupSshKeyResultOutput
Copy

> 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)
}
Copy
public static CompletableFuture<GetSshKeyResult> getSshKey(GetSshKeyArgs args, InvokeOptions options)
public static Output<GetSshKeyResult> getSshKey(GetSshKeyArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: digitalocean:index/getSshKey:getSshKey
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Name This property is required. string
The name of the ssh key.
Name This property is required. string
The name of the ssh key.
name This property is required. String
The name of the ssh key.
name This property is required. string
The name of the ssh key.
name This property is required. str
The name of the ssh key.
name This property is required. String
The name of the ssh key.

getSshKey Result

The following output properties are available:

Fingerprint string
The fingerprint of the public key of the ssh key.
Id int
The ID of the ssh key.
Name string
PublicKey string
The public key of the ssh key.
Fingerprint string
The fingerprint of the public key of the ssh key.
Id int
The ID of the ssh key.
Name string
PublicKey string
The public key of the ssh key.
fingerprint String
The fingerprint of the public key of the ssh key.
id Integer
The ID of the ssh key.
name String
publicKey String
The public key of the ssh key.
fingerprint string
The fingerprint of the public key of the ssh key.
id number
The ID of the ssh key.
name string
publicKey string
The public key of the ssh key.
fingerprint str
The fingerprint of the public key of the ssh key.
id int
The ID of the ssh key.
name str
public_key str
The public key of the ssh key.
fingerprint String
The fingerprint of the public key of the ssh key.
id Number
The ID of the ssh key.
name String
publicKey String
The public key of the ssh key.

Package Details

Repository
DigitalOcean pulumi/pulumi-digitalocean
License
Apache-2.0
Notes
This Pulumi package is based on the digitalocean Terraform Provider.
DigitalOcean v4.42.0 published on Thursday, Apr 17, 2025 by Pulumi