Skip to content

saturnops/terraform-aws-keypair

Repository files navigation

AWS EC2 Keypair


This reusable Terraform module streamlines the creation and management of an EC2 key pair on AWS. It generates the key pair, securely stores the private key in AWS Systems Manager Parameter Store (SSM), and returns the key pair name and SSM parameter ARN for easy reference in other infrastructure resources. By using this module, you can efficiently manage key pairs while maintaining security and compliance in your AWS environment.

Usage Example

module "key_pair" {
  source = "saturnops/keypair/aws"
  key_name           = "example-key"
  environment        = "production"
  ssm_parameter_path = "production-example-key"
}

Refer this for more examples.

Retrieve Private Key

To Retrieve the Private key from SSM:

aws ssm get-parameter --name "<ssm_parameter_path>" --region "<region>" --query Parameter.Value --output text

Additionally, to save the private key to a file:

aws ssm get-parameter --name "<ssm_parameter_path>" --region "<region>" --with-decryption --query Parameter.Value --output text > keypair.pem

IAM Permission

The required IAM permissions to create resources from this module can be found here

Requirements

Name Version
terraform >= 1.0
aws >= 4.21
tls >= 3.4

Providers

Name Version
aws >= 4.21

Modules

Name Source Version
key_pair terraform-aws-modules/key-pair/aws 2.0.0

Resources

Name Type
aws_ssm_parameter.ssm_ec2_keypair resource

Inputs

Name Description Type Default Required
environment Specifies the identifier for the environment where the key pair will be used. string "" no
key_name Specifies the name to be assigned to the key pair that will be generated. string "" no
ssm_parameter_path Specifies the SSM parameter name that will be used to store the generated key pair. string "/example/ssm" no

Outputs

Name Description
key_pair_name The name of the key pair generated for the EC2 instance.
ssm_parameter_arn The Amazon Resource Name (ARN) of the SSM parameter used to store the EC2 instance key pair.

  • Please give our GitHub repository a ⭐️ to show your support and increase its visibility..

About

SSH Key Pair (AWS) Terraform Module

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages