Skip to content

Commit a901af3

Browse files
authored
feat: make module complaint with terraform 1.3 (#5)
1 parent 4e77e08 commit a901af3

File tree

11 files changed

+46
-74
lines changed

11 files changed

+46
-74
lines changed

.github/workflows/docs.yml

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1+
name: Generate terraform docs
12
on:
23
pull_request:
34

45
jobs:
56
docs:
67
runs-on: ubuntu-latest
78
steps:
8-
- uses: actions/checkout@v2
9-
with:
10-
ref: ${{ github.event.pull_request.head.ref }}
9+
- uses: actions/checkout@v2
10+
with:
11+
ref: ${{ github.event.pull_request.head.ref }}
1112

12-
- name: Render terraform docs inside the examples/basic/README.md
13-
uses: terraform-docs/[email protected]
14-
with:
15-
working-dir: ./examples/basic/
16-
git-push: "false"
17-
output-file: README.md
18-
config-file: ".terraform-docs.yml"
13+
- name: Render terraform docs inside the examples/basic/README.md
14+
uses: terraform-docs/[email protected]
15+
with:
16+
working-dir: ./examples/basic/
17+
git-push: "false"
18+
output-file: README.md
19+
config-file: ".terraform-docs.yml"
1920

20-
- name: Render terraform docs inside the README.md
21-
uses: terraform-docs/[email protected]
22-
with:
23-
working-dir: .
24-
git-push: "true"
25-
output-file: README.md
26-
config-file: ".terraform-docs.yml"
21+
- name: Render terraform docs inside the README.md
22+
uses: terraform-docs/[email protected]
23+
with:
24+
working-dir: .
25+
git-push: "true"
26+
output-file: README.md
27+
config-file: ".terraform-docs.yml"

.github/workflows/pr-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
steps:
1111
- name: Lint PR
12-
uses: aslafy-z/conventional-pr-title-action@master
12+
uses: aslafy-z/conventional-pr-title-action@v2.4.1
1313
with:
1414
preset: conventional-changelog-angular@^5.0.6
1515
env:

.github/workflows/terraform.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup Terraform
1515
uses: hashicorp/setup-terraform@v1
1616
with:
17-
terraform_version: 1.0.4
17+
terraform_version: 1.3.0
1818

1919
- name: Ensure Terraform code is formated
2020
run: terraform fmt -check
@@ -24,4 +24,3 @@ jobs:
2424

2525
- name: Validate Terraform code
2626
run: terraform validate -no-color
27-

.github/workflows/tflint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Setup Terraform
1515
uses: hashicorp/setup-terraform@v1
1616
with:
17-
terraform_version: 1.0.4
17+
terraform_version: 1.3.0
1818

1919
- name: Terraform Init
2020
run: terraform init

.github/workflows/tfsec.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Terraform
1616
uses: hashicorp/setup-terraform@v1
1717
with:
18-
terraform_version: 1.0.4
18+
terraform_version: 1.3.0
1919

2020
- name: Terraform Init
2121
run: terraform init

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module "secrets" {
4545

4646
| Name | Version |
4747
|------|---------|
48-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
48+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
4949
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
5050

5151
## Providers
@@ -82,7 +82,7 @@ module "secrets" {
8282
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
8383
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
8484
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
85-
| <a name="input_kms_key"></a> [kms\_key](#input\_kms\_key) | enabled:<br> Whether to create KSM key.<br>description:<br> The description of the key as viewed in AWS console.<br>alias:<br> The display name of the alias. The name must start with the word alias followed by a forward slash. <br> If not specified, the alias name will be auto-generated.<br>deletion\_window\_in\_days:<br> Duration in days after which the key is deleted after destruction of the resource<br>enable\_key\_rotation:<br> Specifies whether key rotation is enabled. | <pre>object({<br> enabled = optional(bool)<br> description = optional(string)<br> alias = optional(string)<br> deletion_window_in_days = optional(number)<br> enable_key_rotation = optional(bool)<br> })</pre> | <pre>{<br> "deletion_window_in_days": 30,<br> "description": "Managed by Terraform",<br> "enable_key_rotation": true,<br> "enabled": true<br>}</pre> | no |
85+
| <a name="input_kms_key"></a> [kms\_key](#input\_kms\_key) | enabled:<br> Whether to create KSM key.<br>description:<br> The description of the key as viewed in AWS console.<br>alias:<br> The display name of the alias. The name must start with the word alias followed by a forward slash. <br> If not specified, the alias name will be auto-generated.<br>deletion\_window\_in\_days:<br> Duration in days after which the key is deleted after destruction of the resource<br>enable\_key\_rotation:<br> Specifies whether key rotation is enabled. | <pre>object({<br> enabled = optional(bool, true)<br> description = optional(string, "Managed by Terraform")<br> alias = optional(string)<br> deletion_window_in_days = optional(number, 30)<br> enable_key_rotation = optional(bool, true)<br> })</pre> | `{}` | no |
8686
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | ARN or Id of the AWS KMS customer master key (CMK) to be used to encrypt the secret values in the versions stored in this secret. <br>If you don't specify this value, then Secrets Manager defaults to using the AWS account's default CMK (the one named `aws/secretsmanager`). | `string` | `null` | no |
8787
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
8888
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
@@ -93,8 +93,8 @@ module "secrets" {
9393
| <a name="input_policy"></a> [policy](#input\_policy) | Valid JSON document representing a resource policy. | `string` | `null` | no |
9494
| <a name="input_recovery_window_in_days"></a> [recovery\_window\_in\_days](#input\_recovery\_window\_in\_days) | Valid JSON document representing a resource policy. | `number` | `30` | no |
9595
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
96-
| <a name="input_rotation"></a> [rotation](#input\_rotation) | enabled:<br> Whether to create secret rotation rule. <br> Default value: `false`<br>lambda\_arn:<br> Specifies the ARN of the Lambda function that can rotate the secret.<br>automatically\_after\_days:<br> Specifies the number of days between automatic scheduled rotations of the secret. | <pre>object({<br> enabled = optional(bool)<br> lambda_arn = string<br> automatically_after_days = number<br> })</pre> | <pre>{<br> "automatically_after_days": 0,<br> "lambda_arn": ""<br>}</pre> | no |
97-
| <a name="input_secret_version"></a> [secret\_version](#input\_secret\_version) | enabled:<br> Whether to create secret version. <br> Default value: `false`<br>secret\_string:<br> Specifies text data that you want to encrypt and store in this version of the secret. <br> This is required if `secret_binary` is not set.<br>secret\_binary:<br> Specifies binary data that you want to encrypt and store in this version of the secret. <br> This is required if `secret_string` is not set. <br> Needs to be encoded to base64. | <pre>object({<br> enabled = optional(bool)<br> secret_string = optional(string)<br> secret_binary = optional(string)<br> })</pre> | `{}` | no |
96+
| <a name="input_rotation"></a> [rotation](#input\_rotation) | enabled:<br> Whether to create secret rotation rule. <br> Default value: `false`<br>lambda\_arn:<br> Specifies the ARN of the Lambda function that can rotate the secret.<br>automatically\_after\_days:<br> Specifies the number of days between automatic scheduled rotations of the secret. | <pre>object({<br> enabled = optional(bool, false)<br> lambda_arn = string<br> automatically_after_days = number<br> })</pre> | <pre>{<br> "automatically_after_days": 0,<br> "lambda_arn": ""<br>}</pre> | no |
97+
| <a name="input_secret_version"></a> [secret\_version](#input\_secret\_version) | enabled:<br> Whether to create secret version. <br> Default value: `false`<br>secret\_string:<br> Specifies text data that you want to encrypt and store in this version of the secret. <br> This is required if `secret_binary` is not set.<br>secret\_binary:<br> Specifies binary data that you want to encrypt and store in this version of the secret. <br> This is required if `secret_string` is not set. <br> Needs to be encoded to base64. | <pre>object({<br> enabled = optional(bool, true)<br> secret_string = optional(string)<br> secret_binary = optional(string)<br> })</pre> | `{}` | no |
9898
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
9999
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
100100
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |

examples/basic/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module "secrets" {
4545

4646
| Name | Version |
4747
|------|---------|
48-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
48+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
4949
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
5050

5151
## Providers

examples/basic/versions.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
terraform {
2-
required_version = ">= 1.0"
3-
experiments = [module_variable_optional_attrs]
2+
required_version = ">= 1.3"
43

54
required_providers {
65
aws = {

main.tf

+10-31
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,20 @@ locals {
44
secret_id = one(aws_secretsmanager_secret.default[*].id)
55
secret_arn = one(aws_secretsmanager_secret.default[*].arn)
66
version_id = one(aws_secretsmanager_secret_version.default[*].version_id)
7-
secret_version = defaults(var.secret_version, local.secret_version_default)
8-
secret_version_enabled = local.enabled && local.secret_version["enabled"]
9-
secret_string = local.secret_version_enabled && length(local.secret_version["secret_string"]) > 0 ? local.secret_version["secret_string"] : null
10-
secret_binary = local.secret_version_enabled && length(local.secret_version["secret_binary"]) > 0 ? local.secret_version["secret_binary"] : null
11-
secret_rotation = defaults(var.rotation, local.secret_rotation_default)
12-
secret_rotation_enabled = local.enabled && local.secret_rotation["enabled"]
13-
kms_key = defaults(var.kms_key, local.kms_key_default)
14-
kms_key_enabled = local.enabled && local.kms_key["enabled"]
15-
kms_key_id = local.kms_key["enabled"] ? module.kms_key.key_id : var.kms_key_id
16-
17-
kms_key_default = {
18-
deletion_window_in_days = 30
19-
description = "Managed by Terraform"
20-
enable_key_rotation = true
21-
enabled = true
22-
}
23-
secret_version_default = {
24-
secret_string = ""
25-
secret_binary = ""
26-
enabled = false
27-
}
28-
29-
secret_rotation_default = {
30-
enabled = false
31-
}
7+
secret_version_enabled = local.enabled && var.secret_version["enabled"]
8+
secret_rotation_enabled = local.enabled && var.rotation["enabled"]
9+
kms_key_enabled = local.enabled && var.kms_key["enabled"]
10+
kms_key_id = var.kms_key["enabled"] ? module.kms_key.key_id : var.kms_key_id
3211
}
3312

3413
module "kms_key" {
3514
source = "cloudposse/kms-key/aws"
3615
version = "0.12.1"
3716

38-
description = local.kms_key["description"]
39-
deletion_window_in_days = local.kms_key["deletion_window_in_days"]
40-
enable_key_rotation = local.kms_key["enable_key_rotation"]
41-
alias = lookup(local.kms_key, "alias", format("secretsmanager/%s", module.this.id))
17+
description = var.kms_key["description"]
18+
deletion_window_in_days = var.kms_key["deletion_window_in_days"]
19+
enable_key_rotation = var.kms_key["enable_key_rotation"]
20+
alias = lookup(var.kms_key, "alias", format("secretsmanager/%s", module.this.id))
4221

4322
enabled = local.kms_key_enabled
4423
context = module.this.context
@@ -59,8 +38,8 @@ resource "aws_secretsmanager_secret_version" "default" {
5938
count = local.secret_version_enabled ? 1 : 0
6039

6140
secret_id = local.secret_id
62-
secret_string = local.secret_string
63-
secret_binary = local.secret_binary
41+
secret_string = var.secret_version["secret_string"]
42+
secret_binary = var.secret_version["secret_binary"]
6443
}
6544

6645
resource "aws_secretsmanager_secret_rotation" "default" {

variables.tf

+7-12
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ variable "kms_key_id" {
2727

2828
variable "kms_key" {
2929
type = object({
30-
enabled = optional(bool)
31-
description = optional(string)
30+
enabled = optional(bool, true)
31+
description = optional(string, "Managed by Terraform")
3232
alias = optional(string)
33-
deletion_window_in_days = optional(number)
34-
enable_key_rotation = optional(bool)
33+
deletion_window_in_days = optional(number, 30)
34+
enable_key_rotation = optional(bool, true)
3535
})
36-
default = {
37-
deletion_window_in_days = 30
38-
description = "Managed by Terraform"
39-
enable_key_rotation = true
40-
enabled = true
41-
}
36+
default = {}
4237
description = <<-DOC
4338
enabled:
4439
Whether to create KSM key.
@@ -56,7 +51,7 @@ variable "kms_key" {
5651

5752
variable "secret_version" {
5853
type = object({
59-
enabled = optional(bool)
54+
enabled = optional(bool, true)
6055
secret_string = optional(string)
6156
secret_binary = optional(string)
6257
})
@@ -78,7 +73,7 @@ variable "secret_version" {
7873

7974
variable "rotation" {
8075
type = object({
81-
enabled = optional(bool)
76+
enabled = optional(bool, false)
8277
lambda_arn = string
8378
automatically_after_days = number
8479
})

versions.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
terraform {
2-
required_version = ">= 1.0"
3-
experiments = [module_variable_optional_attrs]
2+
required_version = ">= 1.3"
43

54
required_providers {
65
aws = {

0 commit comments

Comments
 (0)