Skip to content

Commit

Permalink
Updated dynamic statements to be conditional based on if app account …
Browse files Browse the repository at this point in the history
…numbers are present in list or not
  • Loading branch information
James Maddox committed Oct 28, 2024
1 parent ef25647 commit 3095c53
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
23 changes: 11 additions & 12 deletions kms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ data "aws_iam_policy_document" "ebs_key" {
}

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = [
Expand All @@ -96,7 +96,7 @@ data "aws_iam_policy_document" "ebs_key" {
}
}
dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = [
Expand Down Expand Up @@ -138,7 +138,7 @@ data "aws_iam_policy_document" "s3_key" {
# https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = ["kms:*"]
Expand Down Expand Up @@ -211,7 +211,7 @@ data "aws_iam_policy_document" "s3_key" {
}

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = ["kms:GenerateDataKey*"]
Expand Down Expand Up @@ -254,7 +254,7 @@ data "aws_iam_policy_document" "sns_key" {
}
}
dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = [
Expand Down Expand Up @@ -291,7 +291,7 @@ data "aws_iam_policy_document" "secrets_manager_key" {
# https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = ["kms:*"]
Expand Down Expand Up @@ -364,7 +364,7 @@ data "aws_iam_policy_document" "cloudwatch_key" {
# https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = ["kms:*"]
Expand Down Expand Up @@ -437,7 +437,7 @@ data "aws_iam_policy_document" "cloudwatch_key" {
}

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = ["kms:GenerateDataKey*"]
Expand Down Expand Up @@ -470,7 +470,7 @@ data "aws_iam_policy_document" "config_key" {
# https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = ["kms:*"]
Expand All @@ -483,7 +483,7 @@ data "aws_iam_policy_document" "config_key" {
}

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
effect = "Allow"
actions = ["kms:*"]
Expand All @@ -504,5 +504,4 @@ data "aws_iam_policy_document" "config_key" {
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${var.account_number}:root"]
}
}
}

}
2 changes: 1 addition & 1 deletion s3-accesslog.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ data "aws_iam_policy_document" "s3_accesslogs_bucket_policy" {
resources = ["arn:${data.aws_partition.current.partition}:s3:::${var.resource_prefix}-${var.aws_region}-s3-accesslogs/*"]
}
dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
actions = ["s3:PutObject"]
effect = "Allow"
Expand Down
4 changes: 2 additions & 2 deletions s3-cloudtrail.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ data "aws_iam_policy_document" "log_bucket_policy" {
}

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
#sid = "AgencyAWSCloudTrailWrite"
actions = ["s3:PutObject"]
Expand All @@ -90,7 +90,7 @@ data "aws_iam_policy_document" "log_bucket_policy" {
}

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
#sid = "AgencyAWSCloudTrailAclCheck"
actions = ["s3:GetBucketAcl"]
Expand Down
2 changes: 1 addition & 1 deletion s3-elb-accesslog.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ data "aws_iam_policy_document" "elb_accesslogs_bucket_policy" {
}

dynamic "statement" {
for_each = var.application_account_numbers
for_each = { for idx, account in var.application_account_numbers : idx => account if account != "" }
content {
actions = ["s3:PutObject"]
effect = "Allow"
Expand Down

0 comments on commit 3095c53

Please sign in to comment.