Skip to content

Commit f02df92

Browse files
Király Ádámbryantbiggs
andauthored
fix: Invoke aws_iam_session_context data source only when required (#3058)
* fix: Call `aws_iam_session_context` data resource only if needed * Typo. * Move index. * Fix condition. --------- Co-authored-by: Bryant Biggs <[email protected]>
1 parent 76d6a64 commit f02df92

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ data "aws_partition" "current" {}
22
data "aws_caller_identity" "current" {}
33

44
data "aws_iam_session_context" "current" {
5+
count = (var.create && var.enable_cluster_creator_admin_permissions) || (var.create && var.create_kms_key && local.enable_cluster_encryption_config) ? 1 : 0
56
# This data source provides information on the IAM source role of an STS assumed role
67
# For non-role ARNs, this data source simply passes the ARN through issuer ARN
78
# Ref https://github.com/terraform-aws-modules/terraform-aws-eks/issues/2327#issuecomment-1355581682
@@ -147,7 +148,7 @@ locals {
147148
# better controlled by users through Terraform
148149
bootstrap_cluster_creator_admin_permissions = {
149150
cluster_creator = {
150-
principal_arn = data.aws_iam_session_context.current.issuer_arn
151+
principal_arn = data.aws_iam_session_context.current[0].issuer_arn
151152
type = "STANDARD"
152153

153154
policy_associations = {
@@ -236,7 +237,7 @@ module "kms" {
236237
# Policy
237238
enable_default_policy = var.kms_key_enable_default_policy
238239
key_owners = var.kms_key_owners
239-
key_administrators = coalescelist(var.kms_key_administrators, [data.aws_iam_session_context.current.issuer_arn])
240+
key_administrators = coalescelist(var.kms_key_administrators, [data.aws_iam_session_context.current[0].issuer_arn])
240241
key_users = concat([local.cluster_role], var.kms_key_users)
241242
key_service_users = var.kms_key_service_users
242243
source_policy_documents = var.kms_key_source_policy_documents

0 commit comments

Comments
 (0)