Hey,
Below is my code,
module "ec2" {
source = "../../ec2"
# commons
instance_ami = "ami-08f3d892de259504d"
instance_type = "t2.nano"
key_name = "test"
public_subnet_id_1_mod = "${element(module.subnets.public_subnet_ids, 0)}"
vpc_security_group_public_id =module.security_groups.security_group_public_id
instance_name = "test"
tag_key_names = ["key1", "key1"]
tag_key_values = ["val1", "val2"]
}
resource "aws_instance" "ec2" {
count = "${length(var.tag_key_names)}"
ami = "${var.instance_ami}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
subnet_id = "${var.public_subnet_id_1_mod}"
vpc_security_group_ids = [ "${var.vpc_security_group_public_id}" ]
tags = {
"${element(var.tag_key_names, count.index)}" = "${element(var.tag_key_names, count.index)}"
}
}
I’m trying to apply multiple tags during the resources creation but the code doesn’t work.
Could you please advise with an example to apply multiple tags to the resources ?
Meanwhile, is there any easier way to capture all the existing ec2 instances and apply them the tags?
Thank you,
Bala