|
1 | | -data "aws_partition" "current" {} |
2 | | -data "aws_caller_identity" "current" {} |
| 1 | +data "aws_partition" "current" { |
| 2 | + count = local.create ? 1 : 0 |
| 3 | +} |
| 4 | +data "aws_caller_identity" "current" { |
| 5 | + count = local.create ? 1 : 0 |
| 6 | +} |
3 | 7 |
|
4 | 8 | data "aws_iam_session_context" "current" { |
| 9 | + count = local.create ? 1 : 0 |
| 10 | + |
5 | 11 | # This data source provides information on the IAM source role of an STS assumed role |
6 | 12 | # For non-role ARNs, this data source simply passes the ARN through issuer ARN |
7 | 13 | # Ref https://github.com/terraform-aws-modules/terraform-aws-eks/issues/2327#issuecomment-1355581682 |
8 | 14 | # Ref https://github.com/hashicorp/terraform-provider-aws/issues/28381 |
9 | | - arn = data.aws_caller_identity.current.arn |
| 15 | + arn = try(data.aws_caller_identity.current[0].arn, "") |
10 | 16 | } |
11 | 17 |
|
12 | 18 | locals { |
13 | 19 | create = var.create && var.putin_khuylo |
14 | 20 |
|
15 | | - partition = data.aws_partition.current.partition |
| 21 | + partition = try(data.aws_partition.current[0].partition, "") |
16 | 22 |
|
17 | 23 | cluster_role = try(aws_iam_role.this[0].arn, var.iam_role_arn) |
18 | 24 |
|
19 | 25 | create_outposts_local_cluster = length(var.outpost_config) > 0 |
20 | 26 | enable_cluster_encryption_config = length(var.cluster_encryption_config) > 0 && !local.create_outposts_local_cluster |
21 | 27 |
|
22 | | - auto_mode_enabled = try(var.cluster_compute_config.enabled, false) |
23 | | - auto_mode_nodepools_enabled = length(try(var.cluster_compute_config.node_pools, [])) > 0 |
| 28 | + auto_mode_enabled = try(var.cluster_compute_config.enabled, false) |
24 | 29 | } |
25 | 30 |
|
26 | 31 | ################################################################################ |
@@ -218,7 +223,7 @@ locals { |
218 | 223 | # better controlled by users through Terraform |
219 | 224 | bootstrap_cluster_creator_admin_permissions = { |
220 | 225 | cluster_creator = { |
221 | | - principal_arn = data.aws_iam_session_context.current.issuer_arn |
| 226 | + principal_arn = try(data.aws_iam_session_context.current[0].issuer_arn, "") |
222 | 227 | type = "STANDARD" |
223 | 228 |
|
224 | 229 | policy_associations = { |
@@ -307,7 +312,7 @@ module "kms" { |
307 | 312 | # Policy |
308 | 313 | enable_default_policy = var.kms_key_enable_default_policy |
309 | 314 | key_owners = var.kms_key_owners |
310 | | - key_administrators = coalescelist(var.kms_key_administrators, [data.aws_iam_session_context.current.issuer_arn]) |
| 315 | + key_administrators = coalescelist(var.kms_key_administrators, [try(data.aws_iam_session_context.current[0].issuer_arn, "")]) |
311 | 316 | key_users = concat([local.cluster_role], var.kms_key_users) |
312 | 317 | key_service_users = var.kms_key_service_users |
313 | 318 | source_policy_documents = var.kms_key_source_policy_documents |
@@ -689,7 +694,7 @@ resource "aws_eks_identity_provider_config" "this" { |
689 | 694 | ################################################################################ |
690 | 695 |
|
691 | 696 | locals { |
692 | | - create_node_iam_role = local.create && var.create_node_iam_role && local.auto_mode_nodepools_enabled |
| 697 | + create_node_iam_role = local.create && var.create_node_iam_role && local.auto_mode_enabled |
693 | 698 | node_iam_role_name = coalesce(var.node_iam_role_name, "${var.cluster_name}-eks-auto") |
694 | 699 |
|
695 | 700 | create_node_iam_role_custom_policy = local.create_node_iam_role && (var.enable_node_custom_tags_permissions || length(var.node_iam_role_policy_statements) > 0) |
|
0 commit comments