Skip to content

Commit d6c8501

Browse files
fix: Replace hardcoded "aws" parition with data lookup (#47)
Co-authored-by: Anton Babenko <[email protected]>
1 parent e6469b8 commit d6c8501

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ No modules.
144144
| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
145145
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
146146
| [aws_iam_policy_document.service_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
147+
| [aws_partition.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
147148

148149
## Inputs
149150

iam.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
data "aws_partition" "this" {}
2+
13
locals {
24
service_roles_with_policies = var.create_graphql_api ? { for k, v in var.datasources : k => v if contains(["AWS_LAMBDA", "AMAZON_DYNAMODB", "AMAZON_ELASTICSEARCH"], v.type) && tobool(lookup(v, "create_service_role", true)) } : {}
35

@@ -19,7 +21,7 @@ locals {
1921
dynamodb = {
2022
effect = "Allow"
2123
actions = lookup(v, "policy_actions", null) == null ? var.dynamodb_allowed_actions : v.policy_actions
22-
resources = [for _, f in ["arn:aws:dynamodb:%v:%v:table/%v", "arn:aws:dynamodb:%v:%v:table/%v/*"] : format(f, v.region, lookup(v, "aws_account_id", data.aws_caller_identity.this.account_id), v.table_name)]
24+
resources = [for _, f in ["arn:${data.aws_partition.this.partition}:dynamodb:%v:%v:table/%v", "arn:${data.aws_partition.this.partition}:dynamodb:%v:%v:table/%v/*"] : format(f, v.region, lookup(v, "aws_account_id", data.aws_caller_identity.this.account_id), v.table_name)]
2325
}
2426
}
2527
}
@@ -31,7 +33,7 @@ locals {
3133
elasticsearch = {
3234
effect = "Allow"
3335
actions = lookup(v, "policy_actions", null) == null ? var.elasticsearch_allowed_actions : v.policy_actions
34-
resources = [format("arn:aws:es:%v::domain/%v/*", v.region, v.endpoint)]
36+
resources = [format("arn:${data.aws_partition.this.partition}:es:%v::domain/%v/*", v.region, v.endpoint)]
3537
}
3638
}
3739
}
@@ -72,7 +74,7 @@ resource "aws_iam_role" "logs" {
7274
resource "aws_iam_role_policy_attachment" "logs" {
7375
count = var.logging_enabled && var.create_logs_role ? 1 : 0
7476

75-
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs"
77+
policy_arn = "arn:${data.aws_partition.this.partition}:iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs"
7678
role = aws_iam_role.logs[0].name
7779
}
7880

0 commit comments

Comments
 (0)