Plan and apply separation in pipelines in Terraform - Time & Space Complexity
When using Terraform pipelines, we want to know how the time to plan and apply changes grows as we add more separated pipeline stages.
We ask: How does splitting work into separate pipeline steps affect the total operations needed?
Analyze the time complexity of this Terraform pipeline setup.
terraform {
backend "s3" {}
}
module "network" {
source = "./modules/network"
count = var.env_count
}
module "compute" {
source = "./modules/compute"
count = var.env_count
}
This pipeline separates infrastructure into network and compute modules, each applied in stages for multiple environments.
Look at what repeats as we increase environments.
- Primary operation: Terraform plan and apply for each module per environment.
- How many times: Twice per environment (once for network, once for compute).
As the number of environments grows, the total operations increase proportionally.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 20 (2 modules x 10 envs) |
| 100 | 200 (2 modules x 100 envs) |
| 1000 | 2000 (2 modules x 1000 envs) |
Pattern observation: Operations grow linearly with the number of environments multiplied by the number of pipeline stages.
Time Complexity: O(n)
This means the total work grows directly in proportion to how many environments you have.
[X] Wrong: "Separating pipeline stages will reduce total operations to a constant time."
[OK] Correct: Each environment still needs its own plan and apply per stage, so total operations add up, not stay fixed.
Understanding how pipeline separation affects operation counts helps you design scalable infrastructure workflows confidently.
What if we combined all modules into one pipeline stage? How would the time complexity change?