Challenge - 5 Problems
Terraform Test Framework Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Understanding Terraform Test Framework Behavior
What will be the result of running a Terraform test that uses the
terraform_test block with required_providers specified but the provider version constraint is not met?Terraform
terraform {
required_version = ">= 1.6"
}
terraform {
required_providers = {
aws = {
source = "hashicorp/aws"
version = ">= 4.0, < 4.50"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "test" {
bucket = "tf-test-bucket"
}
output "bucket_name" {
value = aws_s3_bucket.test.bucket
}Attempts:
2 left
💡 Hint
Think about how Terraform enforces provider version constraints during initialization.
✗ Incorrect
Terraform test framework enforces the
required_providers version constraints strictly. If the installed provider version does not satisfy the constraint, the test run fails during initialization with a version conflict error.❓ Configuration
intermediate2:00remaining
Terraform Test Framework Output Verification
Given a Terraform test that creates an AWS S3 bucket and outputs its name, which option correctly verifies the output value in the test code using the Terraform test framework?
Terraform
terraform {
required_providers = {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
}
}
}
resource "aws_s3_bucket" "test" {
bucket = "tf-test-bucket"
}
output "bucket_name" {
value = aws_s3_bucket.test.bucket
}
// Test code snippet to verify output goes hereAttempts:
2 left
💡 Hint
Check the syntax for accessing outputs and the assertion function in Terraform test framework.
✗ Incorrect
In Terraform test framework, outputs are accessed as a map with string keys. The correct assertion function is
assert_equal(actual, expected). Option A uses the correct syntax and function.❓ Architecture
advanced2:00remaining
Isolating Test Runs with Terraform Test Framework
You want to run multiple Terraform tests in parallel, each creating resources in AWS without interfering with each other. Which approach best ensures isolation of test runs using Terraform test framework 1.6+?
Attempts:
2 left
💡 Hint
Think about how Terraform state and resource naming affect test isolation.
✗ Incorrect
To isolate tests, each test should use unique resource names (e.g., with random suffixes) and separate backend workspaces to keep state isolated. This prevents resource conflicts and state overwrites during parallel runs.
❓ security
advanced2:00remaining
Handling Sensitive Data in Terraform Tests
In Terraform test framework 1.6+, you need to test a module that requires sensitive variables like AWS credentials. What is the best practice to handle sensitive data securely during tests?
Attempts:
2 left
💡 Hint
Consider how Terraform handles sensitive variables and best security practices.
✗ Incorrect
Best practice is to pass sensitive data via environment variables or secure variable files marked as sensitive, and avoid exposing them in outputs or logs. Hardcoding or storing in plain text files risks leaks.
✅ Best Practice
expert2:00remaining
Optimizing Terraform Test Runs for Speed and Reliability
You have a large Terraform test suite using the Terraform test framework 1.6+. Tests create and destroy many resources, causing long execution times. Which strategy best improves test speed and reliability without sacrificing test coverage?
Attempts:
2 left
💡 Hint
Think about balancing test isolation with resource reuse to optimize performance.
✗ Incorrect
Grouping tests to share setup and teardown reduces redundant resource creation and destruction, speeding up tests while maintaining coverage and reliability. Independent full runs increase time, skipping reduces coverage, and manual cleanup risks state drift.