count meta-argument

The count argument, which creates that many numbered copies of a resource or module, addressed as name[0], name[1] and so on.

In more detail

Use it when the copies are interchangeable, or with 0 or 1 to switch something off or on. Identity is positional: remove an item from the middle of a list and every later instance shifts, which Terraform sees as changes or replacements. Use for_each when each instance has its own name.

Example

resource "null_resource" "machine" {
  count = var.instance_count
  triggers = { name = "machine-${count.index}" }
}

Related terms

Taught in

References

Certification courses