mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
normalize empty CheckResults fields in stateV4
Ensure that empty check results are normalized in state serialization to prevent unexpected state changes from being written. Because there is no consistent empty, null and omit_empty usage for state structs, there's no good way to create a test which will fail for future additions.
This commit is contained in:
parent
fa4c652013
commit
eae246cfb5
@ -414,9 +414,7 @@ func writeStateV4(file *File, w io.Writer) tfdiags.Diagnostics {
|
||||
}
|
||||
}
|
||||
|
||||
if file.State.CheckResults != nil {
|
||||
sV4.CheckResults = encodeCheckResultsV4(file.State.CheckResults)
|
||||
}
|
||||
sV4.CheckResults = encodeCheckResultsV4(file.State.CheckResults)
|
||||
|
||||
sV4.normalize()
|
||||
|
||||
@ -576,6 +574,11 @@ func decodeCheckResultsV4(in []checkResultsV4) (*states.CheckResults, tfdiags.Di
|
||||
}
|
||||
|
||||
func encodeCheckResultsV4(in *states.CheckResults) []checkResultsV4 {
|
||||
// normalize empty and nil sets in the serialized state
|
||||
if in == nil || in.ConfigResults.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
ret := make([]checkResultsV4, 0, in.ConfigResults.Len())
|
||||
|
||||
for _, configElem := range in.ConfigResults.Elems {
|
||||
|
Loading…
Reference in New Issue
Block a user