From 2200df91303a6d5dd3ea791c884c87cae8ec2cba Mon Sep 17 00:00:00 2001 From: Daniel Piddock Date: Fri, 14 Aug 2020 13:21:04 +0200 Subject: [PATCH] aws bug: use dynamic tag instead of tags in ASG ``` Error: Provider produced inconsistent final plan When expanding the plan for module.eks.aws_autoscaling_group.workers[0] to include new values learned so far during apply, provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags: length changed from 4 to 6. ``` https://github.com/terraform-providers/terraform-provider-aws/issues/14085 --- workers.tf | 55 +++++++++++++++++++++----------------- workers_launch_template.tf | 54 +++++++++++++++++++++---------------- 2 files changed, 62 insertions(+), 47 deletions(-) diff --git a/workers.tf b/workers.tf index 6c9d924f0e..a5b6672951 100644 --- a/workers.tf +++ b/workers.tf @@ -102,31 +102,38 @@ resource "aws_autoscaling_group" "workers" { } } - tags = concat( - [ - { - "key" = "Name" - "value" = "${aws_eks_cluster.this[0].name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg" - "propagate_at_launch" = true - }, - { - "key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}" - "value" = "owned" - "propagate_at_launch" = true - }, - { - "key" = "k8s.io/cluster/${aws_eks_cluster.this[0].name}" - "value" = "owned" - "propagate_at_launch" = true - }, - ], - local.asg_tags, - lookup( - var.worker_groups[count.index], - "tags", - local.workers_group_defaults["tags"] + dynamic "tag" { + for_each = concat( + [ + { + "key" = "Name" + "value" = "${aws_eks_cluster.this[0].name}-${lookup(var.worker_groups[count.index], "name", count.index)}-eks_asg" + "propagate_at_launch" = true + }, + { + "key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}" + "value" = "owned" + "propagate_at_launch" = true + }, + { + "key" = "k8s.io/cluster/${aws_eks_cluster.this[0].name}" + "value" = "owned" + "propagate_at_launch" = true + }, + ], + local.asg_tags, + lookup( + var.worker_groups[count.index], + "tags", + local.workers_group_defaults["tags"] + ) ) - ) + content { + key = tag.value.key + value = tag.value.value + propagate_at_launch = tag.value.propagate_at_launch + } + } lifecycle { create_before_destroy = true diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 5c328c5d3e..600666a11d 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -151,6 +151,7 @@ resource "aws_autoscaling_group" "workers_launch_template" { } } } + dynamic launch_template { iterator = item for_each = (lookup(var.worker_groups_launch_template[count.index], "override_instance_types", null) != null) || (lookup(var.worker_groups_launch_template[count.index], "on_demand_allocation_strategy", local.workers_group_defaults["on_demand_allocation_strategy"]) != null) ? [] : list(var.worker_groups_launch_template[count.index]) @@ -178,30 +179,37 @@ resource "aws_autoscaling_group" "workers_launch_template" { } } - tags = concat( - [ - { - "key" = "Name" - "value" = "${aws_eks_cluster.this[0].name}-${lookup( - var.worker_groups_launch_template[count.index], - "name", - count.index, - )}-eks_asg" - "propagate_at_launch" = true - }, - { - "key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}" - "value" = "owned" - "propagate_at_launch" = true - }, - ], - local.asg_tags, - lookup( - var.worker_groups_launch_template[count.index], - "tags", - local.workers_group_defaults["tags"] + dynamic "tag" { + for_each = concat( + [ + { + "key" = "Name" + "value" = "${aws_eks_cluster.this[0].name}-${lookup( + var.worker_groups_launch_template[count.index], + "name", + count.index, + )}-eks_asg" + "propagate_at_launch" = true + }, + { + "key" = "kubernetes.io/cluster/${aws_eks_cluster.this[0].name}" + "value" = "owned" + "propagate_at_launch" = true + }, + ], + local.asg_tags, + lookup( + var.worker_groups_launch_template[count.index], + "tags", + local.workers_group_defaults["tags"] + ) ) - ) + content { + key = tag.value.key + value = tag.value.value + propagate_at_launch = tag.value.propagate_at_launch + } + } lifecycle { create_before_destroy = true