Recall & Review
beginner
What does the
count argument do in Terraform?The
count argument tells Terraform how many copies of a resource to create. It helps you make multiple instances of the same resource easily.Click to reveal answer
beginner
How do you access the index of each instance when using
count?You use
count.index inside the resource block. It starts at 0 and increases by 1 for each instance, letting you customize each one.Click to reveal answer
beginner
Example: How to create 3 AWS EC2 instances using
count?Use
count = 3 inside the resource "aws_instance" block. Terraform will make 3 EC2 instances with one resource definition.Click to reveal answer
beginner
Why is using
count better than copying resource blocks multiple times?Using
count keeps your code shorter and easier to manage. If you want to change something, you only update one place instead of many.Click to reveal answer
intermediate
Can
count be set dynamically based on a variable?Yes! You can set
count = var.instance_count where instance_count is a variable. This lets you control how many instances to create without changing code.Click to reveal answer
What does
count = 5 do in a Terraform resource?✗ Incorrect
count = 5 tells Terraform to make 5 instances of the resource.
How do you refer to the current instance number inside a resource with count?
✗ Incorrect
count.index gives the zero-based index of the current instance.
If you want to create a variable number of instances, what should you use for
count?✗ Incorrect
Using a variable lets you change the number of instances without editing the code.
What happens if you set
count = 0 for a resource?✗ Incorrect
count = 0 means no instances of the resource are created.
Why is
count useful compared to copying resource blocks?✗ Incorrect
count keeps code DRY (Don't Repeat Yourself) and easier to update.
Explain how the
count argument works in Terraform and how you can use count.index.Think about making many copies of the same thing with small differences.
You got /3 concepts.
Describe a scenario where using
count with a variable is helpful in Terraform.Imagine you want to add or remove servers without rewriting code.
You got /3 concepts.