github.com/openshift/installer@v1.4.17/pkg/terraform/state.go (about) 1 package terraform 2 3 import ( 4 "context" 5 "encoding/json" 6 7 "github.com/pkg/errors" 8 ) 9 10 // StateFilename is the default name of the terraform state file. 11 const StateFilename = "terraform.tfstate" 12 13 // Outputs reads the terraform state file and returns the outputs of the stage as json. 14 func Outputs(dir string, terraformDir string) ([]byte, error) { 15 tf, err := newTFExec(dir, terraformDir) 16 if err != nil { 17 return nil, err 18 } 19 20 tfoutput, err := tf.Output(context.Background()) 21 if err != nil { 22 return nil, errors.Wrap(err, "failed to read terraform state file") 23 } 24 25 outputs := make(map[string]interface{}, len(tfoutput)) 26 for key, value := range tfoutput { 27 outputs[key] = value.Value 28 } 29 30 data, err := json.Marshal(outputs) 31 return data, errors.Wrap(err, "could not marshal outputs") 32 }