1. Packages
  2. DigitalOcean
  3. API Docs
  4. getSshKey
DigitalOcean v4.27.0 published on Wednesday, Mar 13, 2024 by Pulumi

digitalocean.getSshKey

Explore with Pulumi AI

digitalocean logo
DigitalOcean v4.27.0 published on Wednesday, Mar 13, 2024 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 exampleSshKey = digitalocean.getSshKey({
        name: "example",
    });
    const exampleDroplet = new digitalocean.Droplet("exampleDroplet", {
        image: "ubuntu-18-04-x64",
        region: "nyc2",
        size: "s-1vcpu-1gb",
        sshKeys: [exampleSshKey.then(exampleSshKey => exampleSshKey.id)],
    });
    
    import pulumi
    import pulumi_digitalocean as digitalocean
    
    example_ssh_key = digitalocean.get_ssh_key(name="example")
    example_droplet = digitalocean.Droplet("exampleDroplet",
        image="ubuntu-18-04-x64",
        region="nyc2",
        size="s-1vcpu-1gb",
        ssh_keys=[example_ssh_key.id])
    
    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 {
    		exampleSshKey, err := digitalocean.LookupSshKey(ctx, &digitalocean.LookupSshKeyArgs{
    			Name: "example",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = digitalocean.NewDroplet(ctx, "exampleDroplet", &digitalocean.DropletArgs{
    			Image:  pulumi.String("ubuntu-18-04-x64"),
    			Region: pulumi.String("nyc2"),
    			Size:   pulumi.String("s-1vcpu-1gb"),
    			SshKeys: pulumi.StringArray{
    				*pulumi.Int(exampleSshKey.Id),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using DigitalOcean = Pulumi.DigitalOcean;
    
    return await Deployment.RunAsync(() => 
    {
        var exampleSshKey = DigitalOcean.GetSshKey.Invoke(new()
        {
            Name = "example",
        });
    
        var exampleDroplet = new DigitalOcean.Droplet("exampleDroplet", new()
        {
            Image = "ubuntu-18-04-x64",
            Region = "nyc2",
            Size = "s-1vcpu-1gb",
            SshKeys = new[]
            {
                exampleSshKey.Apply(getSshKeyResult => getSshKeyResult.Id),
            },
        });
    
    });
    
    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 exampleSshKey = DigitaloceanFunctions.getSshKey(GetSshKeyArgs.builder()
                .name("example")
                .build());
    
            var exampleDroplet = new Droplet("exampleDroplet", DropletArgs.builder()        
                .image("ubuntu-18-04-x64")
                .region("nyc2")
                .size("s-1vcpu-1gb")
                .sshKeys(exampleSshKey.applyValue(getSshKeyResult -> getSshKeyResult.id()))
                .build());
    
        }
    }
    
    resources:
      exampleDroplet:
        type: digitalocean:Droplet
        properties:
          image: ubuntu-18-04-x64
          region: nyc2
          size: s-1vcpu-1gb
          sshKeys:
            - ${exampleSshKey.id}
    variables:
      exampleSshKey:
        fn::invoke:
          Function: digitalocean:getSshKey
          Arguments:
            name: example
    

    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(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]
    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: digitalocean:index/getSshKey:getSshKey
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Name string
    The name of the ssh key.
    Name string
    The name of the ssh key.
    name String
    The name of the ssh key.
    name string
    The name of the ssh key.
    name str
    The name of the ssh key.
    name 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 logo
    DigitalOcean v4.27.0 published on Wednesday, Mar 13, 2024 by Pulumi