Terraform - how to to Set Conditional Tags Based on Resource Count with Count Parameter
I'm trying to configure I've been struggling with this for a few days now and could really use some help... I'm running into an scenario while trying to dynamically set tags for my AWS EC2 instances based on the count of the instances created using the `count` parameter in Terraform. I want to add a specific tag only if the number of instances is greater than 1. I've set up my configuration as follows: ```hcl variable "instance_count" { default = 2 } resource "aws_instance" "my_instance" { count = var.instance_count ami = "ami-12345678" instance_type = "t2.micro" tags = { Name = "MyInstance-${count.index}" Environment = var.instance_count > 1 ? "Multi-Instance" : "Single-Instance" } } ``` However, I'm working with the following behavior when I run `terraform apply`: ``` behavior: Invalid function argument on main.tf line 9, in resource "aws_instance" "my_instance": 9: Environment = var.instance_count > 1 ? "Multi-Instance" : "Single-Instance" The count.index must be used in the same context as count, but it has been used outside. ``` I've tried several variations, such as using `count` in local values, but nothing seems to be working. It seems like `count.index` is not being evaluated as I expected in the tags. Is there a way to correctly conditionally set tags based on the instance count without running into this behavior? Am I misunderstanding how to utilize `count` in this context? Iām using Terraform version 1.3.5. Any guidance would be greatly appreciated! What's the best practice here? Any ideas how to fix this?