terratest
terratest copied to clipboard
output function returns List as String, and GH Actions returns JSON encoding error
This is neither a Terratest specific bug report nor feature request, but rather some discovered information that may or may not be helpful for behavior observed from the output
function in the terraform
package within terratest
.
I have a simple TF outputs acceptance test for my module:
invFilesOutput := terraform.Output(test, terraformOptions, "inventory_files")
assert.Equal(test, "[./inventory.ini ./inventory.json ./inventory.yaml]", invFilesOutput)
and this returns a JSON encoding error when executed in GH actions (I have a different suite of tests in Circle CI, so I am unsure if the CI platform impacts this at all, but I feel like it should not):
TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z retry.go:91: terraform [output -no-color -json inventory_files] TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: Running command terraform with args [output -no-color -json inventory_files] formLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: [command]/home/runner/work/_temp/495ccae4-f85c-42fd-aef3-c8bd2b8b9d6e/terraform-bin output -no-color -json inventory_files TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ["./inventory.ini","./inventory.json","./inventory.yaml"] TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ::debug::Terraform exited with code 0. TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ::debug::stdout: ["./inventory.ini","./inventory.json","./inventory.yaml"]%0A TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ::debug::stderr: TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ::debug::exitcode: 0 TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ::set-output name=stdout::["./inventory.ini","./inventory.json","./inventory.yaml"]%0A TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ::set-output name=stderr:: TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: TestTerraformLocalAnsibleInv 2022-07-22T16:09:27Z logger.go:66: ::set-output name=exitcode::0 output.go:19: Error Trace: output.go:19 main_test.go:25 Error: Received unexpected error: invalid character 'c' looking for beginning of value Test: TestTerraformLocalAnsibleInv
Already you are probably thinking "but this is a list
type, so it should be OutputList
". That is totally correct, so I update the code accordingly:
invFilesOutput := terraform.OutputList(test, terraformOptions, "inventory_files")
assert.Equal(test, []string{"./inventory.ini", "./inventory.json", "./inventory.yaml"}, invFilesOutput)
This is where things go weird. That test also fails in GH actions with a JSON encoding error, and both tests pass on my local device. The only real difference I can observe between the two environments is that my local device has Go 1.18.1, and GH Actions is using 1.18.5.
I do not feel that Terratest has a bug here, but I think it is odd that GH Actions has some incompatibility such that there is a JSON encoding error for the Output
functions, and maybe also odd that the Output
function actually processes non-primitive types in a feasible manner.
I am curious about thoughts on these unusual observations.
We had the same issue. Are you using the official action to install terraform? If so, you need to disable the wrapper:
steps:
- uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
This solved it for us.