opentofu/internal/command/jsonplan/condition.go
Martin Atkins fe7e6f970e command/jsonplan: Include new-style check results in JSON plan output
This is a new-shaped representation of check results which follows the
two-tiered structure of static objects and dynamic instances of objects,
thereby allowing consumers to see which checkable objects exist in the
configuration even if a dynamic evaluation error prevented actually
expanding them all to determine their declared instances.

Eventually we'll include this in the state too, but this initially adds it
only to the plan in order to replace the now-deprecated experimental
conditions result that was present but undocumented in Terraform v1.2.
2022-08-26 15:47:29 -07:00

45 lines
1.9 KiB
Go

package jsonplan
// conditionResult is the representation of an evaluated condition block.
//
// This no longer really fits how Terraform is modelling checks -- we're now
// treating check status as a whole-object thing rather than an individual
// condition thing -- but we've preserved this for now to remain as compatible
// as possible with the interface we'd experimentally-implemented but not
// documented in the Terraform v1.2 release, before we'd really solidified the
// use-cases for checks outside of just making a single plan and apply
// operation fail with an error.
type conditionResult struct {
// This is a weird "pseudo-comment" noting that we're deprecating this
// not-previously-documented, experimental representation of conditions
// in favor of the "checks" property which better fits Terraform Core's
// modelling of checks.
DeprecationNotice conditionResultDeprecationNotice `json:"//"`
// Address is the absolute address of the condition's containing object.
Address string `json:"address,omitempty"`
// Type is the condition block type, and is one of ResourcePrecondition,
// ResourcePostcondition, or OutputPrecondition.
Type string `json:"condition_type,omitempty"`
// Result is true if the condition succeeds, and false if it fails or is
// known only at apply time.
Result bool `json:"result"`
// Unknown is true if the condition can only be evaluated at apply time.
Unknown bool `json:"unknown"`
// ErrorMessage is the custom error for a failing condition. It is only
// present if the condition fails.
ErrorMessage string `json:"error_message,omitempty"`
}
type conditionResultDeprecationNotice struct{}
func (n conditionResultDeprecationNotice) MarshalJSON() ([]byte, error) {
return conditionResultDeprecationNoticeJSON, nil
}
var conditionResultDeprecationNoticeJSON = []byte(`"This previously-experimental representation of conditions is deprecated and will be removed in Terraform v1.4. Use the 'checks' property instead."`)