Provisioner failure behavior in Terraform - Time & Space Complexity
When Terraform runs provisioners, it may retry or stop on failure. Understanding how the time taken grows with the number of provisioners helps us plan deployments better.
We want to know how the total execution time changes as we add more provisioners that might fail.
Analyze the time complexity of running multiple local-exec provisioners with failure handling.
resource "null_resource" "example" {
count = var.provisioner_count
provisioner "local-exec" {
command = "echo Running provisioner ${count.index}"
on_failure = "continue"
}
}
This creates multiple resources each with a local-exec provisioner that continues even if it fails.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Running each local-exec provisioner command.
- How many times: Once per provisioner, equal to the number of provisioners defined.
Each provisioner runs its command independently. As you add more provisioners, the total time grows roughly in direct proportion.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 provisioner runs |
| 100 | 100 provisioner runs |
| 1000 | 1000 provisioner runs |
Pattern observation: The total execution time increases linearly as the number of provisioners increases.
Time Complexity: O(n)
This means the time to run all provisioners grows directly with how many provisioners you have.
[X] Wrong: "Provisioners run in parallel, so adding more won't increase total time much."
[OK] Correct: By default, provisioners run one after another, so adding more means more total time.
Knowing how provisioner failures affect deployment time helps you design reliable and predictable infrastructure automation.
"What if we changed on_failure from 'continue' to 'fail'? How would the time complexity change when a provisioner fails early?"