Terraform Cloud overview - Time & Space Complexity
We want to understand how the time to run Terraform Cloud operations changes as we add more infrastructure resources.
Specifically, how does the number of API calls and actions grow when Terraform Cloud manages more resources?
Analyze the time complexity of this Terraform Cloud workspace applying multiple resources.
resource "aws_instance" "example" {
count = var.instance_count
ami = "ami-123456"
instance_type = "t2.micro"
}
resource "aws_security_group" "example_sg" {
name = "example-sg"
}
This configuration creates a security group and multiple EC2 instances based on the count variable.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating each EC2 instance via AWS API calls.
- How many times: Once per instance, so equal to the count variable.
As the number of instances increases, the number of API calls grows proportionally.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | About 11 calls (10 instances + 1 security group) |
| 100 | About 101 calls |
| 1000 | About 1001 calls |
Pattern observation: The total operations increase directly with the number of instances.
Time Complexity: O(n)
This means the time to apply changes grows linearly as you add more resources.
[X] Wrong: "Adding more instances won't affect the total time much because Terraform Cloud handles everything in parallel."
[OK] Correct: While some tasks run in parallel, each resource still requires individual API calls and provisioning time, so total time grows with resource count.
Understanding how infrastructure size affects deployment time helps you design scalable and efficient cloud setups.
"What if we added modules that create multiple resources internally? How would that affect the time complexity?"