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.52k stars 1.33k forks source link

[terraform/output] invalid character 'm' after array element #1453

Open ryehowell opened 1 month ago

ryehowell commented 1 month ago

Describe the bug When calling the OutputRequired function in the terraform/output module, I am getting an Error: Received unexpected error: invalid character 'm' after array element.

This error looks to have been reported in this Issue, but continues to persist.

To Reproduce Run the following internal test Offending line

Result:

--- FAIL: TestIntegrationDestroy (537.03s)
    output.go:36: 
            Error Trace:    /Users/me/go/pkg/mod/github.com/gruntwork-io/terratest@v0.47.2/modules/terraform/output.go:36
                                        /Users/me/src/github.com/gruntwork/terraform-aws-ci/test/destroy_test.go:240
                                        /Users/me/go/pkg/mod/github.com/gruntwork-io/terratest@v0.47.2/modules/test-structure/test_structure.go:30
                                        /Users/me/src/github.com/gruntwork/terraform-aws-ci/test/destroy_test.go:207
            Error:          Received unexpected error:
                            invalid character 'm' after array element
            Test:           TestIntegrationDestroy
FAIL

Expected behavior A clear and concise description of what you expected to happen.

Nice to have

Versions

Additional context

When debugging locally


// line 299 of output.go
OutputStructE(out)
// input value of out as input to function cleanOutput(out)
out = "\x1b[90m09:06:11.281 \x1b[0m\x1b[32mINFO   \x1b[0mDownloading Terraform configurations from ../../../../fixtures/null_resource_module into ./.terragrunt-cache/db4UlyBp-l9tLecIJQhY4ihzvZo/WTtZRBNSmdc6CoLXtNhzYg9-r0Q\n\x1b[90m09:06:11.311 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mInitializing the backend...\n\x1b[90m09:06:11.318 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mSuccessfully configured the backend \"local\"! Terraform will automatically\n\x1b[90m09:06:11.318 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0muse this backend unless the backend configuration changes.\n\x1b[90m09:06:11.318 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mInitializing provider plugins...\n\x1b[90m09:06:11.318 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0m- Finding hashicorp/aws versions matching \"< 4.0.0\"...\n\x1b[90m09:06:11.641 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0m- Finding latest version of hashicorp/null...\n\x1b[90m09:06:12.074 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0m- Installing hashicorp/null v3.2.3...\n\x1b[90m09:06:12.429 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0m- Installed hashicorp/null v3.2.3 (signed by HashiCorp)\n\x1b[90m09:06:12.610 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0m- Installing hashicorp/aws v3.76.1...\n\x1b[90m09:06:14.625 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0m- Installed hashicorp/aws v3.76.1 (signed by HashiCorp)\n\x1b[90m09:06:14.625 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mTerraform has created a lock file .terraform.lock.hcl to record the provider\n\x1b[90m09:06:14.625 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mselections it made above. Include this file in your version control repository\n\x1b[90m09:06:14.625 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mso that Terraform can guarantee to make the same selections by default when\n\x1b[90m09:06:14.625 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0myou run \"terraform init\" in the future.\n\x1b[90m09:06:14.625 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mTerraform has been successfully initialized!\n\x1b[90m09:06:14.626 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mYou may now begin working with Terraform. Try running \"terraform plan\" to see\n\x1b[90m09:06:14.626 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0many changes that are required for your infrastructure. All Terraform commands\n\x1b[90m09:06:14.626 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mshould now work.\n\x1b[90m09:06:14.626 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mIf you ever set or change modules or backend configuration for Terraform,\n\x1b[90m09:06:14.626 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mrerun this command to reinitialize your working directory. If you forget, other\n\x1b[90m09:06:14.626 \x1b[0m\x1b[37mSTDOUT \x1b[0m\x1b[36mterraform: \x1b[0mcommands will detect it and remind you to do so if necessary.\n\"3919159218922798988\"\n\x1b[90m09:06:14.815 \x1b[0m\x1b[32mINFO   \x1b[0mRetrieved output from terraform"

//return value of out after running from cleanOutput(out)
out = "[90m09:06:11.311 [0m[37mSTDOUT [0m[36mterraform: [0mInitializing the backend...[90m09:06:11.318 [0m[37mSTDOUT [0m[36mterraform: [0mSuccessfully configured the backend \"local\"! Terraform will automatically[90m09:06:11.318 [0m[37mSTDOUT [0m[36mterraform: [0muse this backend unless the backend configuration changes.[90m09:06:11.318 [0m[37mSTDOUT [0m[36mterraform: [0mInitializing provider plugins...[90m09:06:11.318 [0m[37mSTDOUT [0m[36mterraform: [0m- Finding hashicorp/aws versions matching \"< 4.0.0\"...[90m09:06:11.641 [0m[37mSTDOUT [0m[36mterraform: [0m- Finding latest version of hashicorp/null...[90m09:06:12.074 [0m[37mSTDOUT [0m[36mterraform: [0m- Installing hashicorp/null v3.2.3...[90m09:06:12.429 [0m[37mSTDOUT [0m[36mterraform: [0m- Installed hashicorp/null v3.2.3 (signed by HashiCorp)[90m09:06:12.610 [0m[37mSTDOUT [0m[36mterraform: [0m- Installing hashicorp/aws v3.76.1...[90m09:06:14.625 [0m[37mSTDOUT [0m[36mterraform: [0m- Installed hashicorp/aws v3.76.1 (signed by HashiCorp)[90m09:06:14.625 [0m[37mSTDOUT [0m[36mterraform: [0mTerraform has created a lock file .terraform.lock.hcl to record the provider[90m09:06:14.625 [0m[37mSTDOUT [0m[36mterraform: [0mselections it made above. Include this file in your version control repository[90m09:06:14.625 [0m[37mSTDOUT [0m[36mterraform: [0mso that Terraform can guarantee to make the same selections by default when[90m09:06:14.625 [0m[37mSTDOUT [0m[36mterraform: [0myou run \"terraform init\" in the future.[90m09:06:14.625 [0m[37mSTDOUT [0m[36mterraform: [0mTerraform has been successfully initialized![90m09:06:14.626 [0m[37mSTDOUT [0m[36mterraform: [0mYou may now begin working with Terraform. Try running \"terraform plan\" to see[90m09:06:14.626 [0m[37mSTDOUT [0m[36mterraform: [0many changes that are required for your infrastructure. All Terraform commands[90m09:06:14.626 [0m[37mSTDOUT [0m[36mterraform: [0mshould now work.[90m09:06:14.626 [0m[37mSTDOUT [0m[36mterraform: [0mIf you ever set or change modules or backend configuration for Terraform,[90m09:06:14.626 [0m[37mSTDOUT [0m[36mterraform: [0mrerun this command to reinitialize your working directory. If you forget, other[90m09:06:14.626 [0m[37mSTDOUT [0m[36mterraform: [0mcommands will detect it and remind you to do so if necessary.\"3919159218922798988\""

// fails on error thrown from this line
return json.Unmarshal([]byte(out), &v)
AyoubIssaad commented 1 month ago

I can confirm that the issue that I reported HERE still persists even after the fix. I'm still getting the same error image

wakeful commented 1 month ago

Hey,

What version of Terraform are you using?

AyoubIssaad commented 1 month ago

What version of Terraform are you using ?

In my case, I tested with Terraform 1.9.3 and 1.9.5

wakeful commented 1 month ago

What version of Terraform are you using ?

In my case, I tested with Terraform 1.9.3 and 1.9.5

Do you have some sort of alias or wrapper around the Terraform binary? I'm struggling to reproduce this issue. Is there a chance you could share an example of the output that is failing for you?

To be honest, it seems like the Terraform binary is not receiving the -no-color parameter, as the JSON decode fails on the ANSI escape sequences. However, Terratest is passing that argument here.

AyoubIssaad commented 1 month ago

Do you have some sort of alias or wrapper around the Terraform binary?

You are absolutely right, because I forgot to mention that in my case I'm using Terragrunt (v0.64.4) as a wrapper, Not sure if @ryehowell is using a wrapper as well or not.

I don't have access to my laptop now, but will try to share an example later if still needed.

ryehowell commented 1 month ago

What version of Terraform are you using ?

In my case, I tested with Terraform 1.9.3 and 1.9.5

Do you have some sort of alias or wrapper around the Terraform binary? I'm struggling to reproduce this issue. Is there a chance you could share an example of the output that is failing for you?

To be honest, it seems like the Terraform binary is not receiving the -no-color parameter, as the JSON decode fails on the ANSI escape sequences. However, Terratest is passing that argument here.

Yes, terragrunt is being used with the test execution.

wakeful commented 1 month ago

What version of Terraform are you using ?

In my case, I tested with Terraform 1.9.3 and 1.9.5

Do you have some sort of alias or wrapper around the Terraform binary? I'm struggling to reproduce this issue. Is there a chance you could share an example of the output that is failing for you? To be honest, it seems like the Terraform binary is not receiving the -no-color parameter, as the JSON decode fails on the ANSI escape sequences. However, Terratest is passing that argument here.

Yes, terragrunt is being used with the test execution.

You don’t have any custom alias in your shell for Terragrunt, right?

Can you confirm that when you are running the output, the Terraform binary is set to Terragrunt?

I have quite a few tests using outputs and cannot reproduce your issue. Is there a chance you could share the HCL output file (with mocked data) and the test showing how you are using the code?