diff --git a/data.tf b/data.tf index 5909936031..a574e83bc6 100644 --- a/data.tf +++ b/data.tf @@ -55,98 +55,6 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" { } } -data "template_file" "userdata" { - count = var.create_eks ? local.worker_group_count : 0 - template = lookup( - var.worker_groups[count.index], - "userdata_template_file", - file( - lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) == "windows" - ? "${path.module}/templates/userdata_windows.tpl" - : "${path.module}/templates/userdata.sh.tpl" - ) - ) - - vars = merge({ - platform = lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) - cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0] - endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0] - cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0] - pre_userdata = lookup( - var.worker_groups[count.index], - "pre_userdata", - local.workers_group_defaults["pre_userdata"], - ) - additional_userdata = lookup( - var.worker_groups[count.index], - "additional_userdata", - local.workers_group_defaults["additional_userdata"], - ) - bootstrap_extra_args = lookup( - var.worker_groups[count.index], - "bootstrap_extra_args", - local.workers_group_defaults["bootstrap_extra_args"], - ) - kubelet_extra_args = lookup( - var.worker_groups[count.index], - "kubelet_extra_args", - local.workers_group_defaults["kubelet_extra_args"], - ) - }, - lookup( - var.worker_groups[count.index], - "userdata_template_extra_args", - local.workers_group_defaults["userdata_template_extra_args"] - ) - ) -} - -data "template_file" "launch_template_userdata" { - count = var.create_eks ? local.worker_group_launch_template_count : 0 - template = lookup( - var.worker_groups_launch_template[count.index], - "userdata_template_file", - file( - lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) == "windows" - ? "${path.module}/templates/userdata_windows.tpl" - : "${path.module}/templates/userdata.sh.tpl" - ) - ) - - vars = merge({ - platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) - cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0] - endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0] - cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0] - pre_userdata = lookup( - var.worker_groups_launch_template[count.index], - "pre_userdata", - local.workers_group_defaults["pre_userdata"], - ) - additional_userdata = lookup( - var.worker_groups_launch_template[count.index], - "additional_userdata", - local.workers_group_defaults["additional_userdata"], - ) - bootstrap_extra_args = lookup( - var.worker_groups_launch_template[count.index], - "bootstrap_extra_args", - local.workers_group_defaults["bootstrap_extra_args"], - ) - kubelet_extra_args = lookup( - var.worker_groups_launch_template[count.index], - "kubelet_extra_args", - local.workers_group_defaults["kubelet_extra_args"], - ) - }, - lookup( - var.worker_groups_launch_template[count.index], - "userdata_template_extra_args", - local.workers_group_defaults["userdata_template_extra_args"] - ) - ) -} - data "aws_iam_role" "custom_cluster_iam_role" { count = var.manage_cluster_iam_resources ? 0 : 1 name = var.cluster_iam_role_name diff --git a/examples/basic/versions.tf b/examples/basic/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/basic/versions.tf +++ b/examples/basic/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/examples/fargate/versions.tf b/examples/fargate/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/fargate/versions.tf +++ b/examples/fargate/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/examples/irsa/versions.tf b/examples/irsa/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/irsa/versions.tf +++ b/examples/irsa/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/examples/launch_templates/versions.tf b/examples/launch_templates/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/launch_templates/versions.tf +++ b/examples/launch_templates/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/examples/launch_templates_with_managed_node_groups/versions.tf b/examples/launch_templates_with_managed_node_groups/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/launch_templates_with_managed_node_groups/versions.tf +++ b/examples/launch_templates_with_managed_node_groups/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/examples/managed_node_groups/versions.tf b/examples/managed_node_groups/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/managed_node_groups/versions.tf +++ b/examples/managed_node_groups/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/examples/secrets_encryption/versions.tf b/examples/secrets_encryption/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/secrets_encryption/versions.tf +++ b/examples/secrets_encryption/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/examples/spot_instances/versions.tf b/examples/spot_instances/versions.tf index c9f4a4d350..c6f56daafa 100644 --- a/examples/spot_instances/versions.tf +++ b/examples/spot_instances/versions.tf @@ -5,7 +5,6 @@ terraform { aws = ">= 3.22.0" local = ">= 1.4" null = ">= 2.1" - template = ">= 2.1" random = ">= 2.1" kubernetes = "~> 1.11" } diff --git a/local.tf b/local.tf index 924f9d79e0..3367ae0571 100644 --- a/local.tf +++ b/local.tf @@ -150,4 +150,92 @@ locals { aws_authenticator_additional_args = var.kubeconfig_aws_authenticator_additional_args aws_authenticator_env_variables = var.kubeconfig_aws_authenticator_env_variables }) : "" + + userdata_rendered = [ + for index in range(var.create_eks ? local.worker_group_count : 0) : templatefile( + lookup( + var.worker_groups[index], + "userdata_template_file", + lookup(var.worker_groups[index], "platform", local.workers_group_defaults["platform"]) == "windows" + ? "${path.module}/templates/userdata_windows.tpl" + : "${path.module}/templates/userdata.sh.tpl" + ), + merge({ + platform = lookup(var.worker_groups[index], "platform", local.workers_group_defaults["platform"]) + cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0] + endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0] + cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0] + pre_userdata = lookup( + var.worker_groups[index], + "pre_userdata", + local.workers_group_defaults["pre_userdata"], + ) + additional_userdata = lookup( + var.worker_groups[index], + "additional_userdata", + local.workers_group_defaults["additional_userdata"], + ) + bootstrap_extra_args = lookup( + var.worker_groups[index], + "bootstrap_extra_args", + local.workers_group_defaults["bootstrap_extra_args"], + ) + kubelet_extra_args = lookup( + var.worker_groups[index], + "kubelet_extra_args", + local.workers_group_defaults["kubelet_extra_args"], + ) + }, + lookup( + var.worker_groups[index], + "userdata_template_extra_args", + local.workers_group_defaults["userdata_template_extra_args"] + ) + ) + ) + ] + + launch_template_userdata_rendered = [ + for index in range(var.create_eks ? local.worker_group_launch_template_count : 0) : templatefile( + lookup( + var.worker_groups_launch_template[index], + "userdata_template_file", + lookup(var.worker_groups_launch_template[index], "platform", local.workers_group_defaults["platform"]) == "windows" + ? "${path.module}/templates/userdata_windows.tpl" + : "${path.module}/templates/userdata.sh.tpl" + ), + merge({ + platform = lookup(var.worker_groups_launch_template[index], "platform", local.workers_group_defaults["platform"]) + cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0] + endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0] + cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0] + pre_userdata = lookup( + var.worker_groups_launch_template[index], + "pre_userdata", + local.workers_group_defaults["pre_userdata"], + ) + additional_userdata = lookup( + var.worker_groups_launch_template[index], + "additional_userdata", + local.workers_group_defaults["additional_userdata"], + ) + bootstrap_extra_args = lookup( + var.worker_groups_launch_template[index], + "bootstrap_extra_args", + local.workers_group_defaults["bootstrap_extra_args"], + ) + kubelet_extra_args = lookup( + var.worker_groups_launch_template[index], + "kubelet_extra_args", + local.workers_group_defaults["kubelet_extra_args"], + ) + }, + lookup( + var.worker_groups_launch_template[index], + "userdata_template_extra_args", + local.workers_group_defaults["userdata_template_extra_args"] + ) + ) + ) + ] } diff --git a/outputs.tf b/outputs.tf index 147f036014..b751fb59b1 100644 --- a/outputs.tf +++ b/outputs.tf @@ -109,8 +109,8 @@ output "workers_asg_names" { output "workers_user_data" { description = "User data of worker groups" value = concat( - data.template_file.userdata.*.rendered, - data.template_file.launch_template_userdata.*.rendered, + local.userdata_rendered, + local.launch_template_userdata_rendered, ) } diff --git a/versions.tf b/versions.tf index d6801b048e..57695c1282 100644 --- a/versions.tf +++ b/versions.tf @@ -4,7 +4,6 @@ terraform { required_providers { aws = ">= 3.37.0" local = ">= 1.4" - template = ">= 2.1" random = ">= 2.1" kubernetes = ">= 1.11.1" http = { diff --git a/workers.tf b/workers.tf index 2bd75a27ff..0801c88ef2 100644 --- a/workers.tf +++ b/workers.tf @@ -205,7 +205,7 @@ resource "aws_launch_configuration" "workers" { "key_name", local.workers_group_defaults["key_name"], ) - user_data_base64 = base64encode(data.template_file.userdata.*.rendered[count.index]) + user_data_base64 = base64encode(local.userdata_rendered[count.index]) ebs_optimized = lookup( var.worker_groups[count.index], "ebs_optimized", diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 1602437e55..53e1b0928e 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -318,7 +318,7 @@ resource "aws_launch_template" "workers_launch_template" { local.workers_group_defaults["key_name"], ) user_data = base64encode( - data.template_file.launch_template_userdata.*.rendered[count.index], + local.launch_template_userdata_rendered[count.index], ) ebs_optimized = lookup(