Perhaps that is fine for your case, if those numbers are just there to create some uniqueness and it doesn't matter if they get reassigned over time as CIDR blocks are added, removed and reordered in the input variable. In your specific situation, if you used the index in the tag Name then changing the order of the list would cause Terraform to plan to swap the tagging on those two VPCs: # aws_vpc.vpc will be updated in-place With that all said, the reason why the index isn't directly available when using for_each is that this would defeat the main purpose of using for_each: it would make the order significant again. In your specific case, that would produce the same result regardless of whether var.vpc_cidrs is or, because the instances would be tracked by the CIDR block string and the index in the list is totally ignored. This resource will generally be referenced by OS::Nova::Server userdata, or OS::Heat::MultipartMime parts. Any intrinsic functions called in the config will be resolved before storing the result. This resource allows cloud-config YAML to be defined and stored by the config API. The most common reason to choose for_each rather than count is to ensure that the order of whatever collection of values is driving the repetition is not significant. A configuration resource for representing cloud-init cloud-config. When using for_each, each of the multiple instances is tracked by a string which could be obtained either from a key in a map or from an element in a set, giving addresses like aws_vpc.vpc and aws_vpc.vpc.When using count, each of the multiple instances is tracked by a number starting at 0, giving addresses like aws_vpc.vpc and aws_vpc.vpc.The main difference between these is how Terraform will track the multiple instances they create: ![]() Terraform offers two resource repetition mechanisms: count and for_each.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |