Skip to content

Commit 56e4f77

Browse files
committed
Add debug mode on provider
1 parent 5841472 commit 56e4f77

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ We fork this project for the following items:
1515

1616
## Installation
1717

18-
[Download a binary](https://github.com/phillbaker/terraform-provider-elasticsearch/releases), and put it in a good spot on your system. Then update your `~/.terraformrc` to refer to the binary:
18+
[Download a binary](https://github.com/disaster37/terraform-provider-elasticsearch/releases), and put it in a good spot on your system. Then update your `~/.terraformrc` to refer to the binary:
1919

2020
```hcl
2121
providers {
@@ -50,6 +50,7 @@ provider "elasticsearch" {
5050
- **cacert_file**: (optional) The CA contend to use if you use custom PKI.
5151
- **retry**: (optional) The number of time you should to retry connexion befaore exist with error. Default to `6`.
5252
- **wait_before_retry**: (optional) The number of time in second we wait before each connexion retry. Default to `10`.
53+
- **debug**: (optional) To display debug logs
5354

5455
___
5556

es/provider.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ func Provider() terraform.ResourceProvider {
6666
Default: 10,
6767
Description: "Wait time in second before retry connexion",
6868
},
69+
"debug": {
70+
Type: schema.TypeBool,
71+
Optional: true,
72+
Default: false,
73+
Description: "Enable debug log level in provider",
74+
},
6975
},
7076

7177
ResourcesMap: map[string]*schema.Resource{
@@ -100,6 +106,11 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
100106
transport := &http.Transport{
101107
TLSClientConfig: &tls.Config{},
102108
}
109+
debug := d.Get("debug").(bool)
110+
111+
if debug {
112+
log.SetLevel(log.DebugLevel)
113+
}
103114
// Checks is valid URLs
104115
for _, rawURL := range URLs {
105116
_, err := url.Parse(rawURL)
@@ -143,11 +154,14 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
143154
)
144155
if err == nil && res.IsError() == false {
145156
isOnline = true
157+
log.Debug("Connexion ok")
146158
} else {
147159
if nbFailed == retry {
160+
log.Debug("Connexion failed, end of retry, we exit")
148161
return nil, err
149162
}
150163
nbFailed++
164+
log.Debug("Connexion failed, retry")
151165
time.Sleep(time.Duration(waitBeforeRetry) * time.Second)
152166
}
153167
}

0 commit comments

Comments
 (0)