Skip to content

aboutyou/terraform-aws-key-pair

 
 

Repository files navigation

AWS Key Pair Terraform module

Terraform module which creates EC2 key pair resource by Terraform AWS provider.

This type of resources are supported:

Terraform versions

Only Terraform 0.12 is supported.

Usage

Create new EC2 key pair

resource "tls_private_key" "this" {
  algorithm = "RSA"
}

module "key_pair" {
  source = "terraform-aws-modules/key-pair/aws"

  key_name   = "deployer-one"
  public_key = tls_private_key.this.public_key_openssh
}

Import existing public key as EC2 key pair

module "key_pair" {
  source = "terraform-aws-modules/key-pair/aws"

  key_name   = "deployer-two"
  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com"

}

Conditional creation

Sometimes you need to have a way to create key pair conditionally but Terraform does not allow to use count inside module block, so the solution is to specify argument create_key_pair.

# This EC2 key pair will not be created
module "key_pair" {
  source = "terraform-aws-modules/key-pair/aws"

  create_key_pair = false
  # ... omitted
}

Examples:

Requirements

Name Version
terraform >= 0.12.6
aws >= 2.46

Providers

Name Version
aws >= 2.46

Modules

No Modules.

Resources

Name
aws_key_pair

Inputs

Name Description Type Default Required
create_key_pair Controls if key pair should be created bool true no
key_name The name for the key pair. string null no
key_name_prefix Creates a unique name beginning with the specified prefix. Conflicts with key_name. string null no
public_key The public key material. string "" no
tags A map of tags to add to key pair resource. map(string) {} no

Outputs

Name Description
this_key_pair_fingerprint The MD5 public key fingerprint as specified in section 4 of RFC 4716.
this_key_pair_key_name The key pair name.
this_key_pair_key_pair_id The key pair ID.

Authors

Module managed by Anton Babenko.

License

Apache 2 Licensed. See LICENSE for full details.

Packages

No packages published

Languages

  • HCL 91.2%
  • Makefile 8.8%