Skip to content

Commit

Permalink
Merge pull request #3 from RohitSquareops/main
Browse files Browse the repository at this point in the history
updated readme.md, added output, indentation
  • Loading branch information
sunil-kumar-squareops authored May 18, 2023
2 parents 44d5e91 + 8799815 commit bb56bc6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 34 deletions.
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
[squareops_avatar]: https://squareops.com/wp-content/uploads/2022/12/squareops-logo.png

### [SquareOps Technologies](https://squareops.com/) Your DevOps Partner for Accelerating cloud journey.


<br>

Terraform module which creates EC2 key pair on AWS. The private key will be stored in AWS Systems Manager's Parameter Store.
This module is a reusable Terraform module that simplifies the creation and management of an EC2 key pair on AWS. This module creates an EC2 key pair and securely stores the private key in the AWS Systems Manager Parameter Store (SSM). The module also returns the key pair name and the SSM parameter ARN for later use in other resources, making it easy to reference the key pair in other parts of your infrastructure. Using this module can help you save time and effort in managing your key pairs while ensuring security and compliance in your AWS environment.

## Usage Example

```hcl
module "key_pair" {
source = "squareops/keypair/aws"
environment = "production"
key_name = "example-key"
environment = "production"
ssm_parameter_path = "production-example-key"
}
```
Expand All @@ -28,12 +25,12 @@ Refer [this](https://github.com/squareops/terraform-aws-keypair/tree/main/exampl

To Retrieve the Private key from SSM:
```bash
aws ssm get-parameter --region=us-east-1 --name "production-example-key" --with-decryption --output text --query Parameter.Value
aws ssm get-parameter --name "<ssm_parameter_path>" --region "<region>" --query Parameter.Value --output text
```

Additionally, to save the private to a file:
Additionally, to save the private key to a file:
```bash
aws ssm get-parameter --region=us-east-1 --name "production-example-key" --with-decryption --output text --query Parameter.Value > private-key.pem
aws ssm get-parameter --name "<ssm_parameter_path>" --region "<region>" --with-decryption --query Parameter.Value --output text > keypair.pem
```

## IAM Permission
Expand Down Expand Up @@ -71,16 +68,16 @@ The required IAM permissions to create resources from this module can be found [

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_environment"></a> [environment](#input\_environment) | Environment identifier for the key pair | `string` | `""` | no |
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | The name for the key pair to be generated | `string` | `""` | no |
| <a name="input_ssm_parameter_path"></a> [ssm\_parameter\_path](#input\_ssm\_parameter\_path) | The name of the ssm parameter for storing the keypair | `string` | `"/example/ssm"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Specifies the identifier for the environment where the key pair will be used. | `string` | `""` | no |
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | Specifies the name to be assigned to the key pair that will be generated. | `string` | `""` | no |
| <a name="input_ssm_parameter_path"></a> [ssm\_parameter\_path](#input\_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 |
|------|-------------|
| <a name="output_key_pair_name"></a> [key\_pair\_name](#output\_key\_pair\_name) | The key pair name. |
| <a name="output_ssm_parameter_arn"></a> [ssm\_parameter\_arn](#output\_ssm\_parameter\_arn) | The SSM parameter ARN of key pair. |
| <a name="output_key_pair_name"></a> [key\_pair\_name](#output\_key\_pair\_name) | The name of the key pair generated for the EC2 instance. |
| <a name="output_ssm_parameter_arn"></a> [ssm\_parameter\_arn](#output\_ssm\_parameter\_arn) | The Amazon Resource Name (ARN) of the SSM parameter used to store the EC2 instance key pair. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## Contribution & Issue Reporting
Expand Down
3 changes: 2 additions & 1 deletion examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ No inputs.

| Name | Description |
|------|-------------|
| <a name="output_key_pair_name"></a> [key\_pair\_name](#output\_key\_pair\_name) | The key pair name. |
| <a name="output_key_pair_name"></a> [key\_pair\_name](#output\_key\_pair\_name) | The name of the key pair generated for the EC2 instance. |
| <a name="output_ssm_parameter_arn"></a> [ssm\_parameter\_arn](#output\_ssm\_parameter\_arn) | The Amazon Resource Name (ARN) of the SSM parameter used to store the EC2 instance key pair. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
23 changes: 9 additions & 14 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
provider "aws" {
region = local.region
}

locals {
name = "key"
region = "us-east-2"
environment = "prod"
region = "us-east-1"
name = "skaf"
additional_tags = {
Owner = "organization_name"
Expires = "Never"
Department = "Engineering"
}
}

################################################################################
# Key Pair Module
################################################################################

module "key_pair" {
source = "squareops/keypair/aws"

source = "squareops/keypair/aws"
key_name = format("%s-%s-kp", local.environment, local.name)
ssm_parameter_path = format("%s-%s-ssm", local.environment, local.name) #SSM parameter secret name
environment = local.environment

ssm_parameter_path = format("%s-%s-ssm", local.environment, local.name) #SSM parameter secret name
}
7 changes: 6 additions & 1 deletion examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
output "key_pair_name" {
description = "The key pair name."
description = "The name of the key pair generated for the EC2 instance."
value = module.key_pair.key_pair_name
}

output "ssm_parameter_arn" {
description = "The Amazon Resource Name (ARN) of the SSM parameter used to store the EC2 instance key pair."
value = module.key_pair.ssm_parameter_arn
}
6 changes: 6 additions & 0 deletions examples/complete/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
provider "aws" {
region = local.region
default_tags {
tags = local.additional_tags
}
}
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "key_pair_name" {
description = "The key pair name."
description = "The name of the key pair generated for the EC2 instance."
value = module.key_pair.key_pair_name
}

output "ssm_parameter_arn" {
description = "The SSM parameter ARN of key pair."
description = "The Amazon Resource Name (ARN) of the SSM parameter used to store the EC2 instance key pair."
value = aws_ssm_parameter.ssm_ec2_keypair.arn
}
6 changes: 3 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
variable "key_name" {
description = "The name for the key pair to be generated"
description = "Specifies the name to be assigned to the key pair that will be generated."
default = ""
type = string
}

variable "environment" {
description = "Environment identifier for the key pair"
description = "Specifies the identifier for the environment where the key pair will be used."
default = ""
type = string
}

variable "ssm_parameter_path" {
description = "The name of the ssm parameter for storing the keypair"
description = "Specifies the SSM parameter name that will be used to store the generated key pair."
default = "/example/ssm"
type = string
}

0 comments on commit bb56bc6

Please sign in to comment.