This message was deleted.
# contributors
b
This message was deleted.
m
hey @numerous-waitress-42427 👋
I don’t personally use vscode, so I can’t help here. Paging @little-author-61621 - I know you use vscode. Alternatively you can use a free EAP version of goland, which has excellent debugging support out the box.
n
Thanks a lot @mysterious-teacher-68276 but as I am always coding with vscode for terraform stuff I will wait for @little-author-61621 tips if possible
👍 1
l
I don’t have any good tips tbh, since I don’t use much of the VSCode debugging stuff
It’s something I’ve been meaning to experiment with, so if you find anything useful I’d be interested
m
@numerous-waitress-42427 I’ll have a go at helping you, though I don’t know if this will work, but after reading the vscode spec it seems that you want something like:
Copy code
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "go",
      "request": "launch",
      "name": "Debug Infracost",
      "program": "${workspaceFolder}/cmd/infracost/main.go",
      "args": [
        "breakdown",
        "--path",
        "/path/to/plan.json"
      ]
    }
  ]
}
to debug the main cli application
🙏 1
you can get valid args from
infracost breakdown --help
if you’re looking to debug your golden file unit test, something like this should work:
Copy code
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch sql managed instance test",
      "type": "go",
      "request": "launch",
      "mode": "test",
      "program": "${workspaceFolder}",
      "args": [
        "-test.run",
        "TestSqlManagedInstanceGoldenFile"
      ]
    }
  ]
}
let me know if any of these work for you
n
just testing that right now ... I let you know
ok it fail with that
Copy code
--- FAIL: TestSqlManagedInstanceGoldenFile (0.00s)
    --- FAIL: TestSqlManagedInstanceGoldenFile/HCL (0.00s)
        tftest.go:203: 
            	Error Trace:	tftest.go:231
            	            				tftest.go:203
            	Error:      	Received unexpected error:
            	            	open testdata/sql_managed_instance_test/sql_managed_instance_test.tf: no such file or directory
            	Test:       	TestSqlManagedInstanceGoldenFile/HCL
    --- FAIL: TestSqlManagedInstanceGoldenFile/Terraform_CLI (0.00s)
        tftest.go:207: 
            	Error Trace:	tftest.go:231
            	            				tftest.go:207
            	Error:      	Received unexpected error:
            	            	open testdata/sql_managed_instance_test/sql_managed_instance_test.tf: no such file or directory
            	Test:       	TestSqlManagedInstanceGoldenFile/Terraform_CLI
FAIL
I try to add "cwd": "/workspace/infracost/internal/providers/terraform/" in my launch.json but It seems not to find the file of the tf data
m
could you post the cmd that vscode is trying to run
this might help me debug
n
Copy code
{
    // 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 Package",
            "type": "go",
            "request": "launch",
            "mode": "test",
            "args": [
                "-test.run",
                "TestSqlManagedInstanceGoldenFile"
            ],
            "env": {
                "CGO_ENABLED": "0",
                "GOPATH": "/go"
            },
            "showLog": true,
            "logOutput": "dap",
            "program": "/workspace/infracost/internal/providers/terraform/azure",
            "cwd": "/workspace/infracost/internal/providers/terraform/"
        }
    ]
}
by the way I developed in a container
l
Yeah that’s odd because running this on your branch works okay for me:
Copy code
go test -timeout 60s -run ^TestSqlManagedInstanceGoldenFile$ <http://github.com/infracost/infracost/internal/providers/terraform/azure|github.com/infracost/infracost/internal/providers/terraform/azure> -v
n
that probably why I had to add the env section
m
@numerous-waitress-42427 I meant posting the line before this:
Copy code
--- FAIL: TestSqlManagedInstanceGoldenFile (0.00s)
    --- FAIL: TestSqlManagedInstanceGoldenFile/HCL (0.00s)
        tftest.go:203: 
            	Error Trace:	tftest.go:231
            	            				tftest.go:203
            	Error:      	Received unexpected error:
            	            	open testdata/sql_managed_instance_test/sql_managed_instance_test.tf: no such
so the actual go cmd that vscode tries to run
it should appear similar to the one @little-author-61621 posted
n
Copy code
2022-03-14T16:39:16Z error layer=debugger can't find build-id note on binary
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"event","event":"initialized"}
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"launch"}
2022-03-14T16:39:17Z debug layer=dap [<- from client]{"seq":3,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"sql_managed_instance.go","path":"/workspace/infracost/internal/resources/azure/sql_managed_instance.go"},"breakpoints":[{"line":124}],"lines":[124]}}
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":true,"source":{"name":"sql_managed_instance.go","path":"/workspace/infracost/internal/resources/azure/sql_managed_instance.go"},"line":124}]}}
2022-03-14T16:39:17Z debug layer=dap [<- from client]{"seq":4,"type":"request","command":"setFunctionBreakpoints","arguments":{"breakpoints":[]}}
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":4,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]}}
2022-03-14T16:39:17Z debug layer=dap [<- from client]{"seq":5,"type":"request","command":"setInstructionBreakpoints","arguments":{"breakpoints":[]}}
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":5,"success":true,"command":"setInstructionBreakpoints","body":{"breakpoints":[]}}
2022-03-14T16:39:17Z debug layer=dap [<- from client]{"seq":6,"type":"request","command":"configurationDone","arguments":{}}
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Type 'dlv help' for list of commands.\n","source":{}}}
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":6,"success":true,"command":"configurationDone"}
Type 'dlv help' for list of commands.
2022-03-14T16:39:17Z debug layer=dap [<- from client]{"seq":7,"type":"request","command":"threads"}
2022-03-14T16:39:17Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":7,"success":true,"command":"threads","body":{"threads":[{"id":-1,"name":"Current"}]}}
--- FAIL: TestSqlManagedInstanceGoldenFile (0.00s)
    --- FAIL: TestSqlManagedInstanceGoldenFile/HCL (0.00s)
        tftest.go:203: 
            	Error Trace:	tftest.go:231
            	            				tftest.go:203
            	Error:      	Received unexpected error:
            	            	open testdata/sql_managed_instance_test/sql_managed_instance_test.tf: no such file or directory
            	Test:       	TestSqlManagedInstanceGoldenFile/HCL
    --- FAIL: TestSqlManagedInstanceGoldenFile/Terraform_CLI (0.00s)
        tftest.go:207: 
            	Error Trace:	tftest.go:231
            	            				tftest.go:207
            	Error:      	Received unexpected error:
            	            	open testdata/sql_managed_instance_test/sql_managed_instance_test.tf: no such file or directory
            	Test:       	TestSqlManagedInstanceGoldenFile/Terraform_CLI
FAIL
2022-03-14T16:39:31Z debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}}
2022-03-14T16:39:31Z debug layer=dap [<- from client]{"seq":8,"type":"request","command":"disconnect","arguments":{}}
2022-03-14T16:39:31Z debug layer=dap halting
2022-03-14T16:39:31Z debug layer=dap process not running
2022-03-14T16:39:31Z debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Process 11461 has exited with status 1\n","source":{}}}
2022-03-14T16:39:31Z debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Detaching\n","source":{}}}
2022-03-14T16:39:31Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":8,"success":true,"command":"disconnect"}
2022-03-14T16:39:31Z debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}}
2022-03-14T16:39:31Z debug layer=dap DAP server stopping...
Process 11461 has exited with status 1
Detaching
2022-03-14T16:39:31Z debug layer=dap DAP server stopped
dlv dap (11304) exited with code: 0
here is the message I had
the command from @little-author-61621 works well
I will investigate and let you know
boum done
🎉 1
🙌 1
1
m
what was it
n
{ // 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 Package", "type": "go", "request": "launch", "mode": "test", "args": [ "-test.run", "^TestSqlManagedInstanceGoldenFile$" ], "env": { "CGO_ENABLED": "0", "GOPATH": "/go" }, "showLog": true, "logOutput": "dap", "program": "/workspace/infracost/internal/providers/terraform/azure", "cwd": "/workspace/infracost/internal/providers/terraform/azure" } ] }
As I work in a dev container I need to pass the env stuff
👍 1
m
👍
n
then the log output can be set to true or false depends on what the dev needs 😉
m
FYI you can also configure a file runner like so:
Copy code
{
  "name": "Test Current File",
  "type": "go",
  "request": "launch",
  "mode": "test",
  "program": "${file}",
  "showLog": true
}
which should let you run the current file
so might be easier than having the
program
and
cwd
args - but if you’ve got it working, maybe best just to stick to that for the time being…! 😆
again I don’t use vscode - so this all could be very wrong!
n
yes you are right the parameter cwd can be skipped
1
🦜 1
Thanks a lot it's now a lot better, will used that for checking the comment on my PR and hopefully adding more resources 😉
m
amazeballs
nice work
🤣 1