github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/builtin/providers/mailgun/provider.go (about) 1 package mailgun 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 "api_key": &schema.Schema{ 16 Type: schema.TypeString, 17 Required: true, 18 DefaultFunc: envDefaultFunc("MAILGUN_API_KEY"), 19 }, 20 }, 21 22 ResourcesMap: map[string]*schema.Resource{ 23 "mailgun_domain": resourceMailgunDomain(), 24 }, 25 26 ConfigureFunc: providerConfigure, 27 } 28 } 29 30 func envDefaultFunc(k string) schema.SchemaDefaultFunc { 31 return func() (interface{}, error) { 32 if v := os.Getenv(k); v != "" { 33 return v, nil 34 } 35 36 return nil, nil 37 } 38 } 39 40 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 41 config := Config{ 42 APIKey: d.Get("api_key").(string), 43 } 44 45 log.Println("[INFO] Initializing Mailgun client") 46 return config.Client() 47 }