MCPcopy
hub / github.com/adammck/terraform-inventory / read

Method read

parser.go:75–96  ·  view source on GitHub ↗

read populates the state object from a statefile.

(stateFile io.Reader)

Source from the content-addressed store, hash-verified

73
74// read populates the state object from a statefile.
75func (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.
99func (s *state) outputs() []*Output {

Callers 8

TestListCommandFunction · 0.95
TestHostCommandFunction · 0.95
TestInventoryCommandFunction · 0.95
mainFunction · 0.95

Calls

no outgoing calls

Tested by 7

TestListCommandFunction · 0.76
TestHostCommandFunction · 0.76
TestInventoryCommandFunction · 0.76