aboutsummaryrefslogtreecommitdiffhomepage
path: root/mailgun
diff options
context:
space:
mode:
Diffstat (limited to 'mailgun')
-rw-r--r--mailgun/provider.go34
-rw-r--r--mailgun/provider_test.go38
2 files changed, 72 insertions, 0 deletions
diff --git a/mailgun/provider.go b/mailgun/provider.go
new file mode 100644
index 0000000..8771c48
--- /dev/null
+++ b/mailgun/provider.go
@@ -0,0 +1,34 @@
1package mailgun
2
3import (
4 "github.com/hashicorp/terraform/helper/schema"
5 "github.com/hashicorp/terraform/terraform"
6 "github.com/mailgun/mailgun-go"
7)
8
9func Provider() terraform.ResourceProvider {
10 return &schema.Provider{
11 Schema: map[string]*schema.Schema{
12 "domain": {
13 Type: schema.TypeString,
14 Required: true,
15 DefaultFunc: schema.EnvDefaultFunc("MAILGUN_DOMAIN", nil),
16 Description: "domain for mailgun.",
17 },
18 "apikey": {
19 Type: schema.TypeString,
20 Required: true,
21 DefaultFunc: schema.EnvDefaultFunc("MAILGUN_APIKEY", nil),
22 Description: "API Key for mailgun",
23 },
24 },
25
26 ResourcesMap: map[string]*schema.Resource{},
27
28 ConfigureFunc: providerConfigure,
29 }
30}
31
32func providerConfigure(d *schema.ResourceData) (interface{}, error) {
33 return mailgun.NewMailgun(d.Get("domain").(string), d.Get("apikey").(string)), nil
34}
diff --git a/mailgun/provider_test.go b/mailgun/provider_test.go
new file mode 100644
index 0000000..37c1c7e
--- /dev/null
+++ b/mailgun/provider_test.go
@@ -0,0 +1,38 @@
1package mailgun
2
3import (
4 "os"
5 "testing"
6
7 "github.com/hashicorp/terraform/helper/schema"
8 "github.com/hashicorp/terraform/terraform"
9)
10
11var testAccProviders map[string]terraform.ResourceProvider
12var testAccProvider *schema.Provider
13
14func init() {
15 testAccProvider = Provider().(*schema.Provider)
16 testAccProviders = map[string]terraform.ResourceProvider{
17 "mailgun": testAccProvider,
18 }
19}
20
21func TestProvider(t *testing.T) {
22 if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
23 t.Fatalf("err: %s", err)
24 }
25}
26
27func TestProvider_impl(t *testing.T) {
28 var _ terraform.ResourceProvider = Provider()
29}
30
31func testAccPreCheck(t *testing.T) {
32 if v := os.Getenv("MAILGUN_DOMAIN"); v == "" {
33 t.Fatal("MAILGUN_DOMAIN must be set for acceptance tests")
34 }
35 if v := os.Getenv("MAILGUN_APIKEY"); v == "" {
36 t.Fatal("MAILGUN_APIKEY must be set for acceptance tests")
37 }
38}