Skip to content

Commit

Permalink
Merge pull request #4902 from hashicorp/f-arm-crash-no-credentials
Browse files Browse the repository at this point in the history
provider/azurerm: Fix panic if no creds supplied
  • Loading branch information
phinze committed Jan 29, 2016
2 parents 5420266 + f8a40ff commit 7c1f8dd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions builtin/providers/azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"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/schema"
"github.com/hashicorp/terraform/terraform"
Expand Down Expand Up @@ -75,6 +76,25 @@ type Config struct {
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) {
config := Config{
SubscriptionID: d.Get("subscription_id").(string),
Expand All @@ -83,6 +103,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
TenantID: d.Get("tenant_id").(string),
}

if err := config.validate(); err != nil {
return nil, err
}

client, err := config.getArmClient()
if err != nil {
return nil, err
Expand Down

0 comments on commit 7c1f8dd

Please sign in to comment.