opentofu/internal/command/jsonchecks/status.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

28 lines
602 B
Go

package jsonchecks
import (
"fmt"
"github.com/hashicorp/terraform/internal/checks"
)
type checkStatus []byte
func checkStatusForJSON(s checks.Status) checkStatus {
if ret, ok := checkStatuses[s]; ok {
return ret
}
panic(fmt.Sprintf("unsupported check status %#v", s))
}
func (s checkStatus) MarshalJSON() ([]byte, error) {
return []byte(s), nil
}
var checkStatuses = map[checks.Status]checkStatus{
checks.StatusPass: checkStatus(`"pass"`),
checks.StatusFail: checkStatus(`"fail"`),
checks.StatusError: checkStatus(`"error"`),
checks.StatusUnknown: checkStatus(`"unknown"`),
}