I have applied the code for tagging AWS ec2 instances in Terraform, when the code runs it only created singe TAG.
How can we add multiple TAGs e.g
- It add Auto creation DATE.
- It add Auto OS detection (like it is windows or linux)
Please see TAG detail in Screenshot
Gurus, your kind support will be highly appreciated.
I have added the following code for Tagging.
# Block for create EC2 Instance
resource "aws_instance" "ec2" {
count = var.instance_count
ami = "ami-005835d578c62050d"
instance_type = "t2.micro"
vpc_security_group_ids = [var.security_group_id]
subnet_id = var.subnet_id
key_name = var.key
**tags = {
Name = "${var.name}-${count.index + 1}"**
}
}
2
Answers
You can add other tags by simply adding to your
Tags
, For example:tags
attribute accepts a map of strings and you can also use terraform functions likemerge
to merge default tags if available in your used case with custom resource-specific tags.Something very specific to
terraform-aws-provider
and a very handy feature isdefault_tags
which you can configure on the provider level and these tags will be applied to all resources managed by the provider.Click to view Tutorial from hashicorp on default-tags-in-the-terraform-aws-provider
It’s not possible to get the OS type tag natively as mentioned by @Marcin already in the comments.