Input Validations
In real-world scenarios, it is very common to get the necessary inputs from the user and provision the infrastructure accordingly. For example, you can assume that you are part of a central DevOps team that is involved in setting up the CICD pipelines for any team requiring your service. In this case, they might need to provide basic inputs such as application name/ID, cloud-specific details such as region, and so on.
If the infrastructure provisioning is automated from your end, such that the workflow will trigger directly when the user provides the input via a ticket, it becomes necessary to run the workflow for valid inputs only. Manual errors in inputs would also need to be filtered as early as possible.
This is where input validations will help, and in Terraform, this can be achieved by adding the validation {}
block with the condition
argument specifying the rules in the form of expressions. If the result of the expression is TRUE
, the input will be considered...