github.com/gwilym/terraform@v0.3.8-0.20151231151641-c7573de75b19/builtin/providers/azurerm/provider.go (about)

     1  package azurerm
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  // Provider returns a terraform.ResourceProvider.
    11  func Provider() terraform.ResourceProvider {
    12  	return &schema.Provider{
    13  		Schema: map[string]*schema.Schema{
    14  			"subscription_id": &schema.Schema{
    15  				Type:        schema.TypeString,
    16  				Required:    true,
    17  				DefaultFunc: schema.EnvDefaultFunc("ARM_SUBSCRIPTION_ID", ""),
    18  			},
    19  
    20  			"client_id": &schema.Schema{
    21  				Type:        schema.TypeString,
    22  				Required:    true,
    23  				DefaultFunc: schema.EnvDefaultFunc("ARM_CLIENT_ID", ""),
    24  			},
    25  
    26  			"client_secret": &schema.Schema{
    27  				Type:        schema.TypeString,
    28  				Required:    true,
    29  				DefaultFunc: schema.EnvDefaultFunc("ARM_CLIENT_SECRET", ""),
    30  			},
    31  
    32  			"tenant_id": &schema.Schema{
    33  				Type:        schema.TypeString,
    34  				Required:    true,
    35  				DefaultFunc: schema.EnvDefaultFunc("ARM_TENANT_ID", ""),
    36  			},
    37  		},
    38  
    39  		ResourcesMap: map[string]*schema.Resource{
    40  			"azurerm_resource_group":        resourceArmResourceGroup(),
    41  			"azurerm_virtual_network":       resourceArmVirtualNetwork(),
    42  			"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
    43  		},
    44  
    45  		ConfigureFunc: providerConfigure,
    46  	}
    47  }
    48  
    49  // Config is the configuration structure used to instantiate a
    50  // new Azure management client.
    51  type Config struct {
    52  	ManagementURL string
    53  
    54  	SubscriptionID string
    55  	ClientID       string
    56  	ClientSecret   string
    57  	TenantID       string
    58  }
    59  
    60  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    61  	config := Config{
    62  		SubscriptionID: d.Get("subscription_id").(string),
    63  		ClientID:       d.Get("client_id").(string),
    64  		ClientSecret:   d.Get("client_secret").(string),
    65  		TenantID:       d.Get("tenant_id").(string),
    66  	}
    67  
    68  	client, err := config.getArmClient()
    69  	if err != nil {
    70  		return nil, err
    71  	}
    72  
    73  	return client, nil
    74  }
    75  
    76  func azureRMNormalizeLocation(location interface{}) string {
    77  	input := location.(string)
    78  	return strings.Replace(strings.ToLower(input), " ", "", -1)
    79  }