github.com/acm1/terraform@v0.6.2-0.20150729164239-1f314444f45c/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_affinity_group": resourceAzureAffinityGroup(), 37 "azure_data_disk": resourceAzureDataDisk(), 38 "azure_sql_database_server": resourceAzureSqlDatabaseServer(), 39 "azure_sql_database_server_firewall_rule": resourceAzureSqlDatabaseServerFirewallRule(), 40 "azure_sql_database_service": resourceAzureSqlDatabaseService(), 41 "azure_hosted_service": resourceAzureHostedService(), 42 "azure_storage_service": resourceAzureStorageService(), 43 "azure_storage_container": resourceAzureStorageContainer(), 44 "azure_storage_blob": resourceAzureStorageBlob(), 45 "azure_storage_queue": resourceAzureStorageQueue(), 46 "azure_virtual_network": resourceAzureVirtualNetwork(), 47 "azure_dns_server": resourceAzureDnsServer(), 48 "azure_local_network_connection": resourceAzureLocalNetworkConnection(), 49 "azure_security_group": resourceAzureSecurityGroup(), 50 "azure_security_group_rule": resourceAzureSecurityGroupRule(), 51 }, 52 53 ConfigureFunc: providerConfigure, 54 } 55 } 56 57 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 58 settingsFile, err := homedir.Expand(d.Get("settings_file").(string)) 59 if err != nil { 60 return nil, fmt.Errorf("Error expanding the settings file path: %s", err) 61 } 62 63 config := Config{ 64 SettingsFile: settingsFile, 65 SubscriptionID: d.Get("subscription_id").(string), 66 Certificate: []byte(d.Get("certificate").(string)), 67 } 68 69 if config.SettingsFile != "" { 70 return config.NewClientFromSettingsFile() 71 } 72 73 if config.SubscriptionID != "" && len(config.Certificate) > 0 { 74 return config.NewClient() 75 } 76 77 return nil, fmt.Errorf( 78 "Insufficient configuration data. Please specify either a 'settings_file'\n" + 79 "or both a 'subscription_id' and 'certificate'.") 80 }