KeyPair

Provides an EC2 key pair resource. A key pair is used to control login access to EC2 instances.

Currently this resource requires an existing user-supplied key pair. This key pair’s public key will be registered with AWS to allow logging-in to EC2 instances.

When importing an existing key pair the public key material may be in any format supported by AWS. Supported formats (per the AWS documentation) are:

  • OpenSSH public key format (the format in ~/.ssh/authorized_keys)
  • Base64 encoded DER format
  • SSH public key file format as specified in RFC4716

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var deployer = new Aws.Ec2.KeyPair("deployer", new Aws.Ec2.KeyPairArgs
        {
            PublicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com",
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/ec2"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        _, err := ec2.NewKeyPair(ctx, "deployer", &ec2.KeyPairArgs{
            PublicKey: pulumi.String("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com"),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

deployer = aws.ec2.KeyPair("deployer", public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const deployer = new aws.ec2.KeyPair("deployer", {
    publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com",
});

Create a KeyPair Resource

new KeyPair(name: string, args: KeyPairArgs, opts?: CustomResourceOptions);
def KeyPair(resource_name, opts=None, key_name=None, key_name_prefix=None, public_key=None, tags=None, __props__=None);
func NewKeyPair(ctx *Context, name string, args KeyPairArgs, opts ...ResourceOption) (*KeyPair, error)
public KeyPair(string name, KeyPairArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args KeyPairArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args KeyPairArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args KeyPairArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

KeyPair Resource Properties

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

Inputs

The KeyPair resource accepts the following input properties:

PublicKey string

The public key material.

KeyName string

The name for the key pair.

KeyNamePrefix string

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

Tags Dictionary<string, string>

Key-value map of resource tags

PublicKey string

The public key material.

KeyName string

The name for the key pair.

KeyNamePrefix string

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

Tags map[string]string

Key-value map of resource tags

publicKey string

The public key material.

keyName string

The name for the key pair.

keyNamePrefix string

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

tags {[key: string]: string}

Key-value map of resource tags

public_key str

The public key material.

key_name str

The name for the key pair.

key_name_prefix str

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

tags Dict[str, str]

Key-value map of resource tags

Outputs

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

Arn string

The key pair ARN.

Fingerprint string

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

Id string
The provider-assigned unique ID for this managed resource.
KeyPairId string

The key pair ID.

Arn string

The key pair ARN.

Fingerprint string

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

Id string
The provider-assigned unique ID for this managed resource.
KeyPairId string

The key pair ID.

arn string

The key pair ARN.

fingerprint string

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

id string
The provider-assigned unique ID for this managed resource.
keyPairId string

The key pair ID.

arn str

The key pair ARN.

fingerprint str

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

id str
The provider-assigned unique ID for this managed resource.
key_pair_id str

The key pair ID.

Look up an Existing KeyPair Resource

Get an existing KeyPair 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?: KeyPairState, opts?: CustomResourceOptions): KeyPair
static get(resource_name, id, opts=None, arn=None, fingerprint=None, key_name=None, key_name_prefix=None, key_pair_id=None, public_key=None, tags=None, __props__=None);
func GetKeyPair(ctx *Context, name string, id IDInput, state *KeyPairState, opts ...ResourceOption) (*KeyPair, error)
public static KeyPair Get(string name, Input<string> id, KeyPairState? state, CustomResourceOptions? opts = null)
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.

The following state arguments are supported:

Arn string

The key pair ARN.

Fingerprint string

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

KeyName string

The name for the key pair.

KeyNamePrefix string

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

KeyPairId string

The key pair ID.

PublicKey string

The public key material.

Tags Dictionary<string, string>

Key-value map of resource tags

Arn string

The key pair ARN.

Fingerprint string

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

KeyName string

The name for the key pair.

KeyNamePrefix string

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

KeyPairId string

The key pair ID.

PublicKey string

The public key material.

Tags map[string]string

Key-value map of resource tags

arn string

The key pair ARN.

fingerprint string

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

keyName string

The name for the key pair.

keyNamePrefix string

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

keyPairId string

The key pair ID.

publicKey string

The public key material.

tags {[key: string]: string}

Key-value map of resource tags

arn str

The key pair ARN.

fingerprint str

The MD5 public key fingerprint as specified in section 4 of RFC 4716.

key_name str

The name for the key pair.

key_name_prefix str

Creates a unique name beginning with the specified prefix. Conflicts with key_name.

key_pair_id str

The key pair ID.

public_key str

The public key material.

tags Dict[str, str]

Key-value map of resource tags

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.