terraform: minor edits to reading state to prep for validation
This commit is contained in:
parent
6b67227331
commit
c65bbc4f0c
|
@ -1522,6 +1522,7 @@ func ReadState(src io.Reader) (*State, error) {
|
||||||
return nil, fmt.Errorf("Decoding state file version failed: %v", err)
|
return nil, fmt.Errorf("Decoding state file version failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var result *State
|
||||||
switch versionIdentifier.Version {
|
switch versionIdentifier.Version {
|
||||||
case 0:
|
case 0:
|
||||||
return nil, fmt.Errorf("State version 0 is not supported as JSON.")
|
return nil, fmt.Errorf("State version 0 is not supported as JSON.")
|
||||||
|
@ -1543,7 +1544,7 @@ func ReadState(src io.Reader) (*State, error) {
|
||||||
|
|
||||||
// increment the Serial whenever we upgrade state
|
// increment the Serial whenever we upgrade state
|
||||||
v3State.Serial++
|
v3State.Serial++
|
||||||
return v3State, nil
|
result = v3State
|
||||||
case 2:
|
case 2:
|
||||||
v2State, err := ReadStateV2(jsonBytes)
|
v2State, err := ReadStateV2(jsonBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1555,18 +1556,25 @@ func ReadState(src io.Reader) (*State, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
v3State.Serial++
|
v3State.Serial++
|
||||||
return v3State, nil
|
result = v3State
|
||||||
case 3:
|
case 3:
|
||||||
v3State, err := ReadStateV3(jsonBytes)
|
v3State, err := ReadStateV3(jsonBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return v3State, nil
|
|
||||||
|
result = v3State
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
return nil, fmt.Errorf("Terraform %s does not support state version %d, please update.",
|
||||||
SemVersion.String(), versionIdentifier.Version)
|
SemVersion.String(), versionIdentifier.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we reached this place we must have a result set
|
||||||
|
if result == nil {
|
||||||
|
panic("resulting state in load not set, assertion failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadStateV1(jsonBytes []byte) (*stateV1, error) {
|
func ReadStateV1(jsonBytes []byte) (*stateV1, error) {
|
||||||
|
|
Loading…
Reference in New Issue