Tag issue in autoscaling resource after upgared to 0.12.8

ag issue in autoscaling resource after upgared to 0.12.8.

I am trying to conact list in autoscaling resource, getting the below error.

**Error: Incorrect attribute value type

on modules\asg\autoscaling.tf line 93, in resource “aws_autoscaling_group” “autoscaling”:
93: tags = [

Inappropriate value for attribute “tags”: element 0: map of string required.**

Terraform resource block
TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
force an interpolation expression to be interpreted as a list by wrapping it
in an extra set of list brackets. That form was supported for compatibility in
v0.11, but is no longer supported in Terraform v0.12.
If the expression in the following list itself returns a list, remove the
brackets to avoid interpretation as a list of lists. If the expression
returns a single list item then leave it as-is and remove this TODO comment.
tags = [
concat(
[
{
“key” = “Name”
“value” = var.launch_config_name
“propagate_at_launch” = true
},
{
“key” = “Purpose”
“value” = var.asg_purpose
“propagate_at_launch” = true
},
{
“key” = “Application”
“value” = var.asg_appname
“propagate_at_launch” = true
},
],
var.asg_tags,
),
]

Hi @yeshwanth18sa!

As the TF-UPGRADE-TODO comment indicates, the upgrade tool sometimes doesn’t have enough information to determine automatically whether you intended to create a flat list or a list of lists, and so it conservatively kept your list-of-lists configuration and asked for you to review it yourself.

The tags argument on aws_autoscaling_group requires a flat list of maps, but your tags expression here is producing a list of lists because the [ ] brackets around the whole expression create one level of list but the concat function also returns a list.

To get this working, it looks like you could just remove the surrounding [ ] brackets like the error message suggested:

tags = concat(
  [
    {
      "key" = "Name"
      "value" = var.launch_config_name
      "propagate_at_launch" = true
    },
    {
      "key" = "Purpose"
      "value" = var.asg_purpose
      "propagate_at_launch" = true
    },
    {
      "key" = "Application"
      "value" = var.asg_appname
      "propagate_at_launch" = true
    },
  ],
  var.asg_tags,
)

The error message you saw is also confirming this as the appropriate solution: tags is expecting a list of maps of strings, but you gave it a list of lists of maps of strings. Therefore element zero of the first list is a list rather than a map, and so validation failed.

This worked in Terraform 0.11 due to a backward-compatibility feature supporting a Terraform 0.9-and-earlier behavior that would automatically flatten lists, but that behavior was finally removed in Terraform 0.12 so you now need to explicitly construct a single-level list rather than relying on Terraform to automatically fix the incorrect expression.

I hope that helps!

Hi Martin,

Thanks for your help. It worked.

I tried multiple try and error methods. In one of such i removed those brackets buth problem was I had the concat in next line like below.

tags =
concat(
[
{
“key” = “Name”
“value” = var.launch_config_name
“propagate_at_launch” = true
},
{
“key” = “Purpose”
“value” = var.asg_purpose
“propagate_at_launch” = true
},
{
“key” = “Application”
“value” = var.asg_appname
“propagate_at_launch” = true
},
],
var.asg_tags,
)

However, It’s woking fine now.

Thank you