The check {} block
Unlike the input variable validations and the custom preconditions/postconditions, check {}
blocks are not tied to the resource lifecycle directly. check {}
blocks are used to validate the checks for the overall configuration after the plan/apply operations.
check {}
blocks can help perform the functional validation of the provisioned infrastructure after apply
– check {}
blocks have assert {}
block inside them, which, in turn, contain the condition
and error_message
arguments.
Another major difference is that check {}
blocks will allow the terraform plan
/apply
operation to go through in the case of validation failures. The error message will be written at the end if the defined condition seems to be invalid. This can also be used with data sources.
To understand this block better, we will define an AWS Simple Storage Service (S3) bucket and check the force_destroy
parameter in the check {}
block:
resource "aws_s3_bucket" "app_bucket...