Auto-approve flag and its danger in Terraform - Time & Space Complexity
We want to understand how using the auto-approve flag affects the number of operations Terraform performs.
Specifically, how does it change the approval step when applying changes?
Analyze the time complexity of running Terraform apply with and without the auto-approve flag.
terraform apply -auto-approve
terraform apply
This sequence shows applying infrastructure changes automatically versus requiring manual approval.
Look at what happens repeatedly during apply commands.
- Primary operation: Terraform plans and applies changes to resources.
- How many times: Each apply command triggers one plan and one apply operation.
- Approval step: Without auto-approve, a manual confirmation is required before applying.
As the number of resources grows, the plan and apply steps take longer.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | ~10 resource operations + 1 approval step |
| 100 | ~100 resource operations + 1 approval step |
| 1000 | ~1000 resource operations + 1 approval step |
Pattern observation: The approval step is constant and does not grow with input size.
Time Complexity: O(n)
This means the main work grows linearly with the number of resources, while approval is a fixed step.
[X] Wrong: "Using auto-approve makes Terraform run faster because it skips steps."
[OK] Correct: Auto-approve only skips manual confirmation; it does not reduce the number of resource operations, which dominate execution time.
Understanding how flags like auto-approve affect operation flow helps you explain automation trade-offs clearly and confidently.
"What if we added a pre-check script before apply? How would that affect the time complexity?"