add option to recreate ASG when LT or LC changes (#465)

This commit is contained in:
Thierno IB. BARRY
2019-08-20 15:43:18 +02:00
committed by Max Williams
parent 5636447de6
commit d8ed7d0b66
6 changed files with 92 additions and 13 deletions

View File

@@ -2,11 +2,16 @@
resource "aws_autoscaling_group" "workers_launch_template" {
count = local.worker_group_launch_template_count
name_prefix = "${aws_eks_cluster.this.name}-${lookup(
var.worker_groups_launch_template[count.index],
"name",
count.index,
)}"
name_prefix = join(
"-",
compact(
[
aws_eks_cluster.this.name,
lookup(var.worker_groups_launch_template[count.index], "name", count.index),
lookup(var.worker_groups_launch_template[count.index], "asg_recreate_on_change", local.workers_group_defaults["asg_recreate_on_change"]) ? random_pet.workers_launch_template[count.index].id : ""
]
)
)
desired_capacity = lookup(
var.worker_groups_launch_template[count.index],
"asg_desired_capacity",
@@ -296,6 +301,25 @@ resource "aws_launch_template" "workers_launch_template" {
}
}
resource "random_pet" "workers_launch_template" {
count = local.worker_group_launch_template_count
separator = "-"
length = 2
keepers = {
lt_name = join(
"-",
compact(
[
aws_launch_template.workers_launch_template[count.index].name,
aws_launch_template.workers_launch_template[count.index].latest_version
]
)
)
}
}
resource "aws_iam_instance_profile" "workers_launch_template" {
count = var.manage_worker_iam_resources ? local.worker_group_launch_template_count : 0
name_prefix = aws_eks_cluster.this.name