Skip to content

Commit 2dc2c87

Browse files
committed
add key_spec and upgrade readme
1 parent 28846a0 commit 2dc2c87

File tree

5 files changed

+172
-0
lines changed

5 files changed

+172
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +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_spec"></a> [key\_spec](#input\_key\_spec) | Specifies whether the key contains a symmetric key or an asymmetric key pair and the encryption algorithms or signing algorithms that the key supports. Valid values: SYMMETRIC\_DEFAULT, RSA\_2048, RSA\_3072, RSA\_4096, HMAC\_224, HMAC\_256, HMAC\_384, HMAC\_512, ECC\_NIST\_P256, ECC\_NIST\_P384, ECC\_NIST\_P521, ECC\_SECG\_P256K1, ML\_DSA\_44, ML\_DSA\_65, ML\_DSA\_87, or SM2 (China Regions only). Defaults to SYMMETRIC\_DEFAULT | `string` | `null` | no |
205206
| <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 |
206207
| <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 |
207208
| <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 |

UPGRADE-4.0.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Upgrade from v3.x to v4.x
2+
3+
If you have any questions regarding this upgrade process, please consult the [`examples/`](https://github.com/terraform-aws-modules/terraform-aws-kms/tree/master/examples) projects:
4+
5+
If you find a bug, please open an issue with supporting configuration to reproduce.
6+
7+
## List of backwards incompatible changes
8+
9+
- Support for Terraform `<1.5.7` has been dropped; `1.5.7` is now the minimum supported version
10+
- Terraform AWS provider minimum version is now `v6.0.0` in order to support the `region` argument in resources
11+
- Variable `key_statements.conditions` is now `key_statements.condition`
12+
- Variable `grants.constraints` has changed to type list
13+
14+
## Additional changes
15+
16+
### Added
17+
18+
- `region` to support creating resources in a different region than the provider region
19+
20+
### Modified
21+
22+
- `key_statements.conditions` changed to `key_statements.condition`
23+
- `grants.constrants` changed to type list
24+
25+
### Variable and output changes
26+
27+
1. Removed variables:
28+
29+
- None
30+
31+
2. Renamed variables:
32+
33+
- `key_statements.conditions` -> `key_statements.condition`
34+
35+
3. Added variables:
36+
37+
- `region`
38+
39+
4. Removed outputs:
40+
41+
- None
42+
43+
5. Renamed outputs:
44+
45+
- None
46+
47+
6. Added outputs:
48+
49+
- `key_region` added to support output for setting the `region` variable
50+
51+
## Upgrade Migrations
52+
53+
The following examples demonstrate some of the changes that users can elect to make to avoid any potential disruptions when upgrading.
54+
55+
### Before 3.x Example
56+
57+
```hcl
58+
module "kms" {
59+
source = "terraform-aws-modules/rds/aws"
60+
version = "~> 3.0"
61+
62+
# Only the affected attributes are shown
63+
key_statements = [
64+
{
65+
sid = "CloudWatchLogs"
66+
actions = [
67+
"kms:Encrypt*",
68+
"kms:Decrypt*",
69+
"kms:ReEncrypt*",
70+
"kms:GenerateDataKey*",
71+
"kms:Describe*"
72+
]
73+
resources = ["*"]
74+
75+
principals = [
76+
{
77+
type = "Service"
78+
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"]
79+
}
80+
]
81+
82+
conditions = [
83+
{
84+
test = "ArnLike"
85+
variable = "kms:EncryptionContext:aws:logs:arn"
86+
values = [
87+
"arn:aws:logs:${local.region}:${data.aws_caller_identity.current.account_id}:log-group:*",
88+
]
89+
}
90+
]
91+
}
92+
]
93+
94+
# Grants
95+
grants = {
96+
lambda = {
97+
grantee_principal = aws_iam_role.lambda.arn
98+
operations = ["Encrypt", "Decrypt", "GenerateDataKey"]
99+
constraints = {
100+
encryption_context_equals = {
101+
Department = "Finance"
102+
}
103+
}
104+
}
105+
}
106+
107+
tags = local.tags
108+
}
109+
```
110+
111+
### After 4.x Example
112+
113+
```hcl
114+
module "kms" {
115+
source = "terraform-aws-modules/rds/aws"
116+
version = "~> 4.0"
117+
118+
key_statements = [
119+
{
120+
sid = "CloudWatchLogs"
121+
actions = [
122+
"kms:Encrypt*",
123+
"kms:Decrypt*",
124+
"kms:ReEncrypt*",
125+
"kms:GenerateDataKey*",
126+
"kms:Describe*"
127+
]
128+
resources = ["*"]
129+
130+
principals = [
131+
{
132+
type = "Service"
133+
identifiers = ["logs.${local.region}.amazonaws.com"]
134+
}
135+
]
136+
137+
condition = [
138+
{
139+
test = "ArnLike"
140+
variable = "kms:EncryptionContext:aws:logs:arn"
141+
values = [
142+
"arn:aws:logs:${local.region}:${local.account_id}:log-group:*",
143+
]
144+
}
145+
]
146+
}
147+
]
148+
149+
# Grants
150+
grants = {
151+
lambda = {
152+
grantee_principal = aws_iam_role.lambda.arn
153+
operations = ["Encrypt", "Decrypt", "GenerateDataKey"]
154+
constraints = [{
155+
encryption_context_equals = {
156+
Department = "Finance"
157+
}
158+
}]
159+
}
160+
}
161+
}
162+
```

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ resource "aws_kms_external_key" "this" {
4949
description = var.description
5050
enabled = var.is_enabled
5151
key_material_base64 = var.key_material_base64
52+
key_spec = var.key_spec
53+
key_usage = var.key_usage
5254
multi_region = var.multi_region
5355
policy = coalesce(var.policy, data.aws_iam_policy_document.this[0].json)
5456
valid_to = var.valid_to

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ variable "key_statements" {
184184
default = null
185185
}
186186

187+
variable "key_spec" {
188+
description = "Specifies whether the key contains a symmetric key or an asymmetric key pair and the encryption algorithms or signing algorithms that the key supports. Valid values: SYMMETRIC_DEFAULT, RSA_2048, RSA_3072, RSA_4096, HMAC_224, HMAC_256, HMAC_384, HMAC_512, ECC_NIST_P256, ECC_NIST_P384, ECC_NIST_P521, ECC_SECG_P256K1, ML_DSA_44, ML_DSA_65, ML_DSA_87, or SM2 (China Regions only). Defaults to SYMMETRIC_DEFAULT"
189+
type = string
190+
default = null
191+
}
192+
187193
variable "source_policy_documents" {
188194
description = "List of IAM policy documents that are merged together into the exported document. Statements must have unique `sid`s"
189195
type = list(string)

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module "wrapper" {
2828
key_owners = try(each.value.key_owners, var.defaults.key_owners, [])
2929
key_service_roles_for_autoscaling = try(each.value.key_service_roles_for_autoscaling, var.defaults.key_service_roles_for_autoscaling, [])
3030
key_service_users = try(each.value.key_service_users, var.defaults.key_service_users, [])
31+
key_spec = try(each.value.key_spec, var.defaults.key_spec, null)
3132
key_statements = try(each.value.key_statements, var.defaults.key_statements, null)
3233
key_symmetric_encryption_users = try(each.value.key_symmetric_encryption_users, var.defaults.key_symmetric_encryption_users, [])
3334
key_usage = try(each.value.key_usage, var.defaults.key_usage, null)

0 commit comments

Comments
 (0)