thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

DevOps & Automation · Intermediate

count and for_each

Terraform meta-arguments that create multiple instances of a resource or module from a number or a map/set.

Definition

count indexes instances by number (aws_instance.web[0]); for_each keys them by map key or set value (aws_instance.web["a"]), which avoids unwanted recreation when items are removed from the middle of a list.

Example

for_each = toset(["dev","prod"]) creates one bucket per environment.

Exam tip

Prefer for_each when instances are distinct; removing a middle item from count shifts indexes and recreates resources.

Related terms