Terraform Cloud/Enterprise features - Time & Space Complexity
When using Terraform Cloud or Enterprise features, it is important to understand how the time to complete operations changes as you add more resources or workspaces.
We want to know how the number of API calls and tasks grows when managing infrastructure with these features.
Analyze the time complexity of running Terraform plans and applies across multiple workspaces using Terraform Cloud.
resource "tfe_workspace" "example" {
count = var.workspace_count
name = "workspace-${count.index}"
organization = var.organization
}
resource "tfe_run" "trigger" {
count = var.workspace_count
workspace_id = tfe_workspace.example[count.index].id
depends_on = [tfe_workspace.example]
}
This code creates multiple workspaces and triggers runs in Terraform Cloud for each workspace.
Each workspace creation and run trigger involves API calls to Terraform Cloud.
- Primary operation: API calls to create workspaces and trigger runs.
- How many times: Once per workspace, so the number grows with the number of workspaces.
As you increase the number of workspaces, the number of API calls and triggered runs grows proportionally.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | About 20 (10 workspace creations + 10 run triggers) |
| 100 | About 200 (100 workspace creations + 100 run triggers) |
| 1000 | About 2000 (1000 workspace creations + 1000 run triggers) |
Pattern observation: The total operations double the number of workspaces, growing linearly.
Time Complexity: O(n)
This means the time and API calls grow directly in proportion to the number of workspaces managed.
[X] Wrong: "Adding more workspaces won't affect the number of API calls much because they run in parallel."
[OK] Correct: Even if runs happen in parallel, each workspace still requires separate API calls, so total calls increase with workspace count.
Understanding how Terraform Cloud features scale helps you design infrastructure automation that stays efficient as your projects grow.
"What if we used a single workspace with multiple modules instead of many workspaces? How would the time complexity change?"