provider/azurerm: Fix panic if no creds supplied
Using EnvDefaultFunc with a default of empty string causes the validation which would ordinarily be performed by `Required: true` in the schema to not have any effect. Instead validate the configuration used to produce the ARM client before attempting to use it during provider configuration.
This commit is contained in:
parent
54202669d2
commit
f8a40ff371
|
@ -7,6 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest"
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/hashicorp/terraform/helper/mutexkv"
|
"github.com/hashicorp/terraform/helper/mutexkv"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
@ -75,6 +76,25 @@ type Config struct {
|
||||||
TenantID string
|
TenantID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Config) validate() error {
|
||||||
|
var err *multierror.Error
|
||||||
|
|
||||||
|
if c.SubscriptionID == "" {
|
||||||
|
err = multierror.Append(err, fmt.Errorf("Subscription ID must be configured for the AzureRM provider"))
|
||||||
|
}
|
||||||
|
if c.ClientID == "" {
|
||||||
|
err = multierror.Append(err, fmt.Errorf("Client ID must be configured for the AzureRM provider"))
|
||||||
|
}
|
||||||
|
if c.ClientSecret == "" {
|
||||||
|
err = multierror.Append(err, fmt.Errorf("Client Secret must be configured for the AzureRM provider"))
|
||||||
|
}
|
||||||
|
if c.TenantID == "" {
|
||||||
|
err = multierror.Append(err, fmt.Errorf("Tenant ID must be configured for the AzureRM provider"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return err.ErrorOrNil()
|
||||||
|
}
|
||||||
|
|
||||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||||
config := Config{
|
config := Config{
|
||||||
SubscriptionID: d.Get("subscription_id").(string),
|
SubscriptionID: d.Get("subscription_id").(string),
|
||||||
|
@ -83,6 +103,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||||
TenantID: d.Get("tenant_id").(string),
|
TenantID: d.Get("tenant_id").(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := config.validate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
client, err := config.getArmClient()
|
client, err := config.getArmClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue