read populates the state object from a statefile.
(stateFile io.Reader)
| 73 | |
| 74 | // read populates the state object from a statefile. |
| 75 | func (s *stateAnyTerraformVersion) read(stateFile io.Reader) error { |
| 76 | s.TerraformVersion = TerraformVersionUnknown |
| 77 | |
| 78 | b, readErr := ioutil.ReadAll(stateFile) |
| 79 | if readErr != nil { |
| 80 | return readErr |
| 81 | } |
| 82 | |
| 83 | err0dot12 := json.Unmarshal(b, &(*s).State0dot12) |
| 84 | if err0dot12 == nil && s.State0dot12.Values.RootModule != nil { |
| 85 | s.TerraformVersion = TerraformVersion0dot12 |
| 86 | } else { |
| 87 | errPre0dot12 := json.Unmarshal(b, &(*s).StatePre0dot12) |
| 88 | if errPre0dot12 == nil && s.StatePre0dot12.Modules != nil { |
| 89 | s.TerraformVersion = TerraformVersionPre0dot12 |
| 90 | } else { |
| 91 | return fmt.Errorf("0.12 format error: %v; pre-0.12 format error: %v (nil error means no content/modules found in the respective format)", err0dot12, errPre0dot12) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return nil |
| 96 | } |
| 97 | |
| 98 | // outputs returns a slice of the Outputs found in the statefile. |
| 99 | func (s *state) outputs() []*Output { |
no outgoing calls