From 4f552891ffb6fbed6c17f26ba714e3e99b689a7b Mon Sep 17 00:00:00 2001 From: Scott Stanton Date: Tue, 29 Oct 2019 04:12:47 -0700 Subject: [PATCH] Allow the userdata template to be replaced (#565) * Allow the userdata template to be replaced * Address fmt issue * Rename 'customer_userdata' name to 'userdata_template_file' * Add support for userdata_template_extra_args * Add support for userdata_template_extra_args * fix merge conflicts * Fix merge problem that dropped the file load Add `platform` to the template expansion context Add `userdata_launch_template` to `launch_template_userdata` --- CHANGELOG.md | 1 + data.tf | 46 ++++++++++++++++++++++++++++++++++------------ local.tf | 2 ++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb343ca..3b90864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ project adheres to [Semantic Versioning](http://semver.org/). - **Breaking:** Allow for specifying a custom AMI for the worker nodes. (by @bmcstdio) - Added support for Windows workers AMIs (by @hodduc) +- Allow for replacing the full userdata text with a `userdata_template_file` template and `userdata_template_extra_args` in `worker_groups` (by @snstanton) - Write your awesome addition here (by @you) ### Changed diff --git a/data.tf b/data.tf index 8fee32f..732efa1 100644 --- a/data.tf +++ b/data.tf @@ -105,13 +105,18 @@ EOF data "template_file" "userdata" { count = local.worker_group_count - template = 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" + 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 = { + vars = merge({ + platform = lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) cluster_name = aws_eks_cluster.this.name endpoint = aws_eks_cluster.this.endpoint cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data @@ -135,18 +140,29 @@ data "template_file" "userdata" { "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 = local.worker_group_launch_template_count - template = 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" + 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 = { + vars = merge({ + platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) cluster_name = aws_eks_cluster.this.name endpoint = aws_eks_cluster.this.endpoint cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data @@ -170,7 +186,13 @@ data "template_file" "launch_template_userdata" { "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" { diff --git a/local.tf b/local.tf index 7a4b457..d0c6843 100644 --- a/local.tf +++ b/local.tf @@ -40,6 +40,8 @@ locals { root_iops = "0" # The amount of provisioned IOPS. This must be set with a volume_type of "io1". key_name = "" # The key name that should be used for the instances in the autoscaling group pre_userdata = "" # userdata to pre-append to the default userdata. + userdata_template_file = "" # alternate template to use for userdata + userdata_template_extra_args = {} # Additional arguments to use when expanding the userdata template file bootstrap_extra_args = "" # Extra arguments passed to the bootstrap.sh script from the EKS AMI (Amazon Machine Image). additional_userdata = "" # userdata to append to the default userdata. ebs_optimized = true # sets whether to use ebs optimization on supported types.