Default workspace in Terraform - Time & Space Complexity
When using Terraform, the default workspace manages your infrastructure state. Understanding how operations scale with workspace use helps us know how long deployments take.
We want to see how the number of API calls changes as we use the default workspace for multiple resources.
Analyze the time complexity of the following Terraform configuration using the default workspace.
resource "aws_instance" "example" {
count = var.instance_count
ami = "ami-12345678"
instance_type = "t2.micro"
}
This code creates multiple AWS instances in the default workspace based on the count variable.
Each instance creation triggers API calls to AWS.
- Primary operation: API call to create each AWS instance.
- How many times: Once per instance, equal to the count variable.
As you increase the number of instances, the number of API calls grows directly with it.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 API calls |
| 100 | 100 API calls |
| 1000 | 1000 API calls |
Pattern observation: The number of API calls grows linearly with the number of instances.
Time Complexity: O(n)
This means the time to create resources grows directly in proportion to how many you create.
[X] Wrong: "Using the default workspace means all resources are created with a single API call regardless of count."
[OK] Correct: Each resource still requires its own API call; the workspace just manages state, not batching.
Knowing how resource count affects API calls helps you plan deployments and understand Terraform's behavior in real projects.
"What if we switched from the default workspace to multiple named workspaces? How would the time complexity change?"