« Back to Index

Terraform: Debugging with Delve

View original Gist on GitHub

Tags: #terraform #debug #delve

Terraform Debugging with Delve.md

https://developer.hashicorp.com/terraform/plugin/debugging#debugger-based-debugging

(first shell)  dlv debug . --headless -- --debug
(second shell) dlv connect <output from first shell>
               continue
               <Ctrl-c>
               break path/to/file.go:123
(third shell)  export TF_REATTACH_PROVIDERS="..."
               terraform apply
(second shell) continue (do your step debugging)
               <Ctrl-c> (then run another terraform command from third shell)

You can also debug tests (example below is for github.com/fastly/terraform-provider-fastly)…

cd ./fastly
TF_ACC=true dlv test -- -test.v -test.run TestAccFastlyServiceVCL_syslog_useTLS
break block_fastly_service_logging_syslog_test.go:253 // break inside the test code
break block_fastly_service_logging_syslog.go:342      // break inside the execute terraform code (trigged by the test)