github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/builtin/providers/ovh/provider.go (about) 1 package ovh 2 3 import ( 4 "github.com/hashicorp/terraform/helper/schema" 5 "github.com/hashicorp/terraform/terraform" 6 ) 7 8 // Provider returns a schema.Provider for OVH. 9 func Provider() terraform.ResourceProvider { 10 return &schema.Provider{ 11 Schema: map[string]*schema.Schema{ 12 "endpoint": &schema.Schema{ 13 Type: schema.TypeString, 14 Required: true, 15 DefaultFunc: schema.EnvDefaultFunc("OVH_ENDPOINT", nil), 16 Description: descriptions["endpoint"], 17 }, 18 "application_key": &schema.Schema{ 19 Type: schema.TypeString, 20 Required: true, 21 DefaultFunc: schema.EnvDefaultFunc("OVH_APPLICATION_KEY", ""), 22 Description: descriptions["application_key"], 23 }, 24 "application_secret": &schema.Schema{ 25 Type: schema.TypeString, 26 Required: true, 27 DefaultFunc: schema.EnvDefaultFunc("OVH_APPLICATION_SECRET", ""), 28 Description: descriptions["application_secret"], 29 }, 30 "consumer_key": &schema.Schema{ 31 Type: schema.TypeString, 32 Required: true, 33 DefaultFunc: schema.EnvDefaultFunc("OVH_CONSUMER_KEY", ""), 34 Description: descriptions["consumer_key"], 35 }, 36 }, 37 38 DataSourcesMap: map[string]*schema.Resource{ 39 "ovh_publiccloud_region": dataSourcePublicCloudRegion(), 40 "ovh_publiccloud_regions": dataSourcePublicCloudRegions(), 41 }, 42 43 ResourcesMap: map[string]*schema.Resource{ 44 "ovh_publiccloud_private_network": resourcePublicCloudPrivateNetwork(), 45 "ovh_publiccloud_private_network_subnet": resourcePublicCloudPrivateNetworkSubnet(), 46 "ovh_publiccloud_user": resourcePublicCloudUser(), 47 "ovh_vrack_publiccloud_attachment": resourceVRackPublicCloudAttachment(), 48 }, 49 50 ConfigureFunc: configureProvider, 51 } 52 } 53 54 var descriptions map[string]string 55 56 func init() { 57 descriptions = map[string]string{ 58 "endpoint": "The OVH API endpoint to target (ex: \"ovh-eu\").", 59 60 "application_key": "The OVH API Application Key.", 61 62 "application_secret": "The OVH API Application Secret.", 63 "consumer_key": "The OVH API Consumer key.", 64 } 65 } 66 67 func configureProvider(d *schema.ResourceData) (interface{}, error) { 68 config := Config{ 69 Endpoint: d.Get("endpoint").(string), 70 ApplicationKey: d.Get("application_key").(string), 71 ApplicationSecret: d.Get("application_secret").(string), 72 ConsumerKey: d.Get("consumer_key").(string), 73 } 74 75 if err := config.loadAndValidate(); err != nil { 76 return nil, err 77 } 78 79 return &config, nil 80 }