Your Terraform configuration declares a variable. You want to enforce that its value meets your specific requirements, and you want to block the Terraform operation if it does not. What should you add to your configuration?
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)., , , ]
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit