github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/builtin/providers/digitalocean/provider.go (about) 1 package digitalocean 2 3 import ( 4 "os" 5 6 "github.com/hashicorp/terraform/helper/schema" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 // Provider returns a schema.Provider for DigitalOcean. 11 func Provider() terraform.ResourceProvider { 12 return &schema.Provider{ 13 Schema: map[string]*schema.Schema{ 14 "token": &schema.Schema{ 15 Type: schema.TypeString, 16 Required: true, 17 DefaultFunc: envDefaultFunc("DIGITALOCEAN_TOKEN"), 18 Description: "The token key for API operations.", 19 }, 20 }, 21 22 ResourcesMap: map[string]*schema.Resource{ 23 "digitalocean_domain": resourceDigitalOceanDomain(), 24 "digitalocean_droplet": resourceDigitalOceanDroplet(), 25 "digitalocean_record": resourceDigitalOceanRecord(), 26 }, 27 28 ConfigureFunc: providerConfigure, 29 } 30 } 31 32 func envDefaultFunc(k string) schema.SchemaDefaultFunc { 33 return func() (interface{}, error) { 34 if v := os.Getenv(k); v != "" { 35 return v, nil 36 } 37 38 return nil, nil 39 } 40 } 41 42 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 43 config := Config{ 44 Token: d.Get("token").(string), 45 } 46 47 return config.Client() 48 }