Easily Debugging Terraform Provider for Azure in VSCode

So you’re making a change to the provider to add a feature, it’s going great and your ready to test it out…. but then you realize things get a bit ropey… ideally you want a visual debugger to step through the code.

Well here is how to set that up in VSCode.

First make sure you have VSCode setup for golang debugging (delve configured etc). Then it’s easy, say you want to debug a new provider you’ve written and it has a test called TestAccDataSourceAzureRMFunction_basic in the file data_source_function_test.go then you can setup your launch.json file in VSCode to look like:

(Makes sure you replace the details in the private.env with your service principal and subscription details)


{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceRoot}/azurerm/data_source_function_test.go",
"args": [
"-test.v",
"-test.run",
"TestAccDataSourceAzureRMFunction_basic"
],
"envFile": "${workspaceRoot}/.vscode/private.env",
"showLog": true
},
]
}

view raw

launch.json

hosted with ❤ by GitHub


GOFLAGS='-mod=vendor'
ARM_CLIENT_ID=00000000-0000-0000-0000-000000000000
ARM_CLIENT_SECRET=00000000-0000-0000-0000-000000000000
ARM_SUBSCRIPTION_ID=00000000-0000-0000-0000-000000000000
ARM_TENANT_ID=00000000-0000-0000-0000-000000000000
ARM_TEST_LOCATION=northeurope
ARM_TEST_LOCATION_ALT=westeurope
TF_ACC=1
TF_LOG=DEBUG

view raw

private.env

hosted with ❤ by GitHub

 

By:

Posted in:


Leave a comment

Blog at WordPress.com.