github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/builtin/providers/heroku/provider.go (about) 1 package heroku 2 3 import ( 4 "log" 5 "os" 6 7 "github.com/hashicorp/terraform/helper/schema" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 // Provider returns a terraform.ResourceProvider. 12 func Provider() terraform.ResourceProvider { 13 return &schema.Provider{ 14 Schema: map[string]*schema.Schema{ 15 "email": &schema.Schema{ 16 Type: schema.TypeString, 17 Optional: true, 18 DefaultFunc: envDefaultFunc("HEROKU_EMAIL"), 19 }, 20 21 "api_key": &schema.Schema{ 22 Type: schema.TypeString, 23 Optional: true, 24 DefaultFunc: envDefaultFunc("HEROKU_API_KEY"), 25 }, 26 }, 27 28 ResourcesMap: map[string]*schema.Resource{ 29 "heroku_app": resourceHerokuApp(), 30 "heroku_addon": resourceHerokuAddon(), 31 "heroku_domain": resourceHerokuDomain(), 32 "heroku_drain": resourceHerokuDrain(), 33 "heroku_cert": resourceHerokuCert(), 34 }, 35 36 ConfigureFunc: providerConfigure, 37 } 38 } 39 40 func envDefaultFunc(k string) schema.SchemaDefaultFunc { 41 return func() (interface{}, error) { 42 if v := os.Getenv(k); v != "" { 43 return v, nil 44 } 45 46 return nil, nil 47 } 48 } 49 50 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 51 config := Config{ 52 Email: d.Get("email").(string), 53 APIKey: d.Get("api_key").(string), 54 } 55 56 log.Println("[INFO] Initializing Heroku client") 57 return config.Client() 58 }