Skip to content

Commit

Permalink
aws bug: use dynamic tag instead of tags in ASG
Browse files Browse the repository at this point in the history
```
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.
```

hashicorp/terraform-provider-aws#14085
  • Loading branch information
dpiddock committed Aug 14, 2020
1 parent 0854249 commit 2200df9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 47 deletions.
55 changes: 31 additions & 24 deletions workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 31 additions & 23 deletions workers_launch_template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2200df9

Please sign in to comment.