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-05-22 15:31:14 +02:00
|
|
|
"azure_data_disk": resourceAzureDataDisk(),
|
2015-04-30 10:58:45 +02:00
|
|
|
"azure_instance": resourceAzureInstance(),
|
|
|
|
"azure_security_group": resourceAzureSecurityGroup(),
|
|
|
|
"azure_virtual_network": resourceAzureVirtualNetwork(),
|
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 {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|