AWS Key Pair Terraform module
Terraform module which creates EC2 key pair on AWS.
Usage
EC2 Key pair w/ module created key material
module "key_pair" {
source = "terraform-aws-modules/key-pair/aws"
key_name = "deployer-one"
create_private_key = true
}
EC2 Key pair w/ externally created public key material
resource "tls_private_key" "this" {
algorithm = "RSA"
}
module "key_pair" {
source = "terraform-aws-modules/key-pair/aws"
key_name = "deployer-two"
public_key = trimspace(tls_private_key.this.public_key_openssh)
}
EC2 Key pair w/ existing public key material
module "key_pair" {
source = "terraform-aws-modules/key-pair/aws"
key_name = "deployer-three"
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 = false
# ... omitted
}
Examples:
- Complete - Create EC2 key pair
Authors
Module is maintained by Anton Babenko with help from these awesome contributors.
License
Apache 2 Licensed. See LICENSE for full details.