Skip to content

Commit 28d1038

Browse files
authored
fix: Multiple provider_urls not working with iam-assumable-role-with-oidc (#115)
1 parent 96d710e commit 28d1038

File tree

1 file changed

+25
-24
lines changed
  • modules/iam-assumable-role-with-oidc

1 file changed

+25
-24
lines changed

modules/iam-assumable-role-with-oidc/main.tf

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ locals {
55
for url in compact(distinct(concat(var.provider_urls, [var.provider_url]))) :
66
replace(url, "https://", "")
77
]
8-
identifiers = [
9-
for url in local.urls :
10-
"arn:${data.aws_partition.current.partition}:iam::${local.aws_account_id}:oidc-provider/${url}"
11-
]
128
number_of_role_policy_arns = coalesce(var.number_of_role_policy_arns, length(var.role_policy_arns))
139
}
1410

@@ -19,33 +15,38 @@ data "aws_partition" "current" {}
1915
data "aws_iam_policy_document" "assume_role_with_oidc" {
2016
count = var.create_role ? 1 : 0
2117

22-
statement {
23-
effect = "Allow"
18+
dynamic "statement" {
19+
for_each = local.urls
2420

25-
actions = ["sts:AssumeRoleWithWebIdentity"]
21+
content {
22+
effect = "Allow"
2623

27-
principals {
28-
type = "Federated"
24+
actions = ["sts:AssumeRoleWithWebIdentity"]
2925

30-
identifiers = local.identifiers
31-
}
26+
principals {
27+
type = "Federated"
3228

33-
dynamic "condition" {
34-
for_each = length(var.oidc_fully_qualified_subjects) > 0 ? local.urls : []
35-
content {
36-
test = "StringEquals"
37-
variable = "${condition.value}:sub"
38-
values = var.oidc_fully_qualified_subjects
29+
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${local.aws_account_id}:oidc-provider/${statement.value}"]
30+
}
31+
32+
dynamic "condition" {
33+
for_each = length(var.oidc_fully_qualified_subjects) > 0 ? local.urls : []
34+
35+
content {
36+
test = "StringEquals"
37+
variable = "${statement.value}:sub"
38+
values = var.oidc_fully_qualified_subjects
39+
}
3940
}
40-
}
4141

42+
dynamic "condition" {
43+
for_each = length(var.oidc_subjects_with_wildcards) > 0 ? local.urls : []
4244

43-
dynamic "condition" {
44-
for_each = length(var.oidc_subjects_with_wildcards) > 0 ? local.urls : []
45-
content {
46-
test = "StringLike"
47-
variable = "${condition.value}:sub"
48-
values = var.oidc_subjects_with_wildcards
45+
content {
46+
test = "StringLike"
47+
variable = "${statement.value}:sub"
48+
values = var.oidc_subjects_with_wildcards
49+
}
4950
}
5051
}
5152
}

0 commit comments

Comments
 (0)