hashicorp / terraform-exec

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

tfexec `Terraform.Output` method returns error when command is successful #470

Open Ravikc opened 1 month ago

Ravikc commented 1 month ago

I am using terraform-exec with HCP terraform to manage some infra. When running terraform output command, logs show that there was a connection error and it's trying to re-establish the connection, eventually the command logs the correct output, but Terraform.Output method returns an error.

Expected behaviour: error returned by Terraform.Output should be nil.

Error returned by the library: invalid character 'T' looking for beginning of value

Logs:

time=2024-07-11T13:06:33.111Z level=INFO msg="[INFO] running Terraform command: /home/terraform/app/terraform output -no-color -json"

There was an error connecting to HCP Terraform. Please do not exit
Terraform to prevent data loss! Trying to restore the connection...

Still trying to restore the connection... (3s elapsed)
Still trying to restore the connection... (5s elapsed)
Still trying to restore the connection... (8s elapsed)
Still trying to restore the connection... (12s elapsed)
Still trying to restore the connection... (17s elapsed)
{
  "ubuntu1_public_dns": {
    "sensitive": false,
    "type": "string",
    "value": "<some-value-here>"
  },
  "ubuntu_public_dns": {
    "sensitive": false,
    "type": "string",
    "value": "<some-value-here>"
  }
}

It's probably failing when trying to convert the command's output into map[string]OutputMeta

Ravikc commented 1 month ago

@kmoe could you please help confirming if this is indeed an issue in the library or I might be doing something wrong.