Skip to content

Commit 7b16c44

Browse files
author
Sander van Harmelen
committed
provider/cloudstack: make timeout configurable
Seems some platforms need more time, so make it configurable with a sane default…
1 parent e9b3e57 commit 7b16c44

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

builtin/providers/cloudstack/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ type Config struct {
88
ApiURL string
99
ApiKey string
1010
SecretKey string
11+
Timeout int64
1112
}
1213

1314
// Client() returns a new CloudStack client.
1415
func (c *Config) NewClient() (*cloudstack.CloudStackClient, error) {
1516
cs := cloudstack.NewAsyncClient(c.ApiURL, c.ApiKey, c.SecretKey, false)
16-
cs.AsyncTimeout(180)
17+
cs.AsyncTimeout(c.Timeout)
1718
return cs, nil
1819
}

builtin/providers/cloudstack/provider.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@ func Provider() terraform.ResourceProvider {
1414
"api_url": &schema.Schema{
1515
Type: schema.TypeString,
1616
Required: true,
17-
DefaultFunc: envDefaultFunc("CLOUDSTACK_API_URL"),
17+
DefaultFunc: envDefaultFunc("CLOUDSTACK_API_URL", nil),
1818
},
1919

2020
"api_key": &schema.Schema{
2121
Type: schema.TypeString,
2222
Required: true,
23-
DefaultFunc: envDefaultFunc("CLOUDSTACK_API_KEY"),
23+
DefaultFunc: envDefaultFunc("CLOUDSTACK_API_KEY", nil),
2424
},
2525

2626
"secret_key": &schema.Schema{
2727
Type: schema.TypeString,
2828
Required: true,
29-
DefaultFunc: envDefaultFunc("CLOUDSTACK_SECRET_KEY"),
29+
DefaultFunc: envDefaultFunc("CLOUDSTACK_SECRET_KEY", nil),
30+
},
31+
32+
"timeout": &schema.Schema{
33+
Type: schema.TypeInt,
34+
Required: true,
35+
DefaultFunc: envDefaultFunc("CLOUDSTACK_TIMEOUT", 180),
3036
},
3137
},
3238

@@ -52,17 +58,18 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
5258
ApiURL: d.Get("api_url").(string),
5359
ApiKey: d.Get("api_key").(string),
5460
SecretKey: d.Get("secret_key").(string),
61+
Timeout: d.Get("timeout").(int64),
5562
}
5663

5764
return config.NewClient()
5865
}
5966

60-
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
67+
func envDefaultFunc(k string, dv interface{}) schema.SchemaDefaultFunc {
6168
return func() (interface{}, error) {
6269
if v := os.Getenv(k); v != "" {
6370
return v, nil
6471
}
6572

66-
return nil, nil
73+
return dv, nil
6774
}
6875
}

0 commit comments

Comments
 (0)