Skip to content

Commit f8495d1

Browse files
Replace hardcoded partition with data resource to support aws-cn and aws-gov (#71)
1 parent d8f9d62 commit f8495d1

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ No modules.
194194
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
195195
| [aws_iam_policy_document.dlq](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
196196
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
197+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
197198
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
198199

199200
## Inputs

examples/complete/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Note that this example may create resources which cost money. Run `terraform des
5555
|------|------|
5656
| [aws_kms_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
5757
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
58+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
5859

5960
## Inputs
6061

examples/complete/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ provider "aws" {
44

55
data "aws_caller_identity" "current" {}
66

7+
data "aws_partition" "current" {}
8+
79
locals {
810
name = "ex-${basename(path.cwd)}"
911
region = "eu-west-1"
@@ -125,7 +127,7 @@ module "sqs_with_dlq" {
125127
principals = [
126128
{
127129
type = "AWS"
128-
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
130+
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:root"]
129131
}
130132
]
131133
}
@@ -152,7 +154,7 @@ module "sqs_with_dlq" {
152154
principals = [
153155
{
154156
type = "AWS"
155-
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
157+
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:root"]
156158
}
157159
]
158160
}

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ data "aws_region" "current" {}
22

33
data "aws_caller_identity" "current" {}
44

5+
data "aws_partition" "current" {}
6+
57
################################################################################
68
# Queue
79
################################################################################

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ output "queue_arn" {
1414

1515
output "queue_arn_static" {
1616
description = "The ARN of the SQS queue. Use this to avoid cycle errors between resources (e.g., Step Functions)"
17-
value = var.create && !var.use_name_prefix ? "arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.name}" : ""
17+
value = var.create && !var.use_name_prefix ? "arn:${data.aws_partition.current.partition}:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.name}" : ""
1818
}
1919

2020
output "queue_url" {
@@ -43,7 +43,7 @@ output "dead_letter_queue_arn" {
4343

4444
output "dead_letter_queue_arn_static" {
4545
description = "The ARN of the SQS queue. Use this to avoid cycle errors between resources (e.g., Step Functions)"
46-
value = var.create && var.create_dlq && !var.use_name_prefix ? "arn:aws:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.dlq_name}" : ""
46+
value = var.create && var.create_dlq && !var.use_name_prefix ? "arn:${data.aws_partition.current.partition}:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.dlq_name}" : ""
4747
}
4848

4949
output "dead_letter_queue_url" {

0 commit comments

Comments
 (0)