github.com/shvar/terraform@v0.6.9-0.20151215234924-3365cd2231df/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 }, 43 44 ConfigureFunc: providerConfigure, 45 } 46 } 47 48 // Config is the configuration structure used to instantiate a 49 // new Azure management client. 50 type Config struct { 51 ManagementURL string 52 53 SubscriptionID string 54 ClientID string 55 ClientSecret string 56 TenantID string 57 } 58 59 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 60 config := Config{ 61 SubscriptionID: d.Get("subscription_id").(string), 62 ClientID: d.Get("client_id").(string), 63 ClientSecret: d.Get("client_secret").(string), 64 TenantID: d.Get("tenant_id").(string), 65 } 66 67 client, err := config.getArmClient() 68 if err != nil { 69 return nil, err 70 } 71 72 return client, nil 73 } 74 75 func azureRMNormalizeLocation(location interface{}) string { 76 input := location.(string) 77 return strings.Replace(strings.ToLower(input), " ", "", -1) 78 }