github.com/bendemaree/terraform@v0.5.4-0.20150613200311-f50d97d6eee6/builtin/providers/azure/provider.go (about)

     1  package azure
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  	"github.com/mitchellh/go-homedir"
     9  )
    10  
    11  // Provider returns a terraform.ResourceProvider.
    12  func Provider() terraform.ResourceProvider {
    13  	return &schema.Provider{
    14  		Schema: map[string]*schema.Schema{
    15  			"settings_file": &schema.Schema{
    16  				Type:        schema.TypeString,
    17  				Optional:    true,
    18  				DefaultFunc: schema.EnvDefaultFunc("AZURE_SETTINGS_FILE", nil),
    19  			},
    20  
    21  			"subscription_id": &schema.Schema{
    22  				Type:        schema.TypeString,
    23  				Optional:    true,
    24  				DefaultFunc: schema.EnvDefaultFunc("AZURE_SUBSCRIPTION_ID", ""),
    25  			},
    26  
    27  			"certificate": &schema.Schema{
    28  				Type:        schema.TypeString,
    29  				Optional:    true,
    30  				DefaultFunc: schema.EnvDefaultFunc("AZURE_CERTIFICATE", ""),
    31  			},
    32  		},
    33  
    34  		ResourcesMap: map[string]*schema.Resource{
    35  			"azure_instance":                 resourceAzureInstance(),
    36  			"azure_data_disk":                resourceAzureDataDisk(),
    37  			"azure_hosted_service":           resourceAzureHostedService(),
    38  			"azure_storage_service":          resourceAzureStorageService(),
    39  			"azure_storage_container":        resourceAzureStorageContainer(),
    40  			"azure_storage_blob":             resourceAzureStorageBlob(),
    41  			"azure_storage_queue":            resourceAzureStorageQueue(),
    42  			"azure_virtual_network":          resourceAzureVirtualNetwork(),
    43  			"azure_dns_server":               resourceAzureDnsServer(),
    44  			"azure_local_network_connection": resourceAzureLocalNetworkConnection(),
    45  			"azure_security_group":           resourceAzureSecurityGroup(),
    46  			"azure_security_group_rule":      resourceAzureSecurityGroupRule(),
    47  		},
    48  
    49  		ConfigureFunc: providerConfigure,
    50  	}
    51  }
    52  
    53  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    54  	settingsFile, err := homedir.Expand(d.Get("settings_file").(string))
    55  	if err != nil {
    56  		return nil, fmt.Errorf("Error expanding the settings file path: %s", err)
    57  	}
    58  
    59  	config := Config{
    60  		SettingsFile:   settingsFile,
    61  		SubscriptionID: d.Get("subscription_id").(string),
    62  		Certificate:    []byte(d.Get("certificate").(string)),
    63  	}
    64  
    65  	if config.SettingsFile != "" {
    66  		return config.NewClientFromSettingsFile()
    67  	}
    68  
    69  	if config.SubscriptionID != "" && len(config.Certificate) > 0 {
    70  		return config.NewClient()
    71  	}
    72  
    73  	return nil, fmt.Errorf(
    74  		"Insufficient configuration data. Please specify either a 'settings_file'\n" +
    75  			"or both a 'subscription_id' and 'certificate'.")
    76  }