Output declaration syntax in Terraform - Time & Space Complexity
We want to understand how the time to process output declarations changes as we add more outputs.
How does the number of outputs affect the work Terraform does when applying?
Analyze the time complexity of declaring multiple outputs in Terraform.
output "example_output" {
value = aws_instance.example.id
}
output "another_output" {
value = aws_s3_bucket.example.bucket
}
output "count_output" {
value = length(aws_instance.example[*].id)
}
This sequence declares several outputs to show resource attributes after deployment.
Each output declaration causes Terraform to read resource attributes to show after apply.
- Primary operation: Reading resource attribute values for each output.
- How many times: Once per output declared.
As you add more outputs, Terraform reads more resource attributes, increasing work linearly.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 attribute reads |
| 100 | 100 attribute reads |
| 1000 | 1000 attribute reads |
Pattern observation: The work grows directly with the number of outputs.
Time Complexity: O(n)
This means the time to process outputs grows in direct proportion to how many outputs you declare.
[X] Wrong: "Adding more outputs does not affect apply time much."
[OK] Correct: Each output requires reading resource data, so more outputs mean more work.
Knowing how output declarations affect execution helps you design efficient Terraform configurations and shows you understand resource management.
"What if outputs reference complex computed values instead of simple attributes? How would the time complexity change?"