Challenge - 5 Problems
Terraform Check Blocks Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding Terraform check blocks with assertions
Which of the following Terraform check blocks correctly asserts that an AWS S3 bucket has versioning enabled?
Terraform
check {
assertions = [
{
assert = aws_s3_bucket.example.versioning[0].enabled == true
error_message = "S3 bucket versioning must be enabled"
}
]
}Attempts:
2 left
💡 Hint
Remember that versioning is a list with an 'enabled' boolean attribute inside the first element.
✗ Incorrect
Terraform AWS S3 bucket versioning is represented as a list of objects. The 'enabled' attribute is a boolean inside the first element. Option B correctly accesses it and asserts it is true.
❓ Configuration
intermediate2:00remaining
Detecting open security groups with check blocks
Which check block correctly asserts that no AWS security group allows ingress from 0.0.0.0/0 on port 22?
Attempts:
2 left
💡 Hint
Use nonetrue to ensure no ingress rule matches both conditions simultaneously.
✗ Incorrect
Option C correctly asserts that there is no ingress rule with cidr_blocks containing 0.0.0.0/0 AND from_port equal to 22. This ensures port 22 is not open to the world.
❓ Architecture
advanced2:00remaining
Check block to enforce multi-AZ deployment in AWS RDS
Given an AWS RDS instance resource, which check block correctly asserts that multi-AZ deployment is enabled?
Attempts:
2 left
💡 Hint
The multi_az attribute is a boolean, not a string or number.
✗ Incorrect
Option D correctly asserts that multi_az is true (boolean). Option D compares to string "true" which is incorrect. Option D compares to number 1 which is invalid. Option D is less strict but valid; however, only A explicitly checks for true.
❓ security
advanced2:00remaining
Check block to ensure encryption is enabled on AWS EBS volumes
Which check block correctly asserts that all AWS EBS volumes have encryption enabled?
Attempts:
2 left
💡 Hint
Use alltrue to ensure every volume is encrypted.
✗ Incorrect
Option A asserts all volumes have encrypted == true. Option A only requires any volume encrypted which is insufficient. Option A is logically equivalent to D but less explicit. Option A also works logically but option A is the clearest and most direct assertion.
❓ service_behavior
expert2:00remaining
Check block behavior when resource attribute is missing
What error or behavior occurs when a Terraform check block asserts on a resource attribute that does not exist, for example, aws_instance.example.nonexistent_attribute == true?
Terraform
check {
assertions = [
{
assert = aws_instance.example.nonexistent_attribute == true
error_message = "Attribute must be true"
}
]
}Attempts:
2 left
💡 Hint
Terraform validates references during plan phase and errors if attribute is missing.
✗ Incorrect
Terraform raises an error during plan if a referenced attribute does not exist. It does not silently ignore or defer errors to apply time.