diff --git a/builtin/providers/cloudstack/config.go b/builtin/providers/cloudstack/config.go index b7c4c7ce1..9185bb27e 100644 --- a/builtin/providers/cloudstack/config.go +++ b/builtin/providers/cloudstack/config.go @@ -8,11 +8,12 @@ type Config struct { ApiURL string ApiKey string SecretKey string + Timeout int64 } // Client() returns a new CloudStack client. func (c *Config) NewClient() (*cloudstack.CloudStackClient, error) { cs := cloudstack.NewAsyncClient(c.ApiURL, c.ApiKey, c.SecretKey, false) - cs.AsyncTimeout(180) + cs.AsyncTimeout(c.Timeout) return cs, nil } diff --git a/builtin/providers/cloudstack/provider.go b/builtin/providers/cloudstack/provider.go index 6440ff2c0..f00f11cb7 100644 --- a/builtin/providers/cloudstack/provider.go +++ b/builtin/providers/cloudstack/provider.go @@ -14,19 +14,25 @@ func Provider() terraform.ResourceProvider { "api_url": &schema.Schema{ Type: schema.TypeString, Required: true, - DefaultFunc: envDefaultFunc("CLOUDSTACK_API_URL"), + DefaultFunc: envDefaultFunc("CLOUDSTACK_API_URL", nil), }, "api_key": &schema.Schema{ Type: schema.TypeString, Required: true, - DefaultFunc: envDefaultFunc("CLOUDSTACK_API_KEY"), + DefaultFunc: envDefaultFunc("CLOUDSTACK_API_KEY", nil), }, "secret_key": &schema.Schema{ Type: schema.TypeString, Required: true, - DefaultFunc: envDefaultFunc("CLOUDSTACK_SECRET_KEY"), + DefaultFunc: envDefaultFunc("CLOUDSTACK_SECRET_KEY", nil), + }, + + "timeout": &schema.Schema{ + Type: schema.TypeInt, + Required: true, + DefaultFunc: envDefaultFunc("CLOUDSTACK_TIMEOUT", 180), }, }, @@ -52,17 +58,18 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { ApiURL: d.Get("api_url").(string), ApiKey: d.Get("api_key").(string), SecretKey: d.Get("secret_key").(string), + Timeout: d.Get("timeout").(int64), } return config.NewClient() } -func envDefaultFunc(k string) schema.SchemaDefaultFunc { +func envDefaultFunc(k string, dv interface{}) schema.SchemaDefaultFunc { return func() (interface{}, error) { if v := os.Getenv(k); v != "" { return v, nil } - return nil, nil + return dv, nil } }