Commit 28d10388 authored by Yuji Kinjo's avatar Yuji Kinjo Committed by GitHub

fix: Multiple provider_urls not working with iam-assumable-role-with-oidc (#115)

parent 96d710ea
...@@ -5,10 +5,6 @@ locals { ...@@ -5,10 +5,6 @@ locals {
for url in compact(distinct(concat(var.provider_urls, [var.provider_url]))) : for url in compact(distinct(concat(var.provider_urls, [var.provider_url]))) :
replace(url, "https://", "") replace(url, "https://", "")
] ]
identifiers = [
for url in local.urls :
"arn:${data.aws_partition.current.partition}:iam::${local.aws_account_id}:oidc-provider/${url}"
]
number_of_role_policy_arns = coalesce(var.number_of_role_policy_arns, length(var.role_policy_arns)) number_of_role_policy_arns = coalesce(var.number_of_role_policy_arns, length(var.role_policy_arns))
} }
...@@ -19,33 +15,38 @@ data "aws_partition" "current" {} ...@@ -19,33 +15,38 @@ data "aws_partition" "current" {}
data "aws_iam_policy_document" "assume_role_with_oidc" { data "aws_iam_policy_document" "assume_role_with_oidc" {
count = var.create_role ? 1 : 0 count = var.create_role ? 1 : 0
statement { dynamic "statement" {
effect = "Allow" for_each = local.urls
actions = ["sts:AssumeRoleWithWebIdentity"] content {
effect = "Allow"
principals { actions = ["sts:AssumeRoleWithWebIdentity"]
type = "Federated"
identifiers = local.identifiers principals {
} type = "Federated"
dynamic "condition" { identifiers = ["arn:${data.aws_partition.current.partition}:iam::${local.aws_account_id}:oidc-provider/${statement.value}"]
for_each = length(var.oidc_fully_qualified_subjects) > 0 ? local.urls : [] }
content {
test = "StringEquals" dynamic "condition" {
variable = "${condition.value}:sub" for_each = length(var.oidc_fully_qualified_subjects) > 0 ? local.urls : []
values = var.oidc_fully_qualified_subjects
content {
test = "StringEquals"
variable = "${statement.value}:sub"
values = var.oidc_fully_qualified_subjects
}
} }
}
dynamic "condition" {
for_each = length(var.oidc_subjects_with_wildcards) > 0 ? local.urls : []
dynamic "condition" { content {
for_each = length(var.oidc_subjects_with_wildcards) > 0 ? local.urls : [] test = "StringLike"
content { variable = "${statement.value}:sub"
test = "StringLike" values = var.oidc_subjects_with_wildcards
variable = "${condition.value}:sub" }
values = var.oidc_subjects_with_wildcards
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment