package mailgun import ( "log" "os" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" ) // Provider returns a terraform.ResourceProvider. func Provider() terraform.ResourceProvider { return &schema.Provider{ Schema: map[string]*schema.Schema{ "api_key": &schema.Schema{ Type: schema.TypeString, Required: true, DefaultFunc: envDefaultFunc("MAILGUN_API_KEY"), }, }, ResourcesMap: map[string]*schema.Resource{ "mailgun_domain": resourceMailgunDomain(), }, ConfigureFunc: providerConfigure, } } 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{ APIKey: d.Get("api_key").(string), } log.Println("[INFO] Initializing Mailgun client") return config.Client() }