Skip to content

Commit

Permalink
Part Revert "improvement: Remove dependency on external template prov…
Browse files Browse the repository at this point in the history
…ider (terraform-aws-modules#854)"

This part reverts commit b183b97.

:sob:
  • Loading branch information
dpiddock committed May 15, 2020
1 parent 7137806 commit 5c5a817
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 84 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
| local | >= 1.4 |
| null | >= 2.1 |
| random | >= 2.1 |
| template | >= 2.1 |

## Providers

Expand All @@ -150,6 +151,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
| local | >= 1.4 |
| null | >= 2.1 |
| random | >= 2.1 |
| template | >= 2.1 |

## Inputs

Expand Down
162 changes: 82 additions & 80 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,94 +55,96 @@ data "aws_iam_policy_document" "cluster_assume_role_policy" {
}
}

locals {
userdata = [for worker in var.worker_groups : templatefile(
lookup(
worker,
"userdata_template_file",
lookup(worker, "platform", local.workers_group_defaults["platform"]) == "windows"
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"
),
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
]
)

launch_template_userdata = [for worker in var.worker_groups_launch_template : templatefile(
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"],
)
},
lookup(
worker,
"userdata_template_file",
lookup(worker, "platform", local.workers_group_defaults["platform"]) == "windows"
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"
),
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_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"]
)
)
}

data "aws_iam_role" "custom_cluster_iam_role" {
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ output "workers_asg_names" {
output "workers_user_data" {
description = "User data of worker groups"
value = concat(
local.userdata,
local.launch_template_userdata,
data.template_file.userdata.*.rendered,
data.template_file.launch_template_userdata.*.rendered,
)
}

Expand Down
1 change: 1 addition & 0 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ terraform {
aws = ">= 2.52.0"
local = ">= 1.4"
null = ">= 2.1"
template = ">= 2.1"
random = ">= 2.1"
kubernetes = ">= 1.11.1"
}
Expand Down
2 changes: 1 addition & 1 deletion workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ resource "aws_launch_configuration" "workers" {
"key_name",
local.workers_group_defaults["key_name"],
)
user_data_base64 = base64encode(local.userdata[count.index])
user_data_base64 = base64encode(data.template_file.userdata.*.rendered[count.index])
ebs_optimized = lookup(
var.worker_groups[count.index],
"ebs_optimized",
Expand Down
2 changes: 1 addition & 1 deletion workers_launch_template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ resource "aws_launch_template" "workers_launch_template" {
local.workers_group_defaults["key_name"],
)
user_data = base64encode(
local.launch_template_userdata[count.index],
data.template_file.launch_template_userdata.*.rendered[count.index],
)

ebs_optimized = lookup(
Expand Down

0 comments on commit 5c5a817

Please sign in to comment.