hashicorp / terraform-exec

Terraform CLI commands via Go.
https://pkg.go.dev/github.com/hashicorp/terraform-exec
Mozilla Public License 2.0
661 stars 111 forks source link

Init error return #419

Open zthacker opened 10 months ago

zthacker commented 10 months ago

Hey All,

I couldn't find this answer anywhere, so I'd like to ask here.

Given the following code:

    tf, err := tfexec.NewTerraform("./terraformexample", execPath)
    if err != nil {
        return err
    }

    err = tf.Init(context.Background(), tfexec.Upgrade(true))
    if err != nil {
        return err
    }

I expect tf.Init to return an error as there are no terraform config files in the ./terraformexampole directory. However, this isn't the case.

If I were to run terraform init within that directory, it does error out in reference to not having any terraform config files.

Am I doing anything wrong, or is this expected? My confusion comes from the tf.Init doc:

Init represents the terraform init subcommand.