Sensitive output values in Terraform - Time & Space Complexity
We want to understand how marking output values as sensitive affects the time it takes Terraform to run.
Specifically, how does this choice impact the number of operations Terraform performs?
Analyze the time complexity of marking outputs as sensitive in Terraform.
output "db_password" {
value = aws_db_instance.example.password
sensitive = true
}
output "db_endpoint" {
value = aws_db_instance.example.endpoint
}
This code marks the database password output as sensitive, hiding it from normal display, while the endpoint is shown normally.
Terraform reads and processes each output value during plan and apply.
- Primary operation: Reading and optionally masking output values.
- How many times: Once per output defined in the configuration.
As the number of outputs increases, Terraform processes each output once.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 output processing steps |
| 100 | 100 output processing steps |
| 1000 | 1000 output processing steps |
Pattern observation: The work grows directly with the number of outputs.
Time Complexity: O(n)
This means the time to process outputs grows linearly with how many outputs you have.
[X] Wrong: "Marking outputs as sensitive makes Terraform run much slower because it hides values."
[OK] Correct: Marking outputs sensitive only changes display behavior; Terraform still processes each output once, so the time grows linearly, not slower or faster.
Understanding how output configurations affect Terraform's work helps you design efficient infrastructure code and explain your choices clearly.
"What if we added many outputs that are all marked sensitive? How would that affect the time complexity?"