Skip to content

Commit

Permalink
[WIP]: use for_each for worker_launch_template
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Lefevre <[email protected]>
  • Loading branch information
ArchiFleKs committed Feb 12, 2020
1 parent a9c73b2 commit 4a3dd25
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 77 deletions.
17 changes: 8 additions & 9 deletions aws_auth.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ data "aws_caller_identity" "current" {
}

data "template_file" "launch_template_worker_role_arns" {
count = var.create_eks ? local.worker_group_launch_template_count : 0
#count = var.create_eks ? local.worker_group_launch_template_count : 0
for_each = var.create_eks ? var.worker_groups_launch_template : {}
template = file("${path.module}/templates/worker-role.tpl")

vars = {
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${element(
coalescelist(
aws_iam_instance_profile.workers_launch_template.*.role,
data.aws_iam_instance_profile.custom_worker_group_launch_template_iam_instance_profile.*.role_name,
),
count.index,
)}"
worker_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${
coalesce(
lookup(aws_iam_instance_profile.workers_launch_template[each.key], "role", ""),
lookup(data.aws_iam_instance_profile.custom_worker_group_launch_template_iam_instance_profile[each.key], "role_name", ""
))}"
platform = lookup(
var.worker_groups_launch_template[count.index],
var.worker_groups_launch_template[each.key],
"platform",
local.workers_group_defaults["platform"]
)
Expand Down
24 changes: 13 additions & 11 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,45 +154,46 @@ data "template_file" "userdata" {
}

data "template_file" "launch_template_userdata" {
count = var.create_eks ? local.worker_group_launch_template_count : 0
#count = var.create_eks ? local.worker_group_launch_template_count : 0
for_each = var.create_eks ? var.worker_groups_launch_template : {}
template = lookup(
var.worker_groups_launch_template[count.index],
var.worker_groups_launch_template[each.key],
"userdata_template_file",
file(
lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"]) == "windows"
lookup(var.worker_groups_launch_template[each.key], "platform", local.workers_group_defaults["platform"]) == "windows"
? "${path.module}/templates/userdata_windows.tpl"
: "${path.module}/templates/userdata.sh.tpl"
)
)

vars = merge({
platform = lookup(var.worker_groups_launch_template[count.index], "platform", local.workers_group_defaults["platform"])
platform = lookup(var.worker_groups_launch_template[each.key], "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],
var.worker_groups_launch_template[each.key],
"pre_userdata",
local.workers_group_defaults["pre_userdata"],
)
additional_userdata = lookup(
var.worker_groups_launch_template[count.index],
var.worker_groups_launch_template[each.key],
"additional_userdata",
local.workers_group_defaults["additional_userdata"],
)
bootstrap_extra_args = lookup(
var.worker_groups_launch_template[count.index],
var.worker_groups_launch_template[each.key],
"bootstrap_extra_args",
local.workers_group_defaults["bootstrap_extra_args"],
)
kubelet_extra_args = lookup(
var.worker_groups_launch_template[count.index],
var.worker_groups_launch_template[each.key],
"kubelet_extra_args",
local.workers_group_defaults["kubelet_extra_args"],
)
},
lookup(
var.worker_groups_launch_template[count.index],
var.worker_groups_launch_template[each.key],
"userdata_template_extra_args",
local.workers_group_defaults["userdata_template_extra_args"]
)
Expand All @@ -214,9 +215,10 @@ data "aws_iam_instance_profile" "custom_worker_group_iam_instance_profile" {
}

data "aws_iam_instance_profile" "custom_worker_group_launch_template_iam_instance_profile" {
count = var.manage_worker_iam_resources ? 0 : local.worker_group_launch_template_count
#count = var.manage_worker_iam_resources ? 0 : local.worker_group_launch_template_count
for_each = var.manage_worker_iam_resources ? {} : var.worker_groups_launch_template
name = lookup(
var.worker_groups_launch_template[count.index],
var.worker_groups_launch_template[each.key],
"iam_instance_profile_name",
local.workers_group_defaults["iam_instance_profile_name"],
)
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ output "workers_user_data" {
description = "User data of worker groups"
value = concat(
data.template_file.userdata.*.rendered,
data.template_file.launch_template_userdata.*.rendered,
values(data.template_file.launch_template_userdata)[*].rendered,
)
}

Expand Down
Loading

0 comments on commit 4a3dd25

Please sign in to comment.