Terraform test framework (1.6+) - Time & Space Complexity
We want to understand how the time to run Terraform tests changes as we add more tests or resources.
Specifically, how does the testing process scale when using the Terraform test framework version 1.6 or newer?
Analyze the time complexity of running multiple Terraform tests that each create resources.
terraform {
required_version = ">= 1.6"
}
test "example_test" {
steps = [
{
run = "terraform apply -auto-approve"
},
{
check = "terraform output"
}
]
}
This defines a simple Terraform test that applies infrastructure and checks outputs.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Running
terraform applyto create or update resources. - How many times: Once per test step that applies infrastructure.
- Secondary operation: Running
terraform outputto check state after apply. - How many times: Once per test step that checks outputs.
Each test runs its apply and output commands independently, so adding more tests adds more runs.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 tests | About 20 terraform commands (apply + output per test) |
| 100 tests | About 200 terraform commands |
| 1000 tests | About 2000 terraform commands |
Pattern observation: The number of terraform commands grows linearly with the number of tests.
Time Complexity: O(n)
This means the time to run tests grows directly in proportion to the number of tests you have.
[X] Wrong: "Running more tests will only add a small fixed amount of time because Terraform caches everything."
[OK] Correct: Each test runs separate apply and output commands, so the time grows with the number of tests, not fixed.
Understanding how test execution time grows helps you plan and manage infrastructure testing efficiently in real projects.
"What if we combined multiple tests into one test with multiple steps? How would the time complexity change?"