-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: Remove dependency on external template provider (#854)
* Remove template_file for generating kubeconfig Push logic from terraform down to the template. Makes the formatting slightly easier to follow * Remove template_file for generating userdata Updates to the eks_cluster now do not trigger recreation of launch configurations * Remove template_file for LT userdata * Remove template dependency
- Loading branch information
1 parent
25ebaab
commit b183b97
Showing
8 changed files
with
109 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,138 +66,104 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" { | |
} | ||
} | ||
|
||
data "template_file" "kubeconfig" { | ||
count = var.create_eks ? 1 : 0 | ||
template = file("${path.module}/templates/kubeconfig.tpl") | ||
|
||
vars = { | ||
kubeconfig_name = local.kubeconfig_name | ||
endpoint = aws_eks_cluster.this[0].endpoint | ||
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data | ||
aws_authenticator_command = var.kubeconfig_aws_authenticator_command | ||
aws_authenticator_command_args = length(var.kubeconfig_aws_authenticator_command_args) > 0 ? " - ${join( | ||
"\n - ", | ||
var.kubeconfig_aws_authenticator_command_args, | ||
)}" : " - ${join( | ||
"\n - ", | ||
formatlist("\"%s\"", ["token", "-i", aws_eks_cluster.this[0].name]), | ||
)}" | ||
aws_authenticator_additional_args = length(var.kubeconfig_aws_authenticator_additional_args) > 0 ? " - ${join( | ||
"\n - ", | ||
var.kubeconfig_aws_authenticator_additional_args, | ||
)}" : "" | ||
aws_authenticator_env_variables = length(var.kubeconfig_aws_authenticator_env_variables) > 0 ? " env:\n${join( | ||
"\n", | ||
data.template_file.aws_authenticator_env_variables.*.rendered, | ||
)}" : "" | ||
} | ||
} | ||
|
||
data "template_file" "aws_authenticator_env_variables" { | ||
count = length(var.kubeconfig_aws_authenticator_env_variables) | ||
|
||
template = <<EOF | ||
- name: $${key} | ||
value: $${value} | ||
EOF | ||
|
||
|
||
vars = { | ||
value = values(var.kubeconfig_aws_authenticator_env_variables)[count.index] | ||
key = keys(var.kubeconfig_aws_authenticator_env_variables)[count.index] | ||
} | ||
} | ||
|
||
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" | ||
locals { | ||
kubeconfig = var.create_eks ? templatefile("${path.module}/templates/kubeconfig.tpl", { | ||
kubeconfig_name = local.kubeconfig_name | ||
endpoint = aws_eks_cluster.this[0].endpoint | ||
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data | ||
aws_authenticator_command = var.kubeconfig_aws_authenticator_command | ||
aws_authenticator_command_args = length(var.kubeconfig_aws_authenticator_command_args) > 0 ? var.kubeconfig_aws_authenticator_command_args : ["token", "-i", aws_eks_cluster.this[0].name] | ||
aws_authenticator_additional_args = var.kubeconfig_aws_authenticator_additional_args | ||
aws_authenticator_env_variables = var.kubeconfig_aws_authenticator_env_variables | ||
}) : "" | ||
|
||
userdata = [for worker in var.worker_groups : templatefile( | ||
lookup( | ||
worker, | ||
"userdata_template_file", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mbarrien
Contributor
|
||
lookup(worker, "platform", local.workers_group_defaults["platform"]) == "windows" | ||
? "${path.module}/templates/userdata_windows.tpl" | ||
: "${path.module}/templates/userdata.sh.tpl" | ||
), | ||
merge( | ||
{ | ||
platform = lookup(worker, "platform", local.workers_group_defaults["platform"]) | ||
cluster_name = aws_eks_cluster.this[0].name | ||
endpoint = aws_eks_cluster.this[0].endpoint | ||
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data | ||
pre_userdata = lookup( | ||
worker, | ||
"pre_userdata", | ||
local.workers_group_defaults["pre_userdata"], | ||
) | ||
additional_userdata = lookup( | ||
worker, | ||
"additional_userdata", | ||
local.workers_group_defaults["additional_userdata"], | ||
) | ||
bootstrap_extra_args = lookup( | ||
worker, | ||
"bootstrap_extra_args", | ||
local.workers_group_defaults["bootstrap_extra_args"], | ||
) | ||
kubelet_extra_args = lookup( | ||
worker, | ||
"kubelet_extra_args", | ||
local.workers_group_defaults["kubelet_extra_args"], | ||
) | ||
}, | ||
lookup( | ||
worker, | ||
"userdata_template_extra_args", | ||
local.workers_group_defaults["userdata_template_extra_args"] | ||
) | ||
) | ||
) | ||
) if var.create_eks | ||
] | ||
|
||
vars = merge({ | ||
platform = lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) | ||
cluster_name = aws_eks_cluster.this[0].name | ||
endpoint = aws_eks_cluster.this[0].endpoint | ||
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data | ||
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"], | ||
) | ||
}, | ||
launch_template_userdata = [for worker in var.worker_groups_launch_template : templatefile( | ||
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" | ||
worker, | ||
"userdata_template_file", | ||
lookup(worker, "platform", local.workers_group_defaults["platform"]) == "windows" | ||
? "${path.module}/templates/userdata_windows.tpl" | ||
: "${path.module}/templates/userdata.sh.tpl" | ||
), | ||
merge( | ||
{ | ||
platform = lookup(worker, "platform", local.workers_group_defaults["platform"]) | ||
cluster_name = aws_eks_cluster.this[0].name | ||
endpoint = aws_eks_cluster.this[0].endpoint | ||
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data | ||
pre_userdata = lookup( | ||
worker, | ||
"pre_userdata", | ||
local.workers_group_defaults["pre_userdata"], | ||
) | ||
additional_userdata = lookup( | ||
worker, | ||
"additional_userdata", | ||
local.workers_group_defaults["additional_userdata"], | ||
) | ||
bootstrap_extra_args = lookup( | ||
worker, | ||
"bootstrap_extra_args", | ||
local.workers_group_defaults["bootstrap_extra_args"], | ||
) | ||
kubelet_extra_args = lookup( | ||
worker, | ||
"kubelet_extra_args", | ||
local.workers_group_defaults["kubelet_extra_args"], | ||
) | ||
}, | ||
lookup( | ||
worker, | ||
"userdata_template_extra_args", | ||
local.workers_group_defaults["userdata_template_extra_args"] | ||
) | ||
) | ||
) | ||
|
||
vars = merge({ | ||
platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) | ||
cluster_name = aws_eks_cluster.this[0].name | ||
endpoint = aws_eks_cluster.this[0].endpoint | ||
cluster_auth_base64 = aws_eks_cluster.this[0].certificate_authority[0].data | ||
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"] | ||
) | ||
) | ||
) if var.create_eks | ||
] | ||
} | ||
|
||
data "aws_iam_role" "custom_cluster_iam_role" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
resource "local_file" "kubeconfig" { | ||
count = var.write_kubeconfig && var.create_eks ? 1 : 0 | ||
content = data.template_file.kubeconfig[0].rendered | ||
content = local.kubeconfig | ||
filename = substr(var.config_output_path, -1, 1) == "/" ? "${var.config_output_path}kubeconfig_${var.cluster_name}" : var.config_output_path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This broke userdata_template_file. Prior to this PR userdata_template_file was the contents of the file, not the filename. Heavily broke our usage of this.