1. Packages
  2. Digitalocean Provider
  3. API Docs
  4. SshKey
DigitalOcean v4.33.0 published on Thursday, Sep 26, 2024 by Pulumi

digitalocean.SshKey

Explore with Pulumi AI

digitalocean logo
DigitalOcean v4.33.0 published on Thursday, Sep 26, 2024 by Pulumi

    Provides a DigitalOcean SSH key resource to allow you to manage SSH keys for Droplet access. Keys created with this resource can be referenced in your Droplet configuration via their ID or fingerprint.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as digitalocean from "@pulumi/digitalocean";
    import * as std from "@pulumi/std";
    
    // Create a new SSH key
    const _default = new digitalocean.SshKey("default", {
        name: "Example",
        publicKey: std.file({
            input: "/Users/myuser/.ssh/id_rsa.pub",
        }).then(invoke => invoke.result),
    });
    // Create a new Droplet using the SSH key
    const web = new digitalocean.Droplet("web", {
        image: "ubuntu-18-04-x64",
        name: "web-1",
        region: digitalocean.Region.NYC3,
        size: digitalocean.DropletSlug.DropletS1VCPU1GB,
        sshKeys: [_default.fingerprint],
    });
    
    import pulumi
    import pulumi_digitalocean as digitalocean
    import pulumi_std as std
    
    # Create a new SSH key
    default = digitalocean.SshKey("default",
        name="Example",
        public_key=std.file(input="/Users/myuser/.ssh/id_rsa.pub").result)
    # Create a new Droplet using the SSH key
    web = digitalocean.Droplet("web",
        image="ubuntu-18-04-x64",
        name="web-1",
        region=digitalocean.Region.NYC3,
        size=digitalocean.DropletSlug.DROPLET_S1_VCPU1_GB,
        ssh_keys=[default.fingerprint])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
    	"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: "/Users/myuser/.ssh/id_rsa.pub",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Create a new SSH key
    		_, err = digitalocean.NewSshKey(ctx, "default", &digitalocean.SshKeyArgs{
    			Name:      pulumi.String("Example"),
    			PublicKey: pulumi.String(invokeFile.Result),
    		})
    		if err != nil {
    			return err
    		}
    		// Create a new Droplet using the SSH key
    		_, err = digitalocean.NewDroplet(ctx, "web", &digitalocean.DropletArgs{
    			Image:  pulumi.String("ubuntu-18-04-x64"),
    			Name:   pulumi.String("web-1"),
    			Region: pulumi.String(digitalocean.RegionNYC3),
    			Size:   pulumi.String(digitalocean.DropletSlugDropletS1VCPU1GB),
    			SshKeys: pulumi.StringArray{
    				_default.Fingerprint,
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using DigitalOcean = Pulumi.DigitalOcean;
    using Std = Pulumi.Std;
    
    return await Deployment.RunAsync(() => 
    {
        // Create a new SSH key
        var @default = new DigitalOcean.SshKey("default", new()
        {
            Name = "Example",
            PublicKey = Std.File.Invoke(new()
            {
                Input = "/Users/myuser/.ssh/id_rsa.pub",
            }).Apply(invoke => invoke.Result),
        });
    
        // Create a new Droplet using the SSH key
        var web = new DigitalOcean.Droplet("web", new()
        {
            Image = "ubuntu-18-04-x64",
            Name = "web-1",
            Region = DigitalOcean.Region.NYC3,
            Size = DigitalOcean.DropletSlug.DropletS1VCPU1GB,
            SshKeys = new[]
            {
                @default.Fingerprint,
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.digitalocean.SshKey;
    import com.pulumi.digitalocean.SshKeyArgs;
    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) {
            // Create a new SSH key
            var default_ = new SshKey("default", SshKeyArgs.builder()
                .name("Example")
                .publicKey(StdFunctions.file(FileArgs.builder()
                    .input("/Users/myuser/.ssh/id_rsa.pub")
                    .build()).result())
                .build());
    
            // Create a new Droplet using the SSH key
            var web = new Droplet("web", DropletArgs.builder()
                .image("ubuntu-18-04-x64")
                .name("web-1")
                .region("nyc3")
                .size("s-1vcpu-1gb")
                .sshKeys(default_.fingerprint())
                .build());
    
        }
    }
    
    resources:
      # Create a new SSH key
      default:
        type: digitalocean:SshKey
        properties:
          name: Example
          publicKey:
            fn::invoke:
              Function: std:file
              Arguments:
                input: /Users/myuser/.ssh/id_rsa.pub
              Return: result
      # Create a new Droplet using the SSH key
      web:
        type: digitalocean:Droplet
        properties:
          image: ubuntu-18-04-x64
          name: web-1
          region: nyc3
          size: s-1vcpu-1gb
          sshKeys:
            - ${default.fingerprint}
    

    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,
               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: digitalocean:SshKey
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args SshKeyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args 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 string
    The unique name of the resource.
    args SshKeyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args SshKeyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args 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 DigitalOcean.SshKey("sshKeyResource", new()
    {
        PublicKey = "string",
        Name = "string",
    });
    
    example, err := digitalocean.NewSshKey(ctx, "sshKeyResource", &digitalocean.SshKeyArgs{
    	PublicKey: pulumi.String("string"),
    	Name:      pulumi.String("string"),
    })
    
    var sshKeyResource = new SshKey("sshKeyResource", SshKeyArgs.builder()
        .publicKey("string")
        .name("string")
        .build());
    
    ssh_key_resource = digitalocean.SshKey("sshKeyResource",
        public_key="string",
        name="string")
    
    const sshKeyResource = new digitalocean.SshKey("sshKeyResource", {
        publicKey: "string",
        name: "string",
    });
    
    type: digitalocean:SshKey
    properties:
        name: string
        publicKey: string
    

    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

    The SshKey resource accepts the following input properties:

    PublicKey string
    The public key. If this is a file, it can be read using the file interpolation function
    Name string
    The name of the SSH key for identification
    PublicKey string
    The public key. If this is a file, it can be read using the file interpolation function
    Name string
    The name of the SSH key for identification
    publicKey String
    The public key. If this is a file, it can be read using the file interpolation function
    name String
    The name of the SSH key for identification
    publicKey string
    The public key. If this is a file, it can be read using the file interpolation function
    name string
    The name of the SSH key for identification
    public_key str
    The public key. If this is a file, it can be read using the file interpolation function
    name str
    The name of the SSH key for identification
    publicKey String
    The public key. If this is a file, it can be read using the file interpolation function
    name String
    The name of the SSH key for identification

    Outputs

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

    Fingerprint string
    The fingerprint of the SSH key
    Id string
    The provider-assigned unique ID for this managed resource.
    Fingerprint string
    The fingerprint of the SSH key
    Id string
    The provider-assigned unique ID for this managed resource.
    fingerprint String
    The fingerprint of the SSH key
    id String
    The provider-assigned unique ID for this managed resource.
    fingerprint string
    The fingerprint of the SSH key
    id string
    The provider-assigned unique ID for this managed resource.
    fingerprint str
    The fingerprint of the SSH key
    id str
    The provider-assigned unique ID for this managed resource.
    fingerprint String
    The fingerprint of the SSH 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,
            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)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    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
    The fingerprint of the SSH key
    Name string
    The name of the SSH key for identification
    PublicKey string
    The public key. If this is a file, it can be read using the file interpolation function
    Fingerprint string
    The fingerprint of the SSH key
    Name string
    The name of the SSH key for identification
    PublicKey string
    The public key. If this is a file, it can be read using the file interpolation function
    fingerprint String
    The fingerprint of the SSH key
    name String
    The name of the SSH key for identification
    publicKey String
    The public key. If this is a file, it can be read using the file interpolation function
    fingerprint string
    The fingerprint of the SSH key
    name string
    The name of the SSH key for identification
    publicKey string
    The public key. If this is a file, it can be read using the file interpolation function
    fingerprint str
    The fingerprint of the SSH key
    name str
    The name of the SSH key for identification
    public_key str
    The public key. If this is a file, it can be read using the file interpolation function
    fingerprint String
    The fingerprint of the SSH key
    name String
    The name of the SSH key for identification
    publicKey String
    The public key. If this is a file, it can be read using the file interpolation function

    Import

    SSH Keys can be imported using the ssh key id, e.g.

    $ pulumi import digitalocean:index/sshKey:SshKey mykey 263654
    

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

    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.33.0 published on Thursday, Sep 26, 2024 by Pulumi