Challenge - 5 Problems
Count Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Configuration
intermediate2:00remaining
Count Usage for Multiple Instances
Given the Terraform resource below, how many instances will be created?
Terraform
resource "aws_instance" "example" { count = 3 ami = "ami-123456" instance_type = "t2.micro" }
Attempts:
2 left
💡 Hint
The count argument defines how many copies of the resource are created.
✗ Incorrect
The count argument set to 3 means Terraform will create 3 instances of the aws_instance resource.
❓ Architecture
intermediate2:00remaining
Dynamic Count with Variable
If the variable "instance_count" is set to 5, how many instances will this Terraform code create?
Terraform
variable "instance_count" { type = number default = 5 } resource "aws_instance" "example" { count = var.instance_count ami = "ami-123456" instance_type = "t2.micro" }
Attempts:
2 left
💡 Hint
The count uses the variable value directly.
✗ Incorrect
The count is set to the variable instance_count which is 5, so 5 instances will be created.
❓ service_behavior
advanced2:00remaining
Count with Conditional Expression
What is the number of instances created by this Terraform resource if var.create_instances is false?
Terraform
variable "create_instances" { type = bool default = false } resource "aws_instance" "example" { count = var.create_instances ? 4 : 0 ami = "ami-123456" instance_type = "t2.micro" }
Attempts:
2 left
💡 Hint
The count uses a conditional expression based on the boolean variable.
✗ Incorrect
Since var.create_instances is false, the count evaluates to 0, so no instances are created.
❓ security
advanced2:00remaining
Count with Sensitive Variable
If the variable "instance_count" is marked sensitive and set to 2, how many instances will Terraform create?
Terraform
variable "instance_count" { type = number sensitive = true default = 2 } resource "aws_instance" "example" { count = var.instance_count ami = "ami-123456" instance_type = "t2.micro" }
Attempts:
2 left
💡 Hint
Sensitive variables hide values in logs but do not affect resource creation.
✗ Incorrect
Sensitive variables only hide their values in output and logs; they do not affect the count behavior. Terraform creates 2 instances.
✅ Best Practice
expert2:00remaining
Count with Complex Expression
What is the count value and number of instances created by this resource if var.env is "prod"?
Terraform
variable "env" { type = string default = "prod" } resource "aws_instance" "example" { count = var.env == "prod" ? 5 : 2 ami = "ami-123456" instance_type = "t2.micro" }
Attempts:
2 left
💡 Hint
The count uses a conditional expression comparing the environment variable.
✗ Incorrect
Since var.env is "prod", the count expression evaluates to 5, so Terraform creates 5 instances.