Rationale for Correct Answer: To enforce constraints on an input variable, Terraform provides variable validation using a validation block inside the variable block. If the condition fails, Terraform produces an error and prevents the operation (plan/apply) from continuing with invalid input.
Analysis of Incorrect Options (Distractors):
A (Top-level check block): check blocks validate conditions, but they are not the standard mechanism for constraining input variable values at the point of declaration; variable validation is.
C (Top-level validation block): Terraform does not support a standalone top-level validation block.
D (check block in the variable block): check is not placed inside variable blocks for input validation; the correct construct is validation.
Key Concept: Input variable validation to enforce constraints and fail fast.
[Reference: Terraform Objectives — Read, Generate, and Modify Configurations (input variables and validation)., , , , , , ]
Submit