github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/oneandone/provider.go (about) 1 package oneandone 2 3 import ( 4 "github.com/1and1/oneandone-cloudserver-sdk-go" 5 "github.com/hashicorp/terraform/helper/schema" 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 func Provider() terraform.ResourceProvider { 10 return &schema.Provider{ 11 Schema: map[string]*schema.Schema{ 12 "token": { 13 Type: schema.TypeString, 14 Required: true, 15 DefaultFunc: schema.EnvDefaultFunc("ONEANDONE_TOKEN", nil), 16 Description: "1&1 token for API operations.", 17 }, 18 "retries": { 19 Type: schema.TypeInt, 20 Optional: true, 21 Default: 50, 22 DefaultFunc: schema.EnvDefaultFunc("ONEANDONE_RETRIES", nil), 23 }, 24 "endpoint": { 25 Type: schema.TypeString, 26 Optional: true, 27 Default: oneandone.BaseUrl, 28 DefaultFunc: schema.EnvDefaultFunc("ONEANDONE_ENDPOINT", nil), 29 }, 30 }, 31 ResourcesMap: map[string]*schema.Resource{ 32 "oneandone_server": resourceOneandOneServer(), 33 "oneandone_firewall_policy": resourceOneandOneFirewallPolicy(), 34 "oneandone_private_network": resourceOneandOnePrivateNetwork(), 35 "oneandone_public_ip": resourceOneandOnePublicIp(), 36 "oneandone_shared_storage": resourceOneandOneSharedStorage(), 37 "oneandone_monitoring_policy": resourceOneandOneMonitoringPolicy(), 38 "oneandone_loadbalancer": resourceOneandOneLoadbalancer(), 39 "oneandone_vpn": resourceOneandOneVPN(), 40 }, 41 ConfigureFunc: providerConfigure, 42 } 43 } 44 45 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 46 var endpoint string 47 if d.Get("endpoint").(string) != oneandone.BaseUrl { 48 endpoint = d.Get("endpoint").(string) 49 } 50 config := Config{ 51 Token: d.Get("token").(string), 52 Retries: d.Get("retries").(int), 53 Endpoint: endpoint, 54 } 55 return config.Client() 56 }