Skip to content

Commit

Permalink
Update flow log ARNs to use partition from aws_partition data source,…
Browse files Browse the repository at this point in the history
… ensuring compatibility with AWS GovCloud and other partitions

tfdocs
  • Loading branch information
pjaudiomv committed Aug 9, 2024
1 parent fb9beb3 commit 1fa19c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ No modules.
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.flow_log_cloudwatch_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.vpc_flow_log_cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

## Inputs
Expand Down
7 changes: 6 additions & 1 deletion vpc-flow-logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ data "aws_caller_identity" "current" {
count = var.create_vpc && var.enable_flow_log ? 1 : 0
}

data "aws_partition" "current" {
# Call this API only if create_vpc and enable_flow_log are true
count = var.create_vpc && var.enable_flow_log ? 1 : 0
}

locals {
# Only create flow log if user selected to create a VPC as well
enable_flow_log = var.create_vpc && var.enable_flow_log
Expand All @@ -20,7 +25,7 @@ locals {
flow_log_cloudwatch_log_group_name_suffix = var.flow_log_cloudwatch_log_group_name_suffix == "" ? local.vpc_id : var.flow_log_cloudwatch_log_group_name_suffix
flow_log_group_arns = [
for log_group in aws_cloudwatch_log_group.flow_log :
"arn:aws:logs:${data.aws_region.current[0].name}:${data.aws_caller_identity.current[0].account_id}:log-group:${log_group.name}:*"
"arn:${data.aws_partition.current[0].partition}:logs:${data.aws_region.current[0].name}:${data.aws_caller_identity.current[0].account_id}:log-group:${log_group.name}:*"
]
}

Expand Down

0 comments on commit 1fa19c4

Please sign in to comment.