Plan output reading in Terraform - Time & Space Complexity
When Terraform creates a plan, it shows what changes it will make. Understanding how long it takes to read this plan helps us know how it scales as the plan grows.
We want to know: how does the time to read the plan grow as the number of resources increases?
Analyze the time complexity of reading Terraform plan output for multiple resources.
resource "aws_instance" "example" {
count = var.instance_count
ami = var.ami_id
instance_type = "t2.micro"
}
output "instance_ids" {
value = aws_instance.example[*].id
}
This code creates multiple instances and outputs their IDs in a list.
When reading the plan output, Terraform processes each resource's state and attributes.
- Primary operation: Reading each resource's ID from the plan output.
- How many times: Once per resource instance (equal to
count).
As the number of instances grows, Terraform reads more IDs to build the output list.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 reads of instance IDs |
| 100 | 100 reads of instance IDs |
| 1000 | 1000 reads of instance IDs |
Pattern observation: The number of reads grows directly with the number of instances.
Time Complexity: O(n)
This means reading the plan output takes time proportional to the number of resources.
[X] Wrong: "Reading the plan output is always fast and constant time regardless of resource count."
[OK] Correct: The plan output includes details for each resource, so reading grows with how many resources there are.
Knowing how plan output reading scales helps you understand Terraform's behavior on bigger projects. This skill shows you can think about tool performance as infrastructure grows.
"What if we changed the output to include nested attributes for each instance? How would the time complexity change?"