Why testing infrastructure matters in Terraform - Performance Analysis
Testing infrastructure helps us catch problems early before they affect real users.
We want to know how the time to test grows as we add more infrastructure parts.
Analyze the time complexity of running tests on multiple Terraform modules.
module "network" {
source = "./modules/network"
}
module "compute" {
source = "./modules/compute"
}
module "storage" {
source = "./modules/storage"
}
# Run tests for each module
resource "null_resource" "test" {
count = length([module.network, module.compute, module.storage])
provisioner "local-exec" {
command = "terraform validate ./modules/${element([\"network\", \"compute\", \"storage\"], count.index)}"
}
}
This runs validation tests on each infrastructure module separately.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Running
terraform validateon each module - How many times: Once per module, so as many times as modules exist
Each new module adds one more validation run.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 validation runs |
| 100 | 100 validation runs |
| 1000 | 1000 validation runs |
Pattern observation: The time to test grows directly with the number of modules.
Time Complexity: O(n)
This means testing time grows in a straight line as you add more infrastructure parts.
[X] Wrong: "Testing all modules together takes the same time as testing one module."
[OK] Correct: Each module needs its own test run, so more modules mean more testing time.
Understanding how testing time grows helps you plan and keep infrastructure reliable as it grows.
"What if we combined all modules into one big module and tested once? How would the time complexity change?"