Skip to content

Commit 4bdc26f

Browse files
authored
Fix splat (#4)
* Fix splat * Fix ternary
1 parent c84b1b6 commit 4bdc26f

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
Terraform module that provisions an SSH TLS key pair and writes it to SSM Parameter Store.
1010

11+
This is useful for bot accounts (e.g. for GitHub). Easily rotate SSH secrets by simply tainting the module resource and reapplying.
12+
1113

1214
---
1315

@@ -68,23 +70,23 @@ Available targets:
6870
lint Lint terraform code
6971
7072
```
71-
7273
## Inputs
7374

7475
| Name | Description | Type | Default | Required |
7576
|------|-------------|:----:|:-----:|:-----:|
7677
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
7778
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
7879
| ecdsa_curve | When ssh_key_algorithm is 'ECDSA', the name of the elliptic curve to use. May be any one of 'P256', 'P384' or P521' | string | `P256` | no |
79-
| enable_kms_key_rotation | Whether KMS key rotation is enabled | string | `true` | no |
8080
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `true` | no |
81+
| kms_key_id | KMS Key ID used for encryption | string | `` | no |
8182
| name | Application or solution name (e.g. `app`) | string | - | yes |
8283
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
8384
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | string | `true` | no |
8485
| rsa_bits | When ssh_key_algorithm is 'RSA', the size of the generated RSA key in bits | string | `4096` | no |
8586
| ssh_key_algorithm | SSH key algorithm to use. Currently-supported values are 'RSA' and 'ECDSA' | string | `RSA` | no |
8687
| ssh_private_key_name | SSM Parameter name of the SSH private key | string | `` | no |
8788
| ssh_public_key_name | SSM Parameter name of the SSH public key | string | `` | no |
89+
| ssm_path_format | SSM path format | string | `/%s/%s` | no |
8890
| ssm_path_prefix | The SSM parameter path prefix (e.g. /$ssm_path_prefix/$key_name) | string | `ssh_keys` | no |
8991
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
9092
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |

README.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ related:
4040
description: |-
4141
Terraform module that provisions an SSH TLS key pair and writes it to SSM Parameter Store.
4242
43+
This is useful for bot accounts (e.g. for GitHub). Easily rotate SSH secrets by simply tainting the module resource and reapplying.
44+
4345
# How to use this project
4446
usage: |-
4547
```hcl

docs/terraform.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
21
## Inputs
32

43
| Name | Description | Type | Default | Required |
54
|------|-------------|:----:|:-----:|:-----:|
65
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
76
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
87
| ecdsa_curve | When ssh_key_algorithm is 'ECDSA', the name of the elliptic curve to use. May be any one of 'P256', 'P384' or P521' | string | `P256` | no |
9-
| enable_kms_key_rotation | Whether KMS key rotation is enabled | string | `true` | no |
108
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `true` | no |
9+
| kms_key_id | KMS Key ID used for encryption | string | `` | no |
1110
| name | Application or solution name (e.g. `app`) | string | - | yes |
1211
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
1312
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | string | `true` | no |
1413
| rsa_bits | When ssh_key_algorithm is 'RSA', the size of the generated RSA key in bits | string | `4096` | no |
1514
| ssh_key_algorithm | SSH key algorithm to use. Currently-supported values are 'RSA' and 'ECDSA' | string | `RSA` | no |
1615
| ssh_private_key_name | SSM Parameter name of the SSH private key | string | `` | no |
1716
| ssh_public_key_name | SSM Parameter name of the SSH public key | string | `` | no |
17+
| ssm_path_format | SSM path format | string | `/%s/%s` | no |
1818
| ssm_path_prefix | The SSM parameter path prefix (e.g. /$ssm_path_prefix/$key_name) | string | `ssh_keys` | no |
1919
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
2020
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |

main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ locals {
1717
default_private_key_name = "${local.remapped_label_id}_private_key"
1818
public_key_name = "${length(var.ssh_public_key_name) > 0 ? var.ssh_public_key_name : local.default_public_key_name}"
1919
private_key_name = "${length(var.ssh_private_key_name) > 0 ? var.ssh_private_key_name : local.default_private_key_name}"
20-
ssh_public_key_ssm_path = "${format("/%s/%s", var.ssm_path_prefix, local.public_key_name)}"
21-
ssh_private_key_ssm_path = "${format("/%s/%s", var.ssm_path_prefix, local.private_key_name)}"
20+
ssh_public_key_ssm_path = "${format(var.ssm_path_format, var.ssm_path_prefix, local.public_key_name)}"
21+
ssh_private_key_ssm_path = "${format(var.ssm_path_format, var.ssm_path_prefix, local.private_key_name)}"
22+
kms_key_id = "${length(var.kms_key_id) > 0 ? var.kms_key_id : format("alias/%s-%s-chamber", var.namespace, var.stage)}"
2223
}
2324

24-
data "aws_kms_key" "chamber_kms_key" {
25+
data "aws_kms_key" "kms_key" {
2526
count = "${local.enabled ? 1 : 0}"
26-
key_id = "${format("alias/%s-%s-chamber", var.namespace, var.stage)}"
27+
key_id = "${local.kms_key_id}"
2728
}
2829

2930
resource "tls_private_key" "default_rsa" {
@@ -43,7 +44,7 @@ resource "aws_ssm_parameter" "private_rsa_key" {
4344
name = "${local.ssh_private_key_ssm_path}"
4445
description = "TLS Private Key"
4546
type = "SecureString"
46-
key_id = "${join("", data.aws_kms_key.chamber_kms_key.*.id)}"
47+
key_id = "${join("", data.aws_kms_key.kms_key.*.id)}"
4748
value = "${join("", tls_private_key.default_rsa.*.private_key_pem)}"
4849
overwrite = "${var.overwrite_ssm_parameter}"
4950
depends_on = ["tls_private_key.default_rsa"]
@@ -66,7 +67,7 @@ resource "aws_ssm_parameter" "private_ecdsa_key" {
6667
name = "${local.ssh_private_key_ssm_path}"
6768
description = "TLS Private Key (${var.ssh_key_algorithm})"
6869
type = "SecureString"
69-
key_id = "${join("",data.aws_kms_key.chamber_kms_key.id)}"
70+
key_id = "${join("",data.aws_kms_key.kms_key.*.id)}"
7071
value = "${join("", tls_private_key.default_ecdsa.*.private_key_pem)}"
7172
overwrite = "${var.overwrite_ssm_parameter}"
7273
depends_on = ["tls_private_key.default_ecdsa"]

variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ variable "overwrite_ssm_parameter" {
4343
description = "Whether to overwrite an existing SSM parameter"
4444
}
4545

46-
variable "enable_kms_key_rotation" {
46+
variable "ssm_path_format" {
4747
type = "string"
48-
default = "true"
49-
description = "Whether KMS key rotation is enabled"
48+
description = "SSM path format"
49+
default = "/%s/%s"
50+
}
51+
52+
variable "kms_key_id" {
53+
type = "string"
54+
description = "KMS Key ID used for encryption"
55+
default = ""
5056
}
5157

5258
variable "ssh_public_key_name" {

0 commit comments

Comments
 (0)