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/v4/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/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);
@overload
def KeyPair(resource_name: str,
            opts: Optional[ResourceOptions] = None,
            key_name: Optional[str] = None,
            key_name_prefix: Optional[str] = None,
            public_key: Optional[str] = None,
            tags: Optional[Mapping[str, str]] = None,
            tags_all: Optional[Mapping[str, str]] = None)
@overload
def KeyPair(resource_name: str,
            args: KeyPairArgs,
            opts: Optional[ResourceOptions] = 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.
args KeyPairArgs
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 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>
TagsAll Dictionary<string, string>
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
TagsAll map[string]string
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}
tagsAll {[key: string]: string}
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 Mapping[str, str]
tags_all Mapping[str, str]

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
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        arn: Optional[str] = None,
        fingerprint: Optional[str] = None,
        key_name: Optional[str] = None,
        key_name_prefix: Optional[str] = None,
        key_pair_id: Optional[str] = None,
        public_key: Optional[str] = None,
        tags: Optional[Mapping[str, str]] = None,
        tags_all: Optional[Mapping[str, str]] = None) -> KeyPair
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>
TagsAll Dictionary<string, string>
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
TagsAll map[string]string
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}
tagsAll {[key: string]: string}
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 Mapping[str, str]
tags_all Mapping[str, str]

Import

Key Pairs can be imported using the key_name, e.g.

 $ pulumi import aws:ec2/keyPair:KeyPair deployer deployer-key

Package Details

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