in cli/pkg/lifecycle/tf_deploy.go [29:65]
func InitTF(tfDir string) {
tmpDir, err := os.MkdirTemp("", "tfinstall")
if err != nil {
log.Fatalf("error creating temp dir: %s", err)
}
defer os.RemoveAll(tmpDir)
execPath, err := tfinstall.Find(context.Background(), tfinstall.ExactVersion("1.9.5", tmpDir))
if err != nil {
log.Fatalf("error locating Terraform binary: %s", err)
}
tf, err := tfexec.NewTerraform(tfDir, execPath)
if err != nil {
log.Fatalf("error running NewTerraform: %s", err)
}
tf.SetStdout(log.StandardLogger().Out)
err = tf.Init(context.Background(), tfexec.Upgrade(true))
if err != nil {
log.Fatalf("error running Init: %s", err)
}
state, err := tf.Show(context.Background())
if err != nil {
log.Fatalf("error running Show: %s", err)
}
log.Println(state.FormatVersion) // "0.1"
plan, err := tf.Plan(context.Background(), tfexec.VarFile("../terraform.tfvars"))
if err != nil {
log.Fatalf("error running Plan: %s", err)
}
log.Println(plan)
}