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,7 +15,10 @@ data "aws_partition" "current" {} ...@@ -19,7 +15,10 @@ 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" {
for_each = local.urls
content {
effect = "Allow" effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"] actions = ["sts:AssumeRoleWithWebIdentity"]
...@@ -27,28 +26,30 @@ data "aws_iam_policy_document" "assume_role_with_oidc" { ...@@ -27,28 +26,30 @@ data "aws_iam_policy_document" "assume_role_with_oidc" {
principals { principals {
type = "Federated" type = "Federated"
identifiers = local.identifiers identifiers = ["arn:${data.aws_partition.current.partition}:iam::${local.aws_account_id}:oidc-provider/${statement.value}"]
} }
dynamic "condition" { dynamic "condition" {
for_each = length(var.oidc_fully_qualified_subjects) > 0 ? local.urls : [] for_each = length(var.oidc_fully_qualified_subjects) > 0 ? local.urls : []
content { content {
test = "StringEquals" test = "StringEquals"
variable = "${condition.value}:sub" variable = "${statement.value}:sub"
values = var.oidc_fully_qualified_subjects values = var.oidc_fully_qualified_subjects
} }
} }
dynamic "condition" { dynamic "condition" {
for_each = length(var.oidc_subjects_with_wildcards) > 0 ? local.urls : [] for_each = length(var.oidc_subjects_with_wildcards) > 0 ? local.urls : []
content { content {
test = "StringLike" test = "StringLike"
variable = "${condition.value}:sub" variable = "${statement.value}:sub"
values = var.oidc_subjects_with_wildcards values = var.oidc_subjects_with_wildcards
} }
} }
} }
}
} }
resource "aws_iam_role" "this" { resource "aws_iam_role" "this" {
......
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