This content originally appeared on DEV Community and was authored by drewmullen
To setup debugging while writing to the AWS Terraform Provider, create a .vscode
dir in the root of your clone terraform-provider-aws
local repo then create a launch.json
& private.env
inside that .vscode
directory.
Notice you will have to update PKG_NAME
to the specific service you're developing to. Bonus points to anyone who can figure out a smoother way to set that dynamically based on the location of your test file.
Setup
$ git clone git@github.com:hashicorp/terraform-provider-aws.git
$ mkdir terraform-provider-aws/.vscode
Create launch.json
$ cat << 'EOF' > terraform-provider-aws/.vscode/launch.json
{
// 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 a test function",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"args": [
"-test.v",
"-test.run",
"^${selectedText}$"
],
"showLog": true,
"envFile": "${workspaceFolder}/.vscode/private.env"
}
]
}
EOF
Create private.env
$ cat << 'EOF' > terraform-provider-aws/.vscode/private.env
TF_ACC=1
TF_LOG=INFO
GOFLAGS='-mod=readonly'
PKG_NAME='internal/service/ec2'
EOF
Usage
Reload VSCode and source a profile for terraform's acc tests to use. You can do this by either opening vscode from a terminal with a profile set or by using the AWS Toolkit.
Set break-points in your <resource_name>.go
file, highlight the test you want to run and click the green "play" button in VSCode debug panel.
Enjoy!
This content originally appeared on DEV Community and was authored by drewmullen
drewmullen | Sciencx (2021-11-12T19:43:52+00:00) VSCode + Terraform Provider Development: Setup Debugging. Retrieved from https://www.scien.cx/2021/11/12/vscode-terraform-provider-development-setup-debugging/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.