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

Document debugging of acceptance tests #353

Closed
3 of 6 tasks
azrdev opened this issue Jun 19, 2024 · 2 comments
Closed
3 of 6 tasks

Document debugging of acceptance tests #353

azrdev opened this issue Jun 19, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@azrdev
Copy link

azrdev commented Jun 19, 2024

Does this documentation exist?

  • This is new documentation
  • This is an enhancement to existing documentation

Where would you expect to find this documentation?

  • On terraform.io
  • In the GoDoc for this module
  • In this repo as a markdown file
  • Somewhere else

Details

https://developer.hashicorp.com/terraform/plugin/framework/acctests describes how to write and run (TF_ACC=1) acceptance tests for terraform providers using the plugin framework.

https://developer.hashicorp.com/terraform/plugin/framework/debugging and https://developer.hashicorp.com/terraform/plugin/debugging#starting-a-provider-in-debug-mode describe how to start a provider server in a debugger (e.g. delve), and export its address using TF_REATTACH_PROVIDERS to any terraform commands run afterwards, enabling debugger support for the provider code.

I cannot find how to do both: run an acceptance test with TF_ACC=1 TF_DEBUG=INFO go test -v -run MyResourceCRUD . and get debugger support (e.g. breakpoints) in the provider code.

Extras

With TF_LOG=TRACE I can see multiple debug statements "Setting Terraform CLI reattach configuration", but apparently these are triggered by the provider instantiantion by the acceptance test driver (e.g. with ProtoV6ProviderFactories somewhere in the call stack), and I see no option to override.

Description

References

@azrdev azrdev added the documentation Improvements or additions to documentation label Jun 19, 2024
@azrdev
Copy link
Author

azrdev commented Jun 20, 2024

Apparently debugging just works™ running the test methods from within vscode, given the launch.json from here https://hashicorp.github.io/terraform-provider-aws/debugging/#use-visual-studio-code-debugging

Not sure what went wrong when first trying it.

Caveat: env and envFile seem to be ignored in my case (vscode on windows, running/debugging in WSL2), had to set my auth environment variables via .vscode/settings.json (go.testEnvFile)

@austinvalle
Copy link
Member

Hey @azrdev 👋🏻, looks like you resolved your issue so I'm going to close this out.

I think what's out there should be sufficient, although if you have specific doc suggestions feel free to point them out. Any way that you get the TF_ACC environment variable populated in your test runner should work fine. Personally, I use VSCode and have my global user settings with go.testEnvVars like:

{
  // .. settings.json
  "go.testEnvVars": {
    "TF_ACC_TERRAFORM_PATH": "/Users/austin.valle/go/bin/terraform",
    "TF_LOG": "TRACE",
    "TF_ACC": "1",
  }
}

Although, most provider test debugging I'm doing is with providers that don't need credentials, so go.testEnvFile is also appropriate. I'd imagine using a project/workspace settings.json would lean towards using an env file, where you could define more "global" env variables in your user settings.json.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants