Marek
Marek

Reputation: 63

Terraform 'tags' (plural) are deprecated - how to create multiple 'tag' entries?

So - for ASG's (auto scaling groups) code in Terraform, newest AWS provider deprecates usage of 'tags' (plural) and asks to use a single 'tag' entry. So if you need mulitple tags, you need multiple individual 'tag' entries . With my current code, i get the error that looks like :

│ Warning: Argument is deprecated
│ 
│   with module.service.module.compute.module.controller.aws_autoscaling_group.controller,
│   on .terraform/modules/service/compute/controller/ec2.tf line 74, in resource "aws_autoscaling_group" "controller":
│   74:   tags = [for key, value in merge(local.asg_tags, var.compute_tags) :
│   75:     { key = key, value = value, propagate_at_launch = true }
│   76:   ]
│ 
│ Use tag instead

For some resources i can create several static 'tag' options like

tag {
key = 1
}
tag {
name = 2 
}

But how can i create some form of flat map or something, if my current code is using 'for' loops to create tags ???

│   74:   tags = [for key, value in merge(local.asg_tags, var.compute_tags) :
│   75:     { key = key, value = value, propagate_at_launch = true }
│   76:   ]

I believe its pretty new feature as can't find anything useful what is the best practise to get it sorted. Has anyone came across that ? Thank you

Upvotes: 5

Views: 2932

Answers (2)

Marek
Marek

Reputation: 63

Thank you @Chai for the hint, managed to create dynamic block for tags : enter image description here

Works as expected !

Upvotes: 1

Chai
Chai

Reputation: 2006

I haven't used it, but maybe you can can make use of a dynamic block. Based on what I see in the docs I think it would look something like:

dynamic "tag" {
  for_each = tags  # your array
  content {
    key = each.key
    value = each.value
  }
}

Upvotes: 3

Related Questions