Help de-duplicating tag blocks for AWS Auto Scaling Group

Hi,

I wondered if someone could help me please. I suspect this is down to my limited understanding of data types and conversions. The scenario is: I’m building an AWS Auto Scaling Group and some other AWS resources with Terraform 0.14. As part of my standard approach, I have a tfvars file pertaining to the environment. This file already has in it a tag block which looks like this:

tags = {
  "tag1Name" = "value"
  "tag2Name" = "value"
}

And so on. I pass this to the resource block for, for instance, the AWS Security Group, and it’s fine. However, putting together the requirements for the Auto Scaling Group, I see from the documentation that it needs its tags specified like this:

resource "aws_autoscaling_group" "myasg" {
  tags = concat(
    [  
     {
        "key"                 = "tag1Name"
        "value"               = "value"
        "propagate_at_launch" = true
      },
      {
        "key"                 = "tag2Name"
        "value"               = "value"
        "propagate_at_launch" = true
      },
    ],
  )
}

So I’ve put this in, not quite in that form but storing the tags in the tfvars file in the above structure, and referencing it within the Auto Scaling Group resource block. This means now that my tfvars file has two tag variables with the same content, but structure differently. (I realise the latter version has an extra value, ‘propagate_at_launch’, but since I need that to always be true, it’s the same in terms of value of data.)

I’d like to find a way to use a single tag block to avoid the messy duplication. I saw this example online:

resource "aws_autoscaling_group" "example" {
# ...
dynamic "tag" {
 for_each = local.standard_tags
   content {
     key = tag.key 
     value = tag.value
     propagate_at_launch = true
   }
 }
}

However that didn’t work for me. Terraform reported:

Error: Unsupported block type on main.tf line XX, in resource “xxx” “yyy”: dynamic “tags” - Blocks of type “tags” are not expected here.

Please can anyone help me understand what data structures are at play in this scenario, and if there’s a way to convert between them? Thanks!

I’m not sure if ‘bump’ is a thing on this forum, but I’d still appreciate any help anyone can offer with this question. Thank you.