Skip to content

Commit 210736c

Browse files
feat!: Upgrade AWS provider and min required Terraform version to 6.0 and 1.5.7 respectively (#36)
* feat: addition of enhanced region support * run of pre-commit hooks * feat: addition of enhanced region support * feat: Raise MSV of Terraform * fix: Remove region examples * fix: Re-align example * feat: Add variable definitions to replace `any` * chore: Updates from testing --------- Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
1 parent c20bffd commit 210736c

File tree

12 files changed

+147
-88
lines changed

12 files changed

+147
-88
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.96.1
3+
rev: v1.99.4
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
146146

147147
| Name | Version |
148148
|------|---------|
149-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
150-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.49 |
149+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
150+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
151151

152152
## Providers
153153

154154
| Name | Version |
155155
|------|---------|
156-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.49 |
156+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
157157

158158
## Modules
159159

@@ -180,7 +180,7 @@ No modules.
180180
| <a name="input_aliases"></a> [aliases](#input\_aliases) | A list of aliases to create. Note - due to the use of `toset()`, values must be static strings and not computed values | `list(string)` | `[]` | no |
181181
| <a name="input_aliases_use_name_prefix"></a> [aliases\_use\_name\_prefix](#input\_aliases\_use\_name\_prefix) | Determines whether the alias name is used as a prefix | `bool` | `false` | no |
182182
| <a name="input_bypass_policy_lockout_safety_check"></a> [bypass\_policy\_lockout\_safety\_check](#input\_bypass\_policy\_lockout\_safety\_check) | A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable | `bool` | `null` | no |
183-
| <a name="input_computed_aliases"></a> [computed\_aliases](#input\_computed\_aliases) | A map of aliases to create. Values provided via the `name` key of the map can be computed from upstream resources | `any` | `{}` | no |
183+
| <a name="input_computed_aliases"></a> [computed\_aliases](#input\_computed\_aliases) | A map of aliases to create. Values provided via the `name` key of the map can be computed from upstream resources | <pre>map(object({<br/> name = string<br/> }))</pre> | `{}` | no |
184184
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
185185
| <a name="input_create_external"></a> [create\_external](#input\_create\_external) | Determines whether an external CMK (externally provided material) will be created or a standard CMK (AWS provided material) | `bool` | `false` | no |
186186
| <a name="input_create_replica"></a> [create\_replica](#input\_create\_replica) | Determines whether a replica standard CMK will be created (AWS provided material) | `bool` | `false` | no |
@@ -192,7 +192,7 @@ No modules.
192192
| <a name="input_enable_default_policy"></a> [enable\_default\_policy](#input\_enable\_default\_policy) | Specifies whether to enable the default key policy. Defaults to `true` | `bool` | `true` | no |
193193
| <a name="input_enable_key_rotation"></a> [enable\_key\_rotation](#input\_enable\_key\_rotation) | Specifies whether key rotation is enabled. Defaults to `true` | `bool` | `true` | no |
194194
| <a name="input_enable_route53_dnssec"></a> [enable\_route53\_dnssec](#input\_enable\_route53\_dnssec) | Determines whether the KMS policy used for Route53 DNSSEC signing is enabled | `bool` | `false` | no |
195-
| <a name="input_grants"></a> [grants](#input\_grants) | A map of grant definitions to create | `any` | `{}` | no |
195+
| <a name="input_grants"></a> [grants](#input\_grants) | A map of grant definitions to create | <pre>map(object({<br/> constraints = optional(list(object({<br/> encryption_context_equals = optional(map(string))<br/> encryption_context_subset = optional(map(string))<br/> })))<br/> grant_creation_tokens = optional(list(string))<br/> grantee_principal = string<br/> name = optional(string) # Will fall back to use map key<br/> operations = list(string)<br/> retire_on_delete = optional(bool)<br/> retiring_principal = optional(string)<br/> }))</pre> | `null` | no |
196196
| <a name="input_is_enabled"></a> [is\_enabled](#input\_is\_enabled) | Specifies whether the key is enabled. Defaults to `true` | `bool` | `null` | no |
197197
| <a name="input_key_administrators"></a> [key\_administrators](#input\_key\_administrators) | A list of IAM ARNs for [key administrators](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-default-allow-administrators) | `list(string)` | `[]` | no |
198198
| <a name="input_key_asymmetric_public_encryption_users"></a> [key\_asymmetric\_public\_encryption\_users](#input\_key\_asymmetric\_public\_encryption\_users) | A list of IAM ARNs for [key asymmetric public encryption users](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-users-crypto) | `list(string)` | `[]` | no |
@@ -202,7 +202,7 @@ No modules.
202202
| <a name="input_key_owners"></a> [key\_owners](#input\_key\_owners) | A list of IAM ARNs for those who will have full key permissions (`kms:*`) | `list(string)` | `[]` | no |
203203
| <a name="input_key_service_roles_for_autoscaling"></a> [key\_service\_roles\_for\_autoscaling](#input\_key\_service\_roles\_for\_autoscaling) | A list of IAM ARNs for [AWSServiceRoleForAutoScaling roles](https://docs.aws.amazon.com/autoscaling/ec2/userguide/key-policy-requirements-EBS-encryption.html#policy-example-cmk-access) | `list(string)` | `[]` | no |
204204
| <a name="input_key_service_users"></a> [key\_service\_users](#input\_key\_service\_users) | A list of IAM ARNs for [key service users](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-service-integration) | `list(string)` | `[]` | no |
205-
| <a name="input_key_statements"></a> [key\_statements](#input\_key\_statements) | A map of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) for custom permission usage | `any` | `{}` | no |
205+
| <a name="input_key_statements"></a> [key\_statements](#input\_key\_statements) | A map of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) for custom permission usage | <pre>list(object({<br/> sid = optional(string)<br/> actions = optional(list(string))<br/> not_actions = optional(list(string))<br/> effect = optional(string)<br/> resources = optional(list(string))<br/> not_resources = optional(list(string))<br/> principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> not_principals = optional(list(object({<br/> type = string<br/> identifiers = list(string)<br/> })))<br/> condition = optional(list(object({<br/> test = string<br/> values = list(string)<br/> variable = string<br/> })))<br/> }))</pre> | `null` | no |
206206
| <a name="input_key_symmetric_encryption_users"></a> [key\_symmetric\_encryption\_users](#input\_key\_symmetric\_encryption\_users) | A list of IAM ARNs for [key symmetric encryption users](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-users-crypto) | `list(string)` | `[]` | no |
207207
| <a name="input_key_usage"></a> [key\_usage](#input\_key\_usage) | Specifies the intended use of the key. Valid values: `ENCRYPT_DECRYPT` or `SIGN_VERIFY`. Defaults to `ENCRYPT_DECRYPT` | `string` | `null` | no |
208208
| <a name="input_key_users"></a> [key\_users](#input\_key\_users) | A list of IAM ARNs for [key users](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-default-allow-users) | `list(string)` | `[]` | no |
@@ -211,8 +211,9 @@ No modules.
211211
| <a name="input_policy"></a> [policy](#input\_policy) | A valid policy JSON document. Although this is a key policy, not an IAM policy, an `aws_iam_policy_document`, in the form that designates a principal, can be used | `string` | `null` | no |
212212
| <a name="input_primary_external_key_arn"></a> [primary\_external\_key\_arn](#input\_primary\_external\_key\_arn) | The primary external key arn of a multi-region replica external key | `string` | `null` | no |
213213
| <a name="input_primary_key_arn"></a> [primary\_key\_arn](#input\_primary\_key\_arn) | The primary key arn of a multi-region replica key | `string` | `null` | no |
214+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | `string` | `null` | no |
214215
| <a name="input_rotation_period_in_days"></a> [rotation\_period\_in\_days](#input\_rotation\_period\_in\_days) | Custom period of time between each rotation date. Must be a number between 90 and 2560 (inclusive) | `number` | `null` | no |
215-
| <a name="input_route53_dnssec_sources"></a> [route53\_dnssec\_sources](#input\_route53\_dnssec\_sources) | A list of maps containing `account_ids` and Route53 `hosted_zone_arn` that will be allowed to sign DNSSEC records | `list(any)` | `[]` | no |
216+
| <a name="input_route53_dnssec_sources"></a> [route53\_dnssec\_sources](#input\_route53\_dnssec\_sources) | A list of maps containing `account_ids` and Route53 `hosted_zone_arn` that will be allowed to sign DNSSEC records | <pre>list(object({<br/> account_ids = optional(list(string))<br/> hosted_zone_arn = optional(string)<br/> }))</pre> | `null` | no |
216217
| <a name="input_source_policy_documents"></a> [source\_policy\_documents](#input\_source\_policy\_documents) | List of IAM policy documents that are merged together into the exported document. Statements must have unique `sid`s | `list(string)` | `[]` | no |
217218
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
218219
| <a name="input_valid_to"></a> [valid\_to](#input\_valid\_to) | Time at which the imported key material expires. When the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. If not specified, key material does not expire | `string` | `null` | no |
@@ -229,6 +230,7 @@ No modules.
229230
| <a name="output_key_arn"></a> [key\_arn](#output\_key\_arn) | The Amazon Resource Name (ARN) of the key |
230231
| <a name="output_key_id"></a> [key\_id](#output\_key\_id) | The globally unique identifier for the key |
231232
| <a name="output_key_policy"></a> [key\_policy](#output\_key\_policy) | The IAM resource policy set on the key |
233+
| <a name="output_key_region"></a> [key\_region](#output\_key\_region) | The region for the key |
232234
<!-- END_TF_DOCS -->
233235

234236
## License

examples/complete/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ Note that this example may create resources which will incur monetary charges on
2424

2525
| Name | Version |
2626
|------|---------|
27-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
28-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.49 |
27+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
28+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
2929

3030
## Providers
3131

3232
| Name | Version |
3333
|------|---------|
34-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.49 |
34+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
3535

3636
## Modules
3737

@@ -53,7 +53,6 @@ Note that this example may create resources which will incur monetary charges on
5353
|------|------|
5454
| [aws_iam_role.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
5555
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
56-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
5756

5857
## Inputs
5958

examples/complete/main.tf

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@ provider "aws" {
22
region = local.region
33
}
44

5+
data "aws_caller_identity" "current" {}
6+
57
locals {
68
region = "us-east-1"
7-
name = "kms-ex-${replace(basename(path.cwd), "_", "-")}"
9+
region_secondary = "eu-west-1"
10+
name = "kms-ex-${basename(path.cwd)}"
11+
12+
account_id = data.aws_caller_identity.current.account_id
813
current_identity = data.aws_caller_identity.current.arn
914

15+
# Removes noise from hh:mm:ss in the timestamp
16+
valid_to = replace(timeadd(plantimestamp(), "4380h"), "/T.*/", "T00:00:00Z") # 6 months
17+
1018
tags = {
1119
Name = local.name
1220
Example = "complete"
1321
Repository = "https://github.com/terraform-aws-modules/terraform-aws-kms"
1422
}
1523
}
1624

17-
data "aws_caller_identity" "current" {}
18-
data "aws_region" "current" {}
19-
2025
################################################################################
2126
# KMS Module
2227
################################################################################
@@ -37,7 +42,7 @@ module "kms_complete" {
3742
key_administrators = [local.current_identity]
3843
key_users = [local.current_identity]
3944
key_service_users = [local.current_identity]
40-
key_service_roles_for_autoscaling = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"]
45+
key_service_roles_for_autoscaling = ["arn:aws:iam::${local.account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"]
4146
key_symmetric_encryption_users = [local.current_identity]
4247
key_hmac_users = [local.current_identity]
4348
key_asymmetric_public_encryption_users = [local.current_identity]
@@ -57,16 +62,16 @@ module "kms_complete" {
5762
principals = [
5863
{
5964
type = "Service"
60-
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"]
65+
identifiers = ["logs.${local.region}.amazonaws.com"]
6166
}
6267
]
6368

64-
conditions = [
69+
condition = [
6570
{
6671
test = "ArnLike"
6772
variable = "kms:EncryptionContext:aws:logs:arn"
6873
values = [
69-
"arn:aws:logs:${local.region}:${data.aws_caller_identity.current.account_id}:log-group:*",
74+
"arn:aws:logs:${local.region}:${local.account_id}:log-group:*",
7075
]
7176
}
7277
]
@@ -92,11 +97,11 @@ module "kms_complete" {
9297
lambda = {
9398
grantee_principal = aws_iam_role.lambda.arn
9499
operations = ["Encrypt", "Decrypt", "GenerateDataKey"]
95-
constraints = {
100+
constraints = [{
96101
encryption_context_equals = {
97102
Department = "Finance"
98103
}
99-
}
104+
}]
100105
}
101106
}
102107

@@ -112,7 +117,7 @@ module "kms_external" {
112117
is_enabled = true
113118
key_material_base64 = "Wblj06fduthWggmsT0cLVoIMOkeLbc2kVfMud77i/JY="
114119
multi_region = false
115-
valid_to = "2023-11-21T23:20:50Z"
120+
valid_to = local.valid_to
116121

117122
tags = local.tags
118123
}
@@ -129,8 +134,8 @@ module "kms_dnssec_signing" {
129134
enable_key_rotation = false
130135
route53_dnssec_sources = [
131136
{
132-
accounts_ids = [data.aws_caller_identity.current.account_id] # can ommit if using current account ID which is default
133-
hosted_zone_arn = "arn:aws:route53:::hostedzone/*" # can ommit, this is default value
137+
accounts_ids = [local.account_id] # can ommit if using current account ID which is default
138+
hosted_zone_arn = "arn:aws:route53:::hostedzone/*" # can ommit, this is default value
134139
}
135140
]
136141

@@ -170,14 +175,11 @@ module "kms_primary" {
170175
tags = local.tags
171176
}
172177

173-
provider "aws" {
174-
region = "eu-west-1"
175-
alias = "replica"
176-
}
177-
178178
module "kms_replica" {
179179
source = "../.."
180180

181+
region = local.region_secondary
182+
181183
deletion_window_in_days = 7
182184
description = "Replica key example showing various configurations available"
183185
create_replica = true
@@ -206,19 +208,15 @@ module "kms_replica" {
206208
lambda = {
207209
grantee_principal = aws_iam_role.lambda.arn
208210
operations = ["Encrypt", "Decrypt", "GenerateDataKey"]
209-
constraints = {
211+
constraints = [{
210212
encryption_context_equals = {
211213
Department = "Finance"
212214
}
213-
}
215+
}]
214216
}
215217
}
216218

217219
tags = local.tags
218-
219-
providers = {
220-
aws = aws.replica
221-
}
222220
}
223221

224222
################################################################################
@@ -234,7 +232,7 @@ module "kms_primary_external" {
234232
create_external = true
235233
key_material_base64 = "Wblj06fduthWggmsT0cLVoIMOkeLbc2kVfMud77i/JY="
236234
multi_region = true
237-
valid_to = "2023-11-21T23:20:50Z"
235+
valid_to = local.valid_to
238236

239237
aliases = ["primary-external"]
240238

@@ -244,14 +242,16 @@ module "kms_primary_external" {
244242
module "kms_replica_external" {
245243
source = "../.."
246244

245+
region = local.region_secondary
246+
247247
deletion_window_in_days = 7
248248
description = "Replica external key example showing various configurations available"
249249
create_replica_external = true
250250
is_enabled = true
251251
# key material must be the same as the primary's
252252
key_material_base64 = "Wblj06fduthWggmsT0cLVoIMOkeLbc2kVfMud77i/JY="
253253
primary_external_key_arn = module.kms_primary_external.key_arn
254-
valid_to = "2023-11-21T23:20:50Z"
254+
valid_to = local.valid_to
255255

256256
aliases = ["replica-external"]
257257

@@ -260,19 +260,15 @@ module "kms_replica_external" {
260260
lambda = {
261261
grantee_principal = aws_iam_role.lambda.arn
262262
operations = ["Encrypt", "Decrypt", "GenerateDataKey"]
263-
constraints = {
263+
constraints = [{
264264
encryption_context_equals = {
265265
Department = "Finance"
266266
}
267-
}
267+
}]
268268
}
269269
}
270270

271271
tags = local.tags
272-
273-
providers = {
274-
aws = aws.replica
275-
}
276272
}
277273

278274
################################################################################

examples/complete/outputs.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ output "complete_aliases" {
4040
output "complete_grants" {
4141
description = "A map of grants created and their attributes"
4242
value = module.kms_complete.grants
43+
sensitive = true
4344
}
4445

4546
################################################################################
@@ -84,6 +85,7 @@ output "external_aliases" {
8485
output "external_grants" {
8586
description = "A map of grants created and their attributes"
8687
value = module.kms_external.grants
88+
sensitive = true
8789
}
8890

8991
################################################################################
@@ -128,9 +130,9 @@ output "default_aliases" {
128130
output "default_grants" {
129131
description = "A map of grants created and their attributes"
130132
value = module.kms_default.grants
133+
sensitive = true
131134
}
132135

133-
134136
################################################################################
135137
# Replica
136138
################################################################################
@@ -173,9 +175,9 @@ output "replica_aliases" {
173175
output "replica_grants" {
174176
description = "A map of grants created and their attributes"
175177
value = module.kms_replica.grants
178+
sensitive = true
176179
}
177180

178-
179181
################################################################################
180182
# Replica External
181183
################################################################################
@@ -218,4 +220,5 @@ output "replica_external_aliases" {
218220
output "replica_external_grants" {
219221
description = "A map of grants created and their attributes"
220222
value = module.kms_replica_external.grants
223+
sensitive = true
221224
}

examples/complete/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.3"
2+
required_version = ">= 1.5.7"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.49"
7+
version = ">= 6.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)