Sensitive variables in Terraform - Time & Space Complexity
We want to understand how the time to process sensitive variables changes as we add more of them in Terraform.
How does the number of sensitive variables affect the work Terraform does?
Analyze the time complexity of defining and using sensitive variables in Terraform.
variable "db_password" {
type = string
sensitive = true
}
variable "api_key" {
type = string
sensitive = true
}
output "db_password" {
value = var.db_password
sensitive = true
}
This code defines sensitive variables and outputs them without showing their values in logs.
When Terraform runs, it processes each sensitive variable to keep its value hidden.
- Primary operation: Handling each sensitive variable's value securely during plan and apply.
- How many times: Once per sensitive variable defined and used.
As you add more sensitive variables, Terraform does more work to keep each one secure.
| Input Size (n) | Approx. Secure Handling Steps |
|---|---|
| 10 | 10 secure handling steps |
| 100 | 100 secure handling steps |
| 1000 | 1000 secure handling steps |
Pattern observation: The work grows directly with the number of sensitive variables.
Time Complexity: O(n)
This means the time to handle sensitive variables grows in a straight line as you add more of them.
[X] Wrong: "Sensitive variables don't affect execution time because they are just hidden values."
[OK] Correct: Each sensitive variable requires extra steps to keep its value secure, so more variables mean more work.
Understanding how sensitive data handling scales helps you design secure and efficient infrastructure code.
"What if we changed sensitive variables to regular variables? How would the time complexity change?"