Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
ryehowell opened this issue Oct 2, 2024 · 7 comments · May be fixed by #1462
Open
2 tasks

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

ryehowell opened this issue Oct 2, 2024 · 7 comments · May be fixed by #1462
Assignees
Labels
bug Something isn't working terratest

Comments

@ryehowell
Copy link
Contributor

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/[email protected]/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/[email protected]/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

  • Terminal output
  • Screenshots

Versions

  • Terratest version:
  • Environment details (Ubuntu 20.04, Windows 10, etc.):

Additional context

  • terratest versions v0.47.1 and v0.47.2
  • MacOS 14.2.1 (23C71)

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)
@ryehowell ryehowell added the bug Something isn't working label Oct 2, 2024
@AyoubIssaad
Copy link

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
Copy link
Contributor

wakeful commented Oct 9, 2024

Hey,

What version of Terraform are you using?

@AyoubIssaad
Copy link

AyoubIssaad commented Oct 10, 2024

What version of Terraform are you using ?

In my case, I tested with Terraform 1.9.3 and 1.9.5

@wakeful
Copy link
Contributor

wakeful commented Oct 10, 2024

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
Copy link

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
Copy link
Contributor Author

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
Copy link
Contributor

wakeful commented Oct 14, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working terratest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants