Error: could not parse state: json: cannot unmarshal array into Go struct field terraformOutput.outputs.value of type string
I hit the following issue when I added a Terraform output of type array.
Terraform Cloud Plan & Apply passes successfully and I can see array output.
But kvrhdn/tfe-run action fails with
Run kvrhdn/[email protected]
...
Run has been applied!
Error: could not parse state: json: cannot unmarshal array into Go struct field terraformOutput.outputs.value of type string
My Terraform output
terraform output
name = [
"my-name",
]
Okay this is unfortunate... after applying the config, this action will fetch the outputs and expose them as outputs in GitHub Actions. This implementation is basic but good enough, until now I guess.
The terraformOutput struct in the following code should be adapted to handle arrays:
https://github.com/kvrhdn/go-tfe-run/blob/104d8cce779fddd82ad7a9e81fe74090b02742a9/tferun.go#L283-L317
Even better would be to get rid of this code and use an external library or Terraform itself for this.
The following steps maybe useful for others. Uses terraform output -json and jq to get some terraform output called named foo
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.2
cli_config_credentials_token: ${{ secrets.TFC_ACCESS_TOKEN }}
terraform_wrapper: false # required to use terraform cli
- name: Terraform Output
run: |
TF_OUT=$( terraform output -json )
echo "TF_OUT=${TF_OUT}"
FOO=$( jq '.foo.value' <<< ${TF_OUT} )
echo "::set-output name=foo::$FOO"
id: tfout
Created a PR for this https://github.com/kvrhdn/go-tfe-run/pull/19 it will just skip trying to output complex types. Only primitive types will be output