Skip to content

Commit 801d242

Browse files
authored
feat: Support non-default AWS partitions (#65)
Adds support for audiences other than sts.amazonaws.com, this determines the DNS suffix from the partition and builds the URL correctly, so that regions such as China can use the module.
1 parent f664e8f commit 801d242

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

data.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ data "aws_iam_policy_document" "assume_role" {
3131
}
3232

3333
condition {
34-
test = "StringEquals"
35-
values = var.additional_audiences != null ? concat(["sts.amazonaws.com"], var.additional_audiences) : ["sts.amazonaws.com"]
34+
test = "StringEquals"
35+
values = var.additional_audiences != null ? concat(
36+
[local.audience],
37+
var.additional_audiences,
38+
) : [local.audience]
3639
variable = "token.actions.githubusercontent.com:aud"
3740
}
3841

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
// limitations under the License.
1414

1515
locals {
16+
audience = format("sts.%v", local.dns_suffix)
1617
github_organizations = toset([
1718
for repo in var.github_repositories : split("/", repo)[0]
1819
])
20+
dns_suffix = data.aws_partition.current.dns_suffix
1921
oidc_provider_arn = var.enabled ? (var.create_oidc_provider ? aws_iam_openid_connect_provider.github[0].arn : data.aws_iam_openid_connect_provider.github[0].arn) : ""
2022
partition = data.aws_partition.current.partition
2123
}
@@ -67,7 +69,7 @@ resource "aws_iam_openid_connect_provider" "github" {
6769

6870
client_id_list = concat(
6971
[for org in local.github_organizations : "https://github.com/${org}"],
70-
["sts.amazonaws.com"]
72+
[local.audience],
7173
)
7274

7375
tags = var.tags

0 commit comments

Comments
 (0)