2015-04-24 18:18:24 +02:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
2015-05-29 00:10:21 +02:00
|
|
|
"fmt"
|
|
|
|
|
2015-04-24 18:18:24 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2015-06-02 21:08:14 +02:00
|
|
|
"github.com/mitchellh/go-homedir"
|
2015-04-24 18:18:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"settings_file": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
2015-05-28 00:50:45 +02:00
|
|
|
Optional: true,
|
2015-04-24 18:18:24 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("AZURE_SETTINGS_FILE", nil),
|
|
|
|
},
|
|
|
|
|
|
|
|
"subscription_id": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("AZURE_SUBSCRIPTION_ID", ""),
|
|
|
|
},
|
2015-05-28 00:50:45 +02:00
|
|
|
|
|
|
|
"certificate": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("AZURE_CERTIFICATE", ""),
|
|
|
|
},
|
2015-04-24 18:18:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2015-06-05 16:12:21 +02:00
|
|
|
"azure_instance": resourceAzureInstance(),
|
2015-06-19 18:52:36 +02:00
|
|
|
"azure_affinity_group": resourceAzureAffinityGroup(),
|
2015-06-05 16:12:21 +02:00
|
|
|
"azure_data_disk": resourceAzureDataDisk(),
|
2015-06-17 07:04:10 +02:00
|
|
|
"azure_sql_database_server": resourceAzureSqlDatabaseServer(),
|
|
|
|
"azure_sql_database_service": resourceAzureSqlDatabaseService(),
|
2015-06-05 16:12:21 +02:00
|
|
|
"azure_hosted_service": resourceAzureHostedService(),
|
|
|
|
"azure_storage_service": resourceAzureStorageService(),
|
|
|
|
"azure_storage_container": resourceAzureStorageContainer(),
|
|
|
|
"azure_storage_blob": resourceAzureStorageBlob(),
|
2015-06-12 00:55:43 +02:00
|
|
|
"azure_storage_queue": resourceAzureStorageQueue(),
|
2015-06-05 16:12:21 +02:00
|
|
|
"azure_virtual_network": resourceAzureVirtualNetwork(),
|
|
|
|
"azure_dns_server": resourceAzureDnsServer(),
|
|
|
|
"azure_local_network_connection": resourceAzureLocalNetworkConnection(),
|
|
|
|
"azure_security_group": resourceAzureSecurityGroup(),
|
|
|
|
"azure_security_group_rule": resourceAzureSecurityGroupRule(),
|
2015-04-24 18:18:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
2015-06-02 21:08:14 +02:00
|
|
|
settingsFile, err := homedir.Expand(d.Get("settings_file").(string))
|
|
|
|
if err != nil {
|
2015-06-03 14:45:30 +02:00
|
|
|
return nil, fmt.Errorf("Error expanding the settings file path: %s", err)
|
2015-06-02 21:08:14 +02:00
|
|
|
}
|
|
|
|
|
2015-04-24 18:18:24 +02:00
|
|
|
config := Config{
|
2015-06-02 21:08:14 +02:00
|
|
|
SettingsFile: settingsFile,
|
2015-04-24 18:18:24 +02:00
|
|
|
SubscriptionID: d.Get("subscription_id").(string),
|
2015-05-28 00:50:45 +02:00
|
|
|
Certificate: []byte(d.Get("certificate").(string)),
|
2015-04-24 18:18:24 +02:00
|
|
|
}
|
|
|
|
|
2015-05-29 00:10:21 +02:00
|
|
|
if config.SettingsFile != "" {
|
|
|
|
return config.NewClientFromSettingsFile()
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.SubscriptionID != "" && len(config.Certificate) > 0 {
|
|
|
|
return config.NewClient()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf(
|
|
|
|
"Insufficient configuration data. Please specify either a 'settings_file'\n" +
|
|
|
|
"or both a 'subscription_id' and 'certificate'.")
|
2015-04-24 18:18:24 +02:00
|
|
|
}
|