0
0
Terraformcloud~20 mins

Mock providers in tests in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Mock Provider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use mock providers in Terraform tests?

What is the main reason to use mock providers when writing tests for Terraform modules?

ATo simulate provider behavior without making real API calls, speeding up tests and avoiding costs.
BTo deploy real infrastructure faster by skipping validation steps.
CTo automatically fix syntax errors in Terraform code during testing.
DTo replace Terraform CLI with a simpler command-line tool.
Attempts:
2 left
💡 Hint

Think about why you might want to avoid real cloud calls in tests.

Configuration
intermediate
1:30remaining
Identify the correct mock provider block in Terraform test

Which Terraform configuration snippet correctly defines a mock provider for testing?

Aprovider "mock" { version = "~> 1.0" }
Bprovider "mock" { mock = true }
Cprovider "mock" { test_mode = true }
Dprovider "mock" { mock_provider = true }
Attempts:
2 left
💡 Hint

Look for the standard way to specify provider version in Terraform.

Architecture
advanced
2:00remaining
How does a mock provider affect Terraform plan and apply?

When using a mock provider in Terraform tests, what is the expected behavior during terraform plan and terraform apply?

APlan and apply run without real API calls; resources are simulated but no real infrastructure is created.
BPlan runs normally, but apply creates real resources in the cloud.
CPlan fails because mock providers do not support planning.
DApply runs instantly and deletes all existing real resources.
Attempts:
2 left
💡 Hint

Consider what mock means in testing context.

security
advanced
1:30remaining
Security benefit of using mock providers in Terraform tests

What is a key security advantage of using mock providers when testing Terraform modules?

AThey prevent accidental exposure of real cloud credentials during tests.
BThey encrypt all Terraform state files automatically.
CThey disable all network access on the testing machine.
DThey automatically audit all Terraform code for vulnerabilities.
Attempts:
2 left
💡 Hint

Think about what happens if tests use real providers with credentials.

service_behavior
expert
2:00remaining
What happens if a mock provider returns unexpected resource attributes?

In a Terraform test using a mock provider, if the mock provider returns resource attributes that do not match the module's expected schema, what is the likely outcome?

ATerraform plan or apply will fail with a schema validation error.
BTerraform will ignore the extra attributes and succeed silently.
CTerraform will create real resources to compensate for missing attributes.
DTerraform will automatically fix the schema mismatch and continue.
Attempts:
2 left
💡 Hint

Consider how Terraform validates resource data during plan and apply.