Skip to content

Commit

Permalink
improve error logging in example code
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoe committed Apr 21, 2021
1 parent 25a94d1 commit 2b60e5d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"fmt"
"io/ioutil"
"os"
"log"

"github.com/hashicorp/terraform-exec/tfexec"
"github.com/hashicorp/terraform-exec/tfinstall"
Expand All @@ -36,29 +37,29 @@ import (
func main() {
tmpDir, err := ioutil.TempDir("", "tfinstall")
if err != nil {
panic(err)
log.Fatalf("error creating temp dir: %s", err)
}
defer os.RemoveAll(tmpDir)

execPath, err := tfinstall.Find(context.Background(), tfinstall.LatestVersion(tmpDir, false))
if err != nil {
panic(err)
log.Fatalf("error locating Terraform binary: %s", err)
}

workingDir := "/path/to/working/dir"
tf, err := tfexec.NewTerraform(workingDir, execPath)
if err != nil {
panic(err)
log.Fatalf("error running NewTerraform: %s", err)
}

err = tf.Init(context.Background(), tfexec.Upgrade(true))
if err != nil {
panic(err)
log.Fatalf("error running Init: %s", err)
}

state, err := tf.Show(context.Background())
if err != nil {
panic(err)
log.Fatalf("error running Show: %s", err)
}

fmt.Println(state.FormatVersion) // "0.1"
Expand Down

0 comments on commit 2b60e5d

Please sign in to comment.