Skip to content

Commit dc8d9cc

Browse files
chrissngspr-mweber3
authored andcommitted
feat: Apply distinct() on role arns to ensure no duplicated roles in aws-auth configmap (terraform-aws-modules#2097)
1 parent 27cdd8a commit dc8d9cc

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

main.tf

+27-15
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,33 @@ resource "aws_eks_identity_provider_config" "this" {
356356
################################################################################
357357

358358
locals {
359-
node_iam_role_arns_non_windows = compact(concat(
360-
[for group in module.eks_managed_node_group : group.iam_role_arn],
361-
[for group in module.self_managed_node_group : group.iam_role_arn if group.platform != "windows"],
362-
var.aws_auth_node_iam_role_arns_non_windows,
363-
))
364-
365-
node_iam_role_arns_windows = compact(concat(
366-
[for group in module.self_managed_node_group : group.iam_role_arn if group.platform == "windows"],
367-
var.aws_auth_node_iam_role_arns_windows,
368-
))
369-
370-
fargate_profile_pod_execution_role_arns = compact(concat(
371-
[for group in module.fargate_profile : group.fargate_profile_pod_execution_role_arn],
372-
var.aws_auth_fargate_profile_pod_execution_role_arns,
373-
))
359+
node_iam_role_arns_non_windows = distinct(
360+
compact(
361+
concat(
362+
[for group in module.eks_managed_node_group : group.iam_role_arn],
363+
[for group in module.self_managed_node_group : group.iam_role_arn if group.platform != "windows"],
364+
var.aws_auth_node_iam_role_arns_non_windows,
365+
)
366+
)
367+
)
368+
369+
node_iam_role_arns_windows = distinct(
370+
compact(
371+
concat(
372+
[for group in module.self_managed_node_group : group.iam_role_arn if group.platform == "windows"],
373+
var.aws_auth_node_iam_role_arns_windows,
374+
)
375+
)
376+
)
377+
378+
fargate_profile_pod_execution_role_arns = distinct(
379+
compact(
380+
concat(
381+
[for group in module.fargate_profile : group.fargate_profile_pod_execution_role_arn],
382+
var.aws_auth_fargate_profile_pod_execution_role_arns,
383+
)
384+
)
385+
)
374386

375387
aws_auth_configmap_data = {
376388
mapRoles = yamlencode(concat(

outputs.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ output "aws_auth_configmap_yaml" {
185185
description = "[DEPRECATED - use `var.manage_aws_auth_configmap`] Formatted yaml output for base aws-auth configmap containing roles used in cluster node groups/fargate profiles"
186186
value = templatefile("${path.module}/templates/aws_auth_cm.tpl",
187187
{
188-
eks_managed_role_arns = compact([for group in module.eks_managed_node_group : group.iam_role_arn])
189-
self_managed_role_arns = compact([for group in module.self_managed_node_group : group.iam_role_arn if group.platform != "windows"])
190-
win32_self_managed_role_arns = compact([for group in module.self_managed_node_group : group.iam_role_arn if group.platform == "windows"])
191-
fargate_profile_pod_execution_role_arns = compact([for group in module.fargate_profile : group.fargate_profile_pod_execution_role_arn])
188+
eks_managed_role_arns = distinct(compact([for group in module.eks_managed_node_group : group.iam_role_arn]))
189+
self_managed_role_arns = distinct(compact([for group in module.self_managed_node_group : group.iam_role_arn if group.platform != "windows"]))
190+
win32_self_managed_role_arns = distinct(compact([for group in module.self_managed_node_group : group.iam_role_arn if group.platform == "windows"]))
191+
fargate_profile_pod_execution_role_arns = distinct(compact([for group in module.fargate_profile : group.fargate_profile_pod_execution_role_arn]))
192192
}
193193
)
194194
}

0 commit comments

Comments
 (0)