VSCode + Terraform Provider Development: Setup Debugging

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 …


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » VSCode + Terraform Provider Development: Setup Debugging." drewmullen | Sciencx - Friday November 12, 2021, https://www.scien.cx/2021/11/12/vscode-terraform-provider-development-setup-debugging/
HARVARD
drewmullen | Sciencx Friday November 12, 2021 » VSCode + Terraform Provider Development: Setup Debugging., viewed ,<https://www.scien.cx/2021/11/12/vscode-terraform-provider-development-setup-debugging/>
VANCOUVER
drewmullen | Sciencx - » VSCode + Terraform Provider Development: Setup Debugging. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/12/vscode-terraform-provider-development-setup-debugging/
CHICAGO
" » VSCode + Terraform Provider Development: Setup Debugging." drewmullen | Sciencx - Accessed . https://www.scien.cx/2021/11/12/vscode-terraform-provider-development-setup-debugging/
IEEE
" » VSCode + Terraform Provider Development: Setup Debugging." drewmullen | Sciencx [Online]. Available: https://www.scien.cx/2021/11/12/vscode-terraform-provider-development-setup-debugging/. [Accessed: ]
rf:citation
» VSCode + Terraform Provider Development: Setup Debugging | drewmullen | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.