DELAPARRA
Index
Color
NL
Category: Terraform

count

Explained by Updated

What is count?

count: Creates N copies of a resource. Each instance is addressed by index — resource[0], resource[1]. count in Terraform creates several copies of a resource from one block. count = 3 creates three servers, addressed as aws_instance.web[0], [1] and [2]. count.index gives each one its number. It is also used as a simple on and off switch: count = var.enable_monitoring ? 1 : 0 creates the resource only when the variable is true.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about count

What should you keep in mind with count?

Be careful with lists. If you use count over a list of names and remove one from the middle, every item after it shifts position. Terraform then destroys and recreates resources that did not really change. For collections with names, use for_each instead, which keys each instance by name. Keep count for identical copies and the on and off pattern.

What does an example of count look like?

resource "aws_instance" "web" { count = 3 instance_type = "t3.micro" }

At a glance

CategoryTerraform
Explained by
Updated

More Terraform terms

All terms starting with C

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.