Is it possible to add iterative numbering to servers being spun up?

I’m new at all things Hashicorp. Please forgive if this is a dumb question. I’m attempting to deploy a set of Vault/Consul servers using this example script. There’s a declaration to name the cluster in the module:

name_prefix = var.cluster_name

Which I define in the variables file. When I deploy this, I end up with X number of servers with the same name (at least looking at the AWS tags, I didn’t look at the hostnames on the boxes). Can this be tweaked to allow sequential naming, like consul-server-1, consul-server-2, etc.

The name_prefix you are seeing is within the aws_autoscaling_group resource, so that is to do with setting the name of the Auto Scaling Group (ASG). When an instance is created withing an ASG it inherits certain tags from the ASG (those with tag propagation switched on).

I don’t think AWS has the facility to change tags - they are just straight copies - so I don’t think what you ask is possible.

Note that Terraform is just a way of calling the AWS APIs, so if something isn’t possible in AWS it isn’t possible to add that functionality in Terraform.

1 Like