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`
This commit is contained in:
Scott Stanton
2019-10-29 04:12:47 -07:00
committed by Max Williams
parent c46d5fcb00
commit 4f552891ff
3 changed files with 37 additions and 12 deletions

View File

@@ -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) - **Breaking:** Allow for specifying a custom AMI for the worker nodes. (by @bmcstdio)
- Added support for Windows workers AMIs (by @hodduc) - 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) - Write your awesome addition here (by @you)
### Changed ### Changed

46
data.tf
View File

@@ -105,13 +105,18 @@ EOF
data "template_file" "userdata" { data "template_file" "userdata" {
count = local.worker_group_count count = local.worker_group_count
template = file( template = lookup(
lookup(var.worker_groups[count.index], "platform", local.workers_group_defaults["platform"]) == "windows" ? var.worker_groups[count.index],
"${path.module}/templates/userdata_windows.tpl" : "userdata_template_file",
"${path.module}/templates/userdata.sh.tpl" 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 cluster_name = aws_eks_cluster.this.name
endpoint = aws_eks_cluster.this.endpoint endpoint = aws_eks_cluster.this.endpoint
cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data
@@ -135,18 +140,29 @@ data "template_file" "userdata" {
"kubelet_extra_args", "kubelet_extra_args",
local.workers_group_defaults["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" { data "template_file" "launch_template_userdata" {
count = local.worker_group_launch_template_count count = local.worker_group_launch_template_count
template = file( template = lookup(
lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) == "windows" ? var.worker_groups_launch_template[count.index],
"${path.module}/templates/userdata_windows.tpl" : "userdata_template_file",
"${path.module}/templates/userdata.sh.tpl" 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 cluster_name = aws_eks_cluster.this.name
endpoint = aws_eks_cluster.this.endpoint endpoint = aws_eks_cluster.this.endpoint
cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data cluster_auth_base64 = aws_eks_cluster.this.certificate_authority[0].data
@@ -170,7 +186,13 @@ data "template_file" "launch_template_userdata" {
"kubelet_extra_args", "kubelet_extra_args",
local.workers_group_defaults["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" { data "aws_iam_role" "custom_cluster_iam_role" {

View File

@@ -40,6 +40,8 @@ locals {
root_iops = "0" # The amount of provisioned IOPS. This must be set with a volume_type of "io1". 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 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. 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). 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. additional_userdata = "" # userdata to append to the default userdata.
ebs_optimized = true # sets whether to use ebs optimization on supported types. ebs_optimized = true # sets whether to use ebs optimization on supported types.