postcondition available for
module creations or only for resources?
lifecycle block in which conditions are defined is conspicuously absent from the documentation for modules, I think not.
Which actually makes sense - modules introduce various additional
data blocks into the overall graph processing of a Terraform configuration, but those blocks can end up getting processed freely intermixed with those from other modules - i.e. there is no reasonable definition of “pre” and “post” for modules.
You can always decide to define a
null_resource inside the module, though, and add conditions to that. You would, however, then need to add dependencies between the
null_resource and everything else in the module, if you intended the conditions to run with a guaranteed ordering beyond that required by implicit dependencies due to data flows.
It is possible to declare a
precondition inside an
output block to declare something that ought to be true in order for that output value to be valid. That can be a good place to declare some conditions that should generally be true about the results of a module, without necessarily attaching them to a particular
precondition rather than a
postcondition because when used in a root module it prevents the invalid new value from being written out to the state where a
terraform_remote_state data source could find it. The distinction between “pre” and “post” doesn’t really make any difference for modules being called from
module blocks because evaluating an output value doesn’t have any externally-visible side effects anyway.)