1. A platform team maintains a Terraform module for deploying an application load balancer. The module's `variables.tf` includes the following declaration: ```hcl variable "allowed_ports" { type = list(number) description = "List of ports the ALB listener should accept" validation { condition = length(var.allowed_ports) > 0 && alltrue([for p in var.allowed_ports : p >= 1 && p <= 65535]) error_message = "allowed_ports must contain at least one valid port number between 1 and 65535." } } ``` A developer calls this module in their root configuration but does NOT pass a value for `allowed_ports`. What is the result?
- A. Terraform applies successfully, using an empty list `[]` as the default value since no `default` is defined.
- B. Terraform throws a validation error because the list length is zero, which fails the `condition` expression.
- C. Terraform throws an error during the `plan` phase because no `default` is defined and no value was passed, making the variable required.✓ Correct
- D. Terraform ignores the missing variable and omits the ALB listener from the resulting plan.
Explanation
**Correct: C.** In Terraform, a `variable` block with no `default` argument is a *required* variable. When the calling module does not supply a value for a required variable, Terraform immediately errors during `terraform plan` (or `terraform apply`) with a message indicating the variable must be set — the validation block is never even evaluated because the absence of a value is caught first. **A is wrong** because Terraform does not infer a default of `[]` for `list(number)` types. Only an explicit `default = []` in the variable block would provide that behavior; without it the variable is required. **B is wrong** because the validation block's `condition` is only evaluated after a value has been supplied. Since no value is provided at all, Terraform never reaches the validation logic — the error occurs earlier, at variable resolution time. **D is wrong** because Terraform does not silently skip or ignore required inputs. Missing required variables are always a hard error that stops execution.