Skip to content

Commit 98e137f

Browse files
authored
feat: Add back in CloudWatch log group create deny policy to cluster IAM role (terraform-aws-modules#1974)
1 parent 1c7e316 commit 98e137f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

main.tf

+23
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@ resource "aws_iam_role" "this" {
219219
permissions_boundary = var.iam_role_permissions_boundary
220220
force_detach_policies = true
221221

222+
# https://github.com/terraform-aws-modules/terraform-aws-eks/issues/920
223+
# Resources running on the cluster are still generaring logs when destroying the module resources
224+
# which results in the log group being re-created even after Terraform destroys it. Removing the
225+
# ability for the cluster role to create the log group prevents this log group from being re-created
226+
# outside of Terraform due to services still generating logs during destroy process
227+
dynamic "inline_policy" {
228+
for_each = var.create_cloudwatch_log_group ? [1] : []
229+
content {
230+
name = local.iam_role_name
231+
232+
policy = jsonencode({
233+
Version = "2012-10-17"
234+
Statement = [
235+
{
236+
Action = ["logs:CreateLogGroup"]
237+
Effect = "Deny"
238+
Resource = aws_cloudwatch_log_group.this[0].arn
239+
},
240+
]
241+
})
242+
}
243+
}
244+
222245
tags = merge(var.tags, var.iam_role_tags)
223246
}
224247

0 commit comments

Comments
 (0)