Module inputs (variables) in Terraform - Time & Space Complexity
We want to understand how the time to apply Terraform changes grows when we use module inputs (variables).
Specifically, how does the number of inputs affect the work Terraform does?
Analyze the time complexity of passing multiple variables into a Terraform module.
module "example" {
source = "./modules/example"
var1 = var.input1
var2 = var.input2
var3 = var.input3
# ... imagine many more variables
}
This code passes several input variables into a module to configure resources inside it.
Look at what repeats as the number of inputs grows.
- Primary operation: Terraform reads and processes each input variable to pass into the module.
- How many times: Once per input variable.
As you add more input variables, Terraform does more work reading and validating them.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 variable reads and validations |
| 100 | 100 variable reads and validations |
| 1000 | 1000 variable reads and validations |
Pattern observation: The work grows directly with the number of input variables.
Time Complexity: O(n)
This means the time to process inputs grows in a straight line as you add more variables.
[X] Wrong: "Adding more variables won't affect Terraform's processing time much."
[OK] Correct: Each variable requires reading and validation, so more variables mean more work.
Understanding how input size affects processing helps you design efficient modules and predict deployment times.
"What if we changed from many individual variables to a single map variable? How would the time complexity change?"