patternterraformMinor
Terraform: Is there a concise syntax for specifying multiple tags for a resource?
Viewed 0 times
specifyingresourceconcisesyntaxtagsformultiplethereterraform
Problem
To attach multiple tags to a resource, I currently use multiple
It works, but I wonder if there is a more concise syntax. It is also a bit error prone as you have to specify
Update: The question was written before Terrafrom v0.12 came out. Since then the support has improved with Dynamic Nested Blocks (see my answer below).
tag blocks:resource "aws_autoscaling_group" "instance" {
...
tag {
key = "Name"
value = "${var.cluster_prefix}"
propagate_at_launch = true
}
tag {
key = "Owner"
value = "${var.tag_Owner}"
propagate_at_launch = true
}
tag {
key = "Project"
value = "${var.tag_Project}"
propagate_at_launch = true
}
}It works, but I wonder if there is a more concise syntax. It is also a bit error prone as you have to specify
propagate_at_launch for each tag.Update: The question was written before Terrafrom v0.12 came out. Since then the support has improved with Dynamic Nested Blocks (see my answer below).
Solution
For an
For most other resources you use the
auto-scaling-group this is the most concise syntax available.For most other resources you use the
tags syntax which looks like:tags {
Key1 = "value1"
Key2 = "value2"
}Code Snippets
tags {
Key1 = "value1"
Key2 = "value2"
}Context
StackExchange DevOps Q#2115, answer score: 9
Revisions (0)
No revisions yet.