hashicorp / terraform-plugin-testing

Module for testing Terraform providers
Mozilla Public License 2.0
44 stars 11 forks source link

Document debugging of acceptance tests #353

Open azrdev opened 1 week ago

azrdev commented 1 week ago

Does this documentation exist?

Where would you expect to find this documentation?

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 commented 1 week ago

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)