mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
f40800b3a4
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package statefile
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/hashicorp/terraform/internal/states"
|
|
)
|
|
|
|
// StatesMarshalEqual returns true if and only if the two given states have
|
|
// an identical (byte-for-byte) statefile representation.
|
|
//
|
|
// This function compares only the portions of the state that are persisted
|
|
// in state files, so for example it will not return false if the only
|
|
// differences between the two states are local values or descendent module
|
|
// outputs.
|
|
func StatesMarshalEqual(a, b *states.State) bool {
|
|
var aBuf bytes.Buffer
|
|
var bBuf bytes.Buffer
|
|
|
|
// nil states are not valid states, and so they can never martial equal.
|
|
if a == nil || b == nil {
|
|
return false
|
|
}
|
|
|
|
// We write here some temporary files that have no header information
|
|
// populated, thus ensuring that we're only comparing the state itself
|
|
// and not any metadata.
|
|
err := Write(&File{State: a}, &aBuf)
|
|
if err != nil {
|
|
// Should never happen, because we're writing to an in-memory buffer
|
|
panic(err)
|
|
}
|
|
err = Write(&File{State: b}, &bBuf)
|
|
if err != nil {
|
|
// Should never happen, because we're writing to an in-memory buffer
|
|
panic(err)
|
|
}
|
|
|
|
return bytes.Equal(aBuf.Bytes(), bBuf.Bytes())
|
|
}
|