Skip to content

Commit 56b8bf6

Browse files
authored
Merge pull request #38 from oscarmendoza123/main-1
KMS policy to accept customer managed KMS keys
2 parents 1066050 + 9978c4b commit 56b8bf6

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ No modules.
112112
| [aws_iam_role_policy_attachment.mwaa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
113113
| [aws_mwaa_environment.mwaa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mwaa_environment) | resource |
114114
| [aws_s3_bucket.mwaa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
115-
| [aws_s3_bucket_acl.mwaa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
116115
| [aws_s3_bucket_public_access_block.mwaa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
117116
| [aws_s3_bucket_server_side_encryption_configuration.mwaa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
118117
| [aws_s3_bucket_versioning.mwaa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource |
@@ -139,7 +138,7 @@ No modules.
139138
| <a name="input_environment_class"></a> [environment\_class](#input\_environment\_class) | (Optional) Environment class for the cluster. Possible options are mw1.small, mw1.medium, mw1.large.<br>Will be set by default to mw1.small. Please check the AWS Pricing for more information about the environment classes. | `string` | `"mw1.small"` | no |
140139
| <a name="input_execution_role_arn"></a> [execution\_role\_arn](#input\_execution\_role\_arn) | (Required) The Amazon Resource Name (ARN) of the task execution role that the Amazon MWAA and its environment can assume<br>Mandatory if `create_iam_role=false` | `string` | `null` | no |
141140
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | IAM role Force detach policies | `bool` | `false` | no |
142-
| <a name="input_iam_role_additional_policies"></a> [iam\_role\_additional\_policies](#input\_iam\_role\_additional\_policies) | A map of additional policy ARNs to be added to the IAM role, with an arbitary key name | `map(string)` | `{}` | no |
141+
| <a name="input_iam_role_additional_policies"></a> [iam\_role\_additional\_policies](#input\_iam\_role\_additional\_policies) | Additional policies to be added to the IAM role | `map(string)` | `{}` | no |
143142
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | IAM Role Name to be created if execution\_role\_arn is null | `string` | `null` | no |
144143
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | IAM role path | `string` | `"/"` | no |
145144
| <a name="input_iam_role_permissions_boundary"></a> [iam\_role\_permissions\_boundary](#input\_iam\_role\_permissions\_boundary) | IAM role Permission boundary | `string` | `null` | no |

data.tf

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,51 @@ data "aws_iam_policy_document" "mwaa" {
108108
]
109109
}
110110

111-
statement {
112-
effect = "Allow"
113-
actions = [
114-
"kms:Decrypt",
115-
"kms:DescribeKey",
116-
"kms:GenerateDataKey*",
117-
"kms:Encrypt"
118-
]
119-
not_resources = [
120-
"arn:${data.aws_partition.current.id}:kms:*:${data.aws_caller_identity.current.account_id}:key/*"
121-
]
122-
condition {
123-
test = "StringLike"
124-
variable = "kms:ViaService"
111+
dynamic "statement" {
112+
for_each = var.kms_key != null ? [] : [1]
113+
content {
114+
effect = "Allow"
115+
actions = [
116+
"kms:Decrypt",
117+
"kms:DescribeKey",
118+
"kms:GenerateDataKey*",
119+
"kms:Encrypt"
120+
]
121+
not_resources = [
122+
"arn:${data.aws_partition.current.id}:kms:*:${data.aws_caller_identity.current.account_id}:key/*"
123+
]
124+
condition {
125+
test = "StringLike"
126+
variable = "kms:ViaService"
127+
128+
values = [
129+
"sqs.${data.aws_region.current.name}.amazonaws.com"
130+
]
131+
}
132+
}
133+
}
125134

126-
values = [
127-
"sqs.${data.aws_region.current.name}.amazonaws.com"
135+
dynamic "statement" {
136+
for_each = var.kms_key != null ? [1] : []
137+
content {
138+
effect = "Allow"
139+
actions = [
140+
"kms:Decrypt",
141+
"kms:DescribeKey",
142+
"kms:GenerateDataKey*",
143+
"kms:Encrypt"
144+
]
145+
resources = [
146+
var.kms_key
128147
]
148+
condition {
149+
test = "StringLike"
150+
variable = "kms:ViaService"
151+
152+
values = [
153+
"sqs.${data.aws_region.current.name}.amazonaws.com"
154+
]
155+
}
129156
}
130157
}
131158

0 commit comments

Comments
 (0)