Hello,
I’m working on a blog post highlighting the differences between count and for each.
I created three users using the following code:
variable "user_names_count" {
default = [ "user1", "user2", "user3"]
}
I renamed user2
to user4
:
resource "aws_iam_user" "example_count" {
count = length(var.user_names_count)
name = var.user_names_count[count.index]
}
And I got the following output:
# aws_iam_user.example_count[1] will be updated in-place
~ resource "aws_iam_user" "example_count" {
arn = "arn:aws:iam::247111851647:user/user2"
force_destroy = false
id = "user2"
~ name = "user2" -> "user4"
path = "/"
tags = {}
unique_id = "AIDATTCIDTZ73DUTRE7PM"
}
Plan: 0 to add, 1 to change, 0 to destroy.
I understand this is due to the count index. What I don’t understand is:
Which are adequate use cases for using count? I couldn’t find anything about this in the official documentation.
Regards,