command/jsonstate: Include check results in JSON state report

This commit is contained in:
Martin Atkins 2022-08-24 11:29:52 -07:00
parent 0e4e9f7706
commit a8c255c779

View File

@ -9,6 +9,7 @@ import (
ctyjson "github.com/zclconf/go-cty/cty/json"
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/command/jsonchecks"
"github.com/hashicorp/terraform/internal/lang/marks"
"github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/states/statefile"
@ -23,9 +24,10 @@ const FormatVersion = "1.0"
// state is the top-level representation of the json format of a terraform
// state.
type state struct {
FormatVersion string `json:"format_version,omitempty"`
TerraformVersion string `json:"terraform_version,omitempty"`
Values *stateValues `json:"values,omitempty"`
FormatVersion string `json:"format_version,omitempty"`
TerraformVersion string `json:"terraform_version,omitempty"`
Values *stateValues `json:"values,omitempty"`
Checks json.RawMessage `json:"checks,omitempty"`
}
// stateValues is the common representation of resolved values for both the prior
@ -150,6 +152,11 @@ func Marshal(sf *statefile.File, schemas *terraform.Schemas) ([]byte, error) {
return nil, err
}
// output.Checks
if sf.State.CheckResults != nil && sf.State.CheckResults.ConfigResults.Len() > 0 {
output.Checks = jsonchecks.MarshalCheckStates(sf.State.CheckResults)
}
ret, err := json.Marshal(output)
return ret, err
}