Open
Description
Hi All,
I'm trying to get what terraform writes to stdout and stderr and wrote the following code:
type StdWriter struct {
}
func (sw *StdWriter) Write(data []byte) (n int, err error) {
s := string(data)
print(s)
return 0, nil
}
func main() {
tf, err := tfexec.NewTerraform("./", "terraform")
stdout := &StdWriter{}
stderr := &StdWriter{}
tf.SetStdout(stdout)
tf.SetStderr(stderr)
err = tf.Init(context.Background(), tfexec.Upgrade(true))
if err != nil {
print("terraform init failed.")
print(err.Error())
}
}
I tried to test it on a terraform code that should fail when 'terraform init' executed:
resource "ssss" "ssss" {
}
if I run 'terraform init' in terminal I get the following in stdout:
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/ssss...
and in stderr:
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/ssss: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/ssss
If I try to run terraform with terraform-exec I get stdout printed as expected, but stderr is empty. If I change
tf.SetStderr(stderr)
to tf.SetStderr(os.Stderr)
then I can see stderr printed.
Do I miss something or stderr can be written only to os.Stderr ?
Metadata
Metadata
Assignees
Labels
No labels