github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/helper/terraform/outputs.go (about)

     1  package terraform
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/terraform/terraform"
     7  )
     8  
     9  // Outputs reads the outputs from the Terraform state at the given path.
    10  //
    11  // This is currently done by using the Terraform API to read from the
    12  // state file directory. In the future, this may work by shelling out to
    13  // Terraform which might be more stable.
    14  func Outputs(path string) (map[string]string, error) {
    15  	// Read the state structure itself
    16  	state, err := readState(path)
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  
    21  	// Return the outputs
    22  	return state.RootModule().Outputs, nil
    23  }
    24  
    25  func readState(path string) (*terraform.State, error) {
    26  	f, err := os.Open(path)
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  	defer f.Close()
    31  
    32  	return terraform.ReadState(f)
    33  }