Hello everyone,
I'm provisioning ec2 instances through ASG and would like to customize NAME TAG for each of these and have trouble figuring it out.
I tried using count.index and custom parameters but no luck.
As of now, each ec2 instance gets the same name which is not perfect. I would love to get something like:
CACHE-1
CACHE-2
based on the count of instances that I want to provision through ASG.
Here's how my code looks like so far:
resource "aws_autoscaling_group" "main_asg" {
#count = "${var.asg_number_of_instances}"
instance_count = "{var.asg_number_of_instances}"
depends_on = ["aws_launch_configuration.launch_config"]
name = "${var.asg_name}"
availability_zones = ["${split(",", var.asg_azs)}"]
vpc_zone_identifier = ["${split(",", var.asg_subnets)}"]
launch_configuration = "${aws_launch_configuration.launch_config.id}"
max_size = "${var.asg_number_of_instances}"
min_size = "${var.asg_minimum_number_of_instances}"
load_balancers = ["${var.load_balancers}"]
desired_capacity = "${var.asg_number_of_instances}"
health_check_grace_period = "${var.asg_health_check_grace_period}"
health_check_type = "${var.asg_health_check_type}"
tag {
key = "Name"
value = "${var.name}"
#value = "${var.name}-${count.index}"
#value = "${var.name}-${asg_number_of_instances.index}"
propagate_at_launch = true
}
}
Has anyone had similar issue and solved it somehow?
Any advice really appreciated.
Thank you,
Ernest