github.com/pbthorste/terraform@v0.8.6-0.20170127005045-deb56bd93da2/builtin/providers/profitbricks/provider.go (about) 1 package profitbricks 2 3 import ( 4 "fmt" 5 "github.com/hashicorp/terraform/helper/schema" 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 // Provider returns a schema.Provider for DigitalOcean. 10 func Provider() terraform.ResourceProvider { 11 return &schema.Provider{ 12 Schema: map[string]*schema.Schema{ 13 "username": { 14 Type: schema.TypeString, 15 Required: true, 16 DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_USERNAME", nil), 17 Description: "Profitbricks username for API operations.", 18 }, 19 "password": { 20 Type: schema.TypeString, 21 Required: true, 22 DefaultFunc: schema.EnvDefaultFunc("PROFITBRICKS_PASSWORD", nil), 23 Description: "Profitbricks password for API operations.", 24 }, 25 "retries": { 26 Type: schema.TypeInt, 27 Optional: true, 28 Default: 50, 29 }, 30 }, 31 32 ResourcesMap: map[string]*schema.Resource{ 33 "profitbricks_datacenter": resourceProfitBricksDatacenter(), 34 "profitbricks_ipblock": resourceProfitBricksIPBlock(), 35 "profitbricks_firewall": resourceProfitBricksFirewall(), 36 "profitbricks_lan": resourceProfitBricksLan(), 37 "profitbricks_loadbalancer": resourceProfitBricksLoadbalancer(), 38 "profitbricks_nic": resourceProfitBricksNic(), 39 "profitbricks_server": resourceProfitBricksServer(), 40 "profitbricks_volume": resourceProfitBricksVolume(), 41 }, 42 43 ConfigureFunc: providerConfigure, 44 } 45 } 46 47 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 48 49 if _, ok := d.GetOk("username"); !ok { 50 return nil, fmt.Errorf("ProfitBricks username has not been provided.") 51 } 52 53 if _, ok := d.GetOk("password"); !ok { 54 return nil, fmt.Errorf("ProfitBricks password has not been provided.") 55 } 56 57 config := Config{ 58 Username: d.Get("username").(string), 59 Password: d.Get("password").(string), 60 Retries: d.Get("retries").(int), 61 } 62 63 return config.Client() 64 }