gruntwork-io / terratest

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
https://terratest.gruntwork.io/
Apache License 2.0
7.46k stars 1.32k forks source link

JSON Parsing Error in Terratest v0.47.1: Invalid character in boolean value #1442

Open AyoubIssaad opened 1 week ago

AyoubIssaad commented 1 week ago

Describe the bug After upgrading to Terratest v0.47.1, we're encountering a JSON parsing error when trying to get output using the OutputForKeys function. This error does not occur with previous versions of Terratest. The error suggests an issue with parsing boolean values in the JSON output from Terragrunt.

To Reproduce

  1. Use Terratest v0.47.1
  2. Run tests that use OutputForKeys to parse Terragrunt output
  3. Observe the JSON parsing error
// This is the code that cause the issue
terraformOptions := &terraform.Options{
        TerraformDir:    config.TerraformDir,
        TerraformBinary: "terragrunt",
        Logger:          logger.Discard,
    }

outputMap := terraform.OutputForKeys(t, terraformOptions, []string{"virtual_machine_resource_group_name", "virtual_machine_name"})

This is the error that we get:

TestAzureXXX 2024-09-03T14:47:54Z retry.go:91: terragrunt [output -no-color -json virtual_machine_resource_group_name --terragrunt-non-interactive]
    output.go:19: 
            Error Trace:    /go/pkg/mod/github.com/gruntwork-io/terratest@v0.47.1/modules/terraform/output.go:19
                                        /runner/_work/qa-azure/qa-azure/terratest/test-templates/vm_unit_test_template.go:43
                                        /runner/_work/qa-azure/qa-azure/terratest/packages/triggers/unit.go:63
                                        /runner/_work/qa-azure/qa-azure/terratest/unit-tests/redhat8_base_unit_test.go:9
            Error:          Received unexpected error:
                            invalid character 'i' in literal true (expecting 'r')
            Test:           TestAzureredhat8baseVm

Expected behavior Terratest should successfully parse the JSON output from Terragrunt without errors, allowing the test to proceed with the parsed output.

Versions

tgeijg commented 1 week ago

Seeing the same with just Output. actualArn := terraform.Output(t, terraformOptions, "arn") gives the same error on 0.47.1, but not 0.47.0.