Search code examples
amazon-web-servicesterraformtagging

Why ASG Tagging in Terraform uses list of maps instead of a single map?


#1. AWS Resource Tagging Using Terraform (single map)

resource "aws_vpc" "example" {
  # ... other configuration ...

  tags = {
    Name = "MyVPC"
  }
}

#2. ASG Tagging (list of maps)

resource "aws_autoscaling_group" "asg_ec2" {
    ..........
    ..........

    lifecycle {
    create_before_destroy = true
    }

  tag {
    key                 = "Name"
    value               = "awesome-app-server"
    propagate_at_launch = true
  }

  tag {
    key                 = "Role"
    value               = "server"
    propagate_at_launch = true
  }

  dynamic "tag" {
    for_each = var.tags

    content {
      key    =  tag.key
      value   =  tag.value
      propagate_at_launch =  true
    }
  }

}

Question:

Normally all resources are tagged using a map as shown in #1 above

But all blogs and documentation always suggest tagging for ASG using a "list of maps" and not just a map as shown in #2 above.

Would like to understand why this deviation only for ASG?


Solution

  • TF docs states that tags is depricated:

    tags (Optional, Deprecated use tag instead) Set of maps containing resource tags. Conflicts with tag. See Tags below for more details.

    So you shoudn't be using tags as it is going to be removed in future.