count
Last updated
What is count?
The count meta-argument in Terraform allows you to specify the number of instances of a particular resource to create. By setting count to a numeric value, Terraform dynamically generates multiple instances of the resource, indexed from 0 to count-1. This is useful for managing infrastructure that requires multiple identical or similar resources, such as creating multiple virtual machines or storage buckets. Using count, you can conditionally create resources by setting the value based on variables or expressions, making your configurations more flexible and reducing redundancy. Each instance of the resource can be uniquely referenced using the count.index value, enabling more granular control and customization of each resource instance.
Note: You cannot declare count and for_each on the same resource.
Free resources to learn count
- Official docsTerraform Docs - count
- ArticleTerraform by Example - count
- VideoConditional blocks in Terraform using count
More in stage 3: Providers
count: common questions
Can I learn count in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain count in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this count tutorial for beginners?
It is lesson 18 of 110 in the free Terraform roadmap, in stage 3, Providers. If you are new to Terraform, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.