|
|
|
|
@ -2,10 +2,10 @@ package mailgun
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
|
|
|
|
@ -13,8 +13,9 @@ func Provider() terraform.ResourceProvider {
|
|
|
|
|
return &schema.Provider{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"api_key": &schema.Schema{
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Required: true,
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Required: true,
|
|
|
|
|
DefaultFunc: envDefaultFunc("MAILGUN_API_KEY"),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@ -26,14 +27,21 @@ func Provider() terraform.ResourceProvider {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
var config Config
|
|
|
|
|
configRaw := d.Get("").(map[string]interface{})
|
|
|
|
|
if err := mapstructure.Decode(configRaw, &config); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
config := Config{
|
|
|
|
|
APIKey: d.Get("api_key").(string),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("[INFO] Initializing Mailgun client")
|
|
|
|
|
|
|
|
|
|
return config.Client()
|
|
|
|
|
}
|
|
|
|
|
|