2014-08-18 18:32:40 +02:00
|
|
|
package heroku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2014-11-19 14:25:18 +01:00
|
|
|
"os"
|
2014-08-18 18:32:40 +02:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-09-28 20:51:39 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2014-08-18 18:32:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
2014-09-28 20:51:39 +02:00
|
|
|
func Provider() terraform.ResourceProvider {
|
2014-08-18 18:32:40 +02:00
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"email": &schema.Schema{
|
2014-11-19 14:25:18 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: envDefaultFunc("HEROKU_EMAIL"),
|
2014-08-18 18:32:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
"api_key": &schema.Schema{
|
2014-11-19 14:25:18 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: envDefaultFunc("HEROKU_API_KEY"),
|
2014-08-18 18:32:40 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2014-08-19 18:14:14 +02:00
|
|
|
"heroku_app": resourceHerokuApp(),
|
|
|
|
"heroku_addon": resourceHerokuAddon(),
|
|
|
|
"heroku_domain": resourceHerokuDomain(),
|
2014-08-19 18:18:45 +02:00
|
|
|
"heroku_drain": resourceHerokuDrain(),
|
2014-11-27 12:12:34 +01:00
|
|
|
"heroku_cert": resourceHerokuCert(),
|
2014-08-18 18:32:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 14:25:18 +01:00
|
|
|
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
|
|
|
|
return func() (interface{}, error) {
|
|
|
|
if v := os.Getenv(k); v != "" {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-18 18:32:40 +02:00
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
2014-11-19 14:25:18 +01:00
|
|
|
config := Config{
|
|
|
|
Email: d.Get("email").(string),
|
|
|
|
APIKey: d.Get("api_key").(string),
|
2014-08-18 18:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("[INFO] Initializing Heroku client")
|
|
|
|
return config.Client()
|
|
|
|
}
|