2015-01-06 06:44:18 +01:00
---
layout: "aws"
page_title: "AWS: aws_key_pair"
sidebar_current: "docs-aws-resource-key-pair"
description: |-
Provides a Key Pair resource. Currently this supports importing an existing key pair but not creating a new key pair.
---
# aws\_key\_pair
2017-02-18 23:48:50 +01:00
Provides an [EC2 key pair ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html ) resource. A key pair is used to control login access to EC2 instances.
2015-01-06 06:44:18 +01:00
2017-03-16 20:52:47 +01:00
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.
2015-01-06 06:44:18 +01:00
2016-01-14 21:55:39 +01:00
When importing an existing key pair the public key material may be in any format supported by AWS. Supported formats (per the [AWS documentation ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws )) are:
2015-01-06 06:44:18 +01:00
* 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
2017-04-17 12:17:54 +02:00
```hcl
2015-01-06 06:44:18 +01:00
resource "aws_key_pair" "deployer" {
2017-02-18 23:48:50 +01:00
key_name = "deployer-key"
2015-01-06 06:44:18 +01:00
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com"
}
```
## Argument Reference
The following arguments are supported:
2016-11-09 13:54:12 +01:00
* `key_name` - (Optional) The name for the key pair.
2016-11-09 16:35:51 +01:00
* `key_name_prefix` - (Optional) Creates a unique name beginning with the specified prefix. Conflicts with `key_name` .
* `public_key` - (Required) The public key material.
2015-01-06 06:44:18 +01:00
## Attributes Reference
The following attributes are exported:
* `key_name` - The key pair name.
* `fingerprint` - The MD5 public key fingerprint as specified in section 4 of RFC 4716.
2016-07-21 00:28:59 +02:00
## Import
2017-02-18 23:48:50 +01:00
Key Pairs can be imported using the `key_name` , e.g.
2016-07-21 00:28:59 +02:00
```
$ terraform import aws_key_pair.deployer deployer-key
2016-11-09 16:35:51 +01:00
```