2014-09-09 22:13:11 +02:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
2014-11-17 18:55:45 +01:00
|
|
|
"os"
|
|
|
|
|
2014-09-09 22:13:11 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-11-17 18:55:45 +01:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2014-09-09 22:13:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a schema.Provider for DigitalOcean.
|
2014-11-17 18:55:45 +01:00
|
|
|
func Provider() terraform.ResourceProvider {
|
2014-09-09 22:13:11 +02:00
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"token": &schema.Schema{
|
2014-11-17 18:55:45 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: envDefaultFunc("DIGITALOCEAN_TOKEN"),
|
|
|
|
Description: "The token key for API operations.",
|
2014-09-09 22:13:11 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2014-09-09 22:29:36 +02:00
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2014-11-17 18:55:45 +01:00
|
|
|
"digitalocean_domain": resourceDigitalOceanDomain(),
|
|
|
|
"digitalocean_droplet": resourceDigitalOceanDroplet(),
|
|
|
|
"digitalocean_record": resourceDigitalOceanRecord(),
|
2014-09-09 22:29:36 +02:00
|
|
|
},
|
2014-11-17 18:55:45 +01:00
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
2014-09-09 22:13:11 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-17 18:55:45 +01:00
|
|
|
|
|
|
|
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
|
|
|
|
return func() (interface{}, error) {
|
|
|
|
if v := os.Getenv(k); v != "" {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
|
|
|
Token: d.Get("token").(string),
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.Client()
|
|
|
|
}
|