Skip to content

Commit 4d7f453

Browse files
committed
Restore local.region
Given var.region can be null, add another try() to check for a provided value before falling back to current region.
1 parent 23494e6 commit 4d7f453

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

modules/service/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ module "ecs_service" {
222222
| [aws_iam_policy_document.tasks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
223223
| [aws_iam_policy_document.tasks_assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
224224
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
225+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
225226
| [aws_subnet.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | data source |
226227

227228
## Inputs

modules/service/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
data "aws_region" "current" {
2+
count = var.create ? 1 : 0
3+
}
14
data "aws_partition" "current" {
25
count = var.create ? 1 : 0
36
}
@@ -8,6 +11,7 @@ data "aws_caller_identity" "current" {
811
locals {
912
account_id = try(data.aws_caller_identity.current[0].account_id, "")
1013
partition = try(data.aws_partition.current[0].partition, "")
14+
region = try(var.region, try(data.aws_region.current[0].region, ""))
1115
}
1216

1317
################################################################################
@@ -1180,7 +1184,7 @@ data "aws_iam_policy_document" "tasks_assume" {
11801184
condition {
11811185
test = "ArnLike"
11821186
variable = "aws:SourceArn"
1183-
values = ["arn:${local.partition}:ecs:${var.region}:${local.account_id}:*"]
1187+
values = ["arn:${local.partition}:ecs:${local.region}:${local.account_id}:*"]
11841188
}
11851189

11861190
condition {

0 commit comments

Comments
 (0)