Skip to content

Commit 01f54a7

Browse files
authored
Merge pull request #348 from SourceFellows/master
Added the ability to debug the plugin through the Terraform Plugin SDK.
2 parents 7d3e5b9 + 43f7015 commit 01f54a7

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ This section is here to both serve as a reminder to contributers of areas for im
2727

2828
When contributing, please also add documentation to help other users.
2929

30+
### Debugging the provider
31+
32+
Debugging is available for this provider through the Terraform Plugin SDK versions 2.0.0. Therefore the plugin can be
33+
started with the debugging flag `--debug`.
34+
35+
For example (using [delve](https://github.com/go-delve/delve) as Debugger):
36+
```bash
37+
dlv exec --headless ./terraform-provider-my-provider -- --debug
38+
```
39+
40+
For more information about debugging a provider please see: [Debugger-Based Debugging](https://www.terraform.io/docs/extend/debugging.html#debugger-based-debugging)
41+
3042
## Useful links
3143

3244
* [Proxmox](https://www.proxmox.com/en/)

main.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
package main
22

33
import (
4+
"context"
5+
"flag"
46
"github.com/Telmate/terraform-provider-proxmox/proxmox"
57
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
68
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
9+
"log"
710
)
811

912
func main() {
10-
plugin.Serve(&plugin.ServeOpts{
13+
14+
var debugMode bool
15+
16+
flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve")
17+
flag.Parse()
18+
19+
opts := &plugin.ServeOpts{
1120
ProviderFunc: func() *schema.Provider {
1221
return proxmox.Provider()
1322
},
14-
})
23+
}
24+
25+
if debugMode {
26+
err := plugin.Debug(context.Background(), "registry.terraform.io/telmate/proxmox", opts)
27+
if err != nil {
28+
log.Fatal(err.Error())
29+
}
30+
return
31+
}
32+
33+
plugin.Serve(opts)
1534
}

proxmox/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"os"
77
"regexp"
88
"strconv"
9-
"sync"
109
"strings"
10+
"sync"
1111

1212
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -213,7 +213,7 @@ func getClient(pm_api_url string, pm_user string, pm_password string, pm_api_tok
213213
// API authentication
214214
if pm_api_token_id != "" && pm_api_token_secret != "" {
215215
// Unsure how to get an err for this
216-
client.SetAPIToken( pm_api_token_id, pm_api_token_secret)
216+
client.SetAPIToken(pm_api_token_id, pm_api_token_secret)
217217
}
218218

219219
if err != nil {

proxmox/resource_vm_qemu.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ func resourceVmQemu() *schema.Resource {
211211
Type: schema.TypeString,
212212
Optional: true,
213213
},
214-
"args": {
215-
Type: schema.TypeString,
216-
Optional: true,
217-
},
214+
"args": {
215+
Type: schema.TypeString,
216+
Optional: true,
217+
},
218218
"memory": {
219219
Type: schema.TypeInt,
220220
Optional: true,

0 commit comments

Comments
 (0)