in cloudstack/provider.go [140:186]
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
apiURL, apiURLOK := d.GetOk("api_url")
apiKey, apiKeyOK := d.GetOk("api_key")
secretKey, secretKeyOK := d.GetOk("secret_key")
config, configOK := d.GetOk("config")
profile, profileOK := d.GetOk("profile")
switch {
case apiURLOK, apiKeyOK, secretKeyOK:
if !(apiURLOK && apiKeyOK && secretKeyOK) {
return nil, errors.New("'api_url', 'api_key' and 'secret_key' should all have values")
}
case configOK, profileOK:
if !(configOK && profileOK) {
return nil, errors.New("'config' and 'profile' should both have a value")
}
default:
return nil, errors.New(
"either 'api_url', 'api_key' and 'secret_key' or 'config' and 'profile' should have values")
}
if configOK && profileOK {
cfg, err := ini.Load(config.(string))
if err != nil {
return nil, err
}
section, err := cfg.GetSection(profile.(string))
if err != nil {
return nil, err
}
apiURL = section.Key("url").String()
apiKey = section.Key("apikey").String()
secretKey = section.Key("secretkey").String()
}
cfg := Config{
APIURL: apiURL.(string),
APIKey: apiKey.(string),
SecretKey: secretKey.(string),
HTTPGETOnly: d.Get("http_get_only").(bool),
Timeout: int64(d.Get("timeout").(int)),
}
return cfg.NewClient()
}