0
0
Terraformcloud~5 mins

Module inputs (variables) in Terraform - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Module inputs (variables)
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As you add more input variables, Terraform does more work reading and validating them.

Input Size (n)Approx. Operations
1010 variable reads and validations
100100 variable reads and validations
10001000 variable reads and validations

Pattern observation: The work grows directly with the number of input variables.

Final Time Complexity

Time Complexity: O(n)

This means the time to process inputs grows in a straight line as you add more variables.

Common Mistake

[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.

Interview Connect

Understanding how input size affects processing helps you design efficient modules and predict deployment times.

Self-Check

"What if we changed from many individual variables to a single map variable? How would the time complexity change?"