Skip to content

Commit 69b77b9

Browse files
Dov Salomonbarryib
Dov Salomon
authored andcommitted
feat: Remove dependency on deprecated hashicorp/template provider (terraform-aws-modules#1297)
BREAKING CHANGES: We remove the dependency on the deprecated `hashicorp/template` provider and use the Terraform built in `templatefile` function. This will broke some workflows due to previously being able to pass in the raw contents of a template file for processing. The `templatefile` function requires a template file that exists before running a plan.
1 parent fd90f9d commit 69b77b9

File tree

14 files changed

+92
-105
lines changed

14 files changed

+92
-105
lines changed

data.tf

-92
Original file line numberDiff line numberDiff line change
@@ -55,98 +55,6 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" {
5555
}
5656
}
5757

58-
data "template_file" "userdata" {
59-
count = var.create_eks ? local.worker_group_count : 0
60-
template = lookup(
61-
var.worker_groups[count.index],
62-
"userdata_template_file",
63-
file(
64-
lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) == "windows"
65-
? "${path.module}/templates/userdata_windows.tpl"
66-
: "${path.module}/templates/userdata.sh.tpl"
67-
)
68-
)
69-
70-
vars = merge({
71-
platform = lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"])
72-
cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0]
73-
endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0]
74-
cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0]
75-
pre_userdata = lookup(
76-
var.worker_groups[count.index],
77-
"pre_userdata",
78-
local.workers_group_defaults["pre_userdata"],
79-
)
80-
additional_userdata = lookup(
81-
var.worker_groups[count.index],
82-
"additional_userdata",
83-
local.workers_group_defaults["additional_userdata"],
84-
)
85-
bootstrap_extra_args = lookup(
86-
var.worker_groups[count.index],
87-
"bootstrap_extra_args",
88-
local.workers_group_defaults["bootstrap_extra_args"],
89-
)
90-
kubelet_extra_args = lookup(
91-
var.worker_groups[count.index],
92-
"kubelet_extra_args",
93-
local.workers_group_defaults["kubelet_extra_args"],
94-
)
95-
},
96-
lookup(
97-
var.worker_groups[count.index],
98-
"userdata_template_extra_args",
99-
local.workers_group_defaults["userdata_template_extra_args"]
100-
)
101-
)
102-
}
103-
104-
data "template_file" "launch_template_userdata" {
105-
count = var.create_eks ? local.worker_group_launch_template_count : 0
106-
template = lookup(
107-
var.worker_groups_launch_template[count.index],
108-
"userdata_template_file",
109-
file(
110-
lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) == "windows"
111-
? "${path.module}/templates/userdata_windows.tpl"
112-
: "${path.module}/templates/userdata.sh.tpl"
113-
)
114-
)
115-
116-
vars = merge({
117-
platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"])
118-
cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0]
119-
endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0]
120-
cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0]
121-
pre_userdata = lookup(
122-
var.worker_groups_launch_template[count.index],
123-
"pre_userdata",
124-
local.workers_group_defaults["pre_userdata"],
125-
)
126-
additional_userdata = lookup(
127-
var.worker_groups_launch_template[count.index],
128-
"additional_userdata",
129-
local.workers_group_defaults["additional_userdata"],
130-
)
131-
bootstrap_extra_args = lookup(
132-
var.worker_groups_launch_template[count.index],
133-
"bootstrap_extra_args",
134-
local.workers_group_defaults["bootstrap_extra_args"],
135-
)
136-
kubelet_extra_args = lookup(
137-
var.worker_groups_launch_template[count.index],
138-
"kubelet_extra_args",
139-
local.workers_group_defaults["kubelet_extra_args"],
140-
)
141-
},
142-
lookup(
143-
var.worker_groups_launch_template[count.index],
144-
"userdata_template_extra_args",
145-
local.workers_group_defaults["userdata_template_extra_args"]
146-
)
147-
)
148-
}
149-
15058
data "aws_iam_role" "custom_cluster_iam_role" {
15159
count = var.manage_cluster_iam_resources ? 0 : 1
15260
name = var.cluster_iam_role_name

examples/basic/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

examples/fargate/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

examples/irsa/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

examples/launch_templates/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

examples/launch_templates_with_managed_node_groups/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

examples/managed_node_groups/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

examples/secrets_encryption/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

examples/spot_instances/versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ terraform {
55
aws = ">= 3.22.0"
66
local = ">= 1.4"
77
null = ">= 2.1"
8-
template = ">= 2.1"
98
random = ">= 2.1"
109
kubernetes = "~> 1.11"
1110
}

local.tf

+88
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,92 @@ locals {
150150
aws_authenticator_additional_args = var.kubeconfig_aws_authenticator_additional_args
151151
aws_authenticator_env_variables = var.kubeconfig_aws_authenticator_env_variables
152152
}) : ""
153+
154+
userdata_rendered = [
155+
for index in range(var.create_eks ? local.worker_group_count : 0) : templatefile(
156+
lookup(
157+
var.worker_groups[index],
158+
"userdata_template_file",
159+
lookup(var.worker_groups[index], "platform", local.workers_group_defaults["platform"]) == "windows"
160+
? "${path.module}/templates/userdata_windows.tpl"
161+
: "${path.module}/templates/userdata.sh.tpl"
162+
),
163+
merge({
164+
platform = lookup(var.worker_groups[index], "platform", local.workers_group_defaults["platform"])
165+
cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0]
166+
endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0]
167+
cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0]
168+
pre_userdata = lookup(
169+
var.worker_groups[index],
170+
"pre_userdata",
171+
local.workers_group_defaults["pre_userdata"],
172+
)
173+
additional_userdata = lookup(
174+
var.worker_groups[index],
175+
"additional_userdata",
176+
local.workers_group_defaults["additional_userdata"],
177+
)
178+
bootstrap_extra_args = lookup(
179+
var.worker_groups[index],
180+
"bootstrap_extra_args",
181+
local.workers_group_defaults["bootstrap_extra_args"],
182+
)
183+
kubelet_extra_args = lookup(
184+
var.worker_groups[index],
185+
"kubelet_extra_args",
186+
local.workers_group_defaults["kubelet_extra_args"],
187+
)
188+
},
189+
lookup(
190+
var.worker_groups[index],
191+
"userdata_template_extra_args",
192+
local.workers_group_defaults["userdata_template_extra_args"]
193+
)
194+
)
195+
)
196+
]
197+
198+
launch_template_userdata_rendered = [
199+
for index in range(var.create_eks ? local.worker_group_launch_template_count : 0) : templatefile(
200+
lookup(
201+
var.worker_groups_launch_template[index],
202+
"userdata_template_file",
203+
lookup(var.worker_groups_launch_template[index], "platform", local.workers_group_defaults["platform"]) == "windows"
204+
? "${path.module}/templates/userdata_windows.tpl"
205+
: "${path.module}/templates/userdata.sh.tpl"
206+
),
207+
merge({
208+
platform = lookup(var.worker_groups_launch_template[index], "platform", local.workers_group_defaults["platform"])
209+
cluster_name = coalescelist(aws_eks_cluster.this[*].name, [""])[0]
210+
endpoint = coalescelist(aws_eks_cluster.this[*].endpoint, [""])[0]
211+
cluster_auth_base64 = coalescelist(aws_eks_cluster.this[*].certificate_authority[0].data, [""])[0]
212+
pre_userdata = lookup(
213+
var.worker_groups_launch_template[index],
214+
"pre_userdata",
215+
local.workers_group_defaults["pre_userdata"],
216+
)
217+
additional_userdata = lookup(
218+
var.worker_groups_launch_template[index],
219+
"additional_userdata",
220+
local.workers_group_defaults["additional_userdata"],
221+
)
222+
bootstrap_extra_args = lookup(
223+
var.worker_groups_launch_template[index],
224+
"bootstrap_extra_args",
225+
local.workers_group_defaults["bootstrap_extra_args"],
226+
)
227+
kubelet_extra_args = lookup(
228+
var.worker_groups_launch_template[index],
229+
"kubelet_extra_args",
230+
local.workers_group_defaults["kubelet_extra_args"],
231+
)
232+
},
233+
lookup(
234+
var.worker_groups_launch_template[index],
235+
"userdata_template_extra_args",
236+
local.workers_group_defaults["userdata_template_extra_args"]
237+
)
238+
)
239+
)
240+
]
153241
}

outputs.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ output "workers_asg_names" {
109109
output "workers_user_data" {
110110
description = "User data of worker groups"
111111
value = concat(
112-
data.template_file.userdata.*.rendered,
113-
data.template_file.launch_template_userdata.*.rendered,
112+
local.userdata_rendered,
113+
local.launch_template_userdata_rendered,
114114
)
115115
}
116116

versions.tf

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ terraform {
44
required_providers {
55
aws = ">= 3.37.0"
66
local = ">= 1.4"
7-
template = ">= 2.1"
87
random = ">= 2.1"
98
kubernetes = ">= 1.11.1"
109
http = {

workers.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ resource "aws_launch_configuration" "workers" {
205205
"key_name",
206206
local.workers_group_defaults["key_name"],
207207
)
208-
user_data_base64 = base64encode(data.template_file.userdata.*.rendered[count.index])
208+
user_data_base64 = base64encode(local.userdata_rendered[count.index])
209209
ebs_optimized = lookup(
210210
var.worker_groups[count.index],
211211
"ebs_optimized",

workers_launch_template.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ resource "aws_launch_template" "workers_launch_template" {
318318
local.workers_group_defaults["key_name"],
319319
)
320320
user_data = base64encode(
321-
data.template_file.launch_template_userdata.*.rendered[count.index],
321+
local.launch_template_userdata_rendered[count.index],
322322
)
323323

324324
ebs_optimized = lookup(

0 commit comments

Comments
 (0)