]> git.immae.eu Git - github/fretlink/terraform-provider-mailgun.git/commitdiff
add provider without ressources and makefile
authorAlexandre Garand <alexandre.garand@fretlink.com>
Fri, 28 Jun 2019 09:23:27 +0000 (11:23 +0200)
committerAlexandre Garand <alexandre.garand@fretlink.com>
Fri, 28 Jun 2019 09:23:27 +0000 (11:23 +0200)
GNUmakefile [new file with mode: 0644]
mailgun/provider.go [new file with mode: 0644]
mailgun/provider_test.go [new file with mode: 0644]
main.go [new file with mode: 0644]
scripts/errcheck.sh [new file with mode: 0755]
scripts/gofmtcheck.sh [new file with mode: 0755]

diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644 (file)
index 0000000..0e2ce73
--- /dev/null
@@ -0,0 +1,44 @@
+TEST?=$$(go list ./... |grep -v 'vendor')
+GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
+PKG_NAME=mailgun
+
+default: build
+
+build: fmtcheck
+       go install
+
+test: fmtcheck
+       go test -i $(TEST) || exit 1
+       echo $(TEST) | \
+               xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
+
+testacc: fmtcheck
+       TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
+
+vet:
+       @echo "go vet ."
+       @go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
+               echo ""; \
+               echo "Vet found suspicious constructs. Please check the reported constructs"; \
+               echo "and fix them if necessary before submitting the code for review."; \
+               exit 1; \
+       fi
+
+fmt:
+       gofmt -w $(GOFMT_FILES)
+
+fmtcheck:
+       @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
+
+errcheck:
+       @sh -c "'$(CURDIR)/scripts/errcheck.sh'"
+
+
+test-compile:
+       @if [ "$(TEST)" = "./..." ]; then \
+               echo "ERROR: Set TEST to a specific package. For example,"; \
+               echo "  make test-compile TEST=./$(PKG_NAME)"; \
+               exit 1; \
+       fi
+       go test -c $(TEST) $(TESTARGS)
+
diff --git a/mailgun/provider.go b/mailgun/provider.go
new file mode 100644 (file)
index 0000000..8771c48
--- /dev/null
@@ -0,0 +1,34 @@
+package mailgun
+
+import (
+       "github.com/hashicorp/terraform/helper/schema"
+       "github.com/hashicorp/terraform/terraform"
+       "github.com/mailgun/mailgun-go"
+)
+
+func Provider() terraform.ResourceProvider {
+       return &schema.Provider{
+               Schema: map[string]*schema.Schema{
+                       "domain": {
+                               Type:        schema.TypeString,
+                               Required:    true,
+                               DefaultFunc: schema.EnvDefaultFunc("MAILGUN_DOMAIN", nil),
+                               Description: "domain for mailgun.",
+                       },
+                       "apikey": {
+                               Type:        schema.TypeString,
+                               Required:    true,
+                               DefaultFunc: schema.EnvDefaultFunc("MAILGUN_APIKEY", nil),
+                               Description: "API Key for mailgun",
+                       },
+               },
+
+               ResourcesMap: map[string]*schema.Resource{},
+
+               ConfigureFunc: providerConfigure,
+       }
+}
+
+func providerConfigure(d *schema.ResourceData) (interface{}, error) {
+       return mailgun.NewMailgun(d.Get("domain").(string), d.Get("apikey").(string)), nil
+}
diff --git a/mailgun/provider_test.go b/mailgun/provider_test.go
new file mode 100644 (file)
index 0000000..37c1c7e
--- /dev/null
@@ -0,0 +1,38 @@
+package mailgun
+
+import (
+       "os"
+       "testing"
+
+       "github.com/hashicorp/terraform/helper/schema"
+       "github.com/hashicorp/terraform/terraform"
+)
+
+var testAccProviders map[string]terraform.ResourceProvider
+var testAccProvider *schema.Provider
+
+func init() {
+       testAccProvider = Provider().(*schema.Provider)
+       testAccProviders = map[string]terraform.ResourceProvider{
+               "mailgun": testAccProvider,
+       }
+}
+
+func TestProvider(t *testing.T) {
+       if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
+               t.Fatalf("err: %s", err)
+       }
+}
+
+func TestProvider_impl(t *testing.T) {
+       var _ terraform.ResourceProvider = Provider()
+}
+
+func testAccPreCheck(t *testing.T) {
+       if v := os.Getenv("MAILGUN_DOMAIN"); v == "" {
+               t.Fatal("MAILGUN_DOMAIN must be set for acceptance tests")
+       }
+       if v := os.Getenv("MAILGUN_APIKEY"); v == "" {
+               t.Fatal("MAILGUN_APIKEY must be set for acceptance tests")
+       }
+}
diff --git a/main.go b/main.go
new file mode 100644 (file)
index 0000000..debeaa0
--- /dev/null
+++ b/main.go
@@ -0,0 +1,11 @@
+package main
+
+import (
+       "github.com/alexandreFre/terraform-provider-mailgun/mailgun"
+       "github.com/hashicorp/terraform/plugin"
+)
+
+func main() {
+       plugin.Serve(&plugin.ServeOpts{
+               ProviderFunc: mailgun.Provider})
+}
diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh
new file mode 100755 (executable)
index 0000000..15464f5
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+# Check gofmt
+echo "==> Checking for unchecked errors..."
+
+if ! which errcheck > /dev/null; then
+    echo "==> Installing errcheck..."
+    go get -u github.com/kisielk/errcheck
+fi
+
+err_files=$(errcheck -ignoretests \
+                     -ignore 'github.com/hashicorp/terraform/helper/schema:Set' \
+                     -ignore 'bytes:.*' \
+                     -ignore 'io:Close|Write' \
+                     $(go list ./...| grep -v /vendor/))
+
+if [[ -n ${err_files} ]]; then
+    echo 'Unchecked errors found in the following places:'
+    echo "${err_files}"
+    echo "Please handle returned errors. You can check directly with \`make errcheck\`"
+    exit 1
+fi
+
+exit 0
diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh
new file mode 100755 (executable)
index 0000000..1c05581
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+# Check gofmt
+echo "==> Checking that code complies with gofmt requirements..."
+gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`)
+if [[ -n ${gofmt_files} ]]; then
+    echo 'gofmt needs running on the following files:'
+    echo "${gofmt_files}"
+    echo "You can use the command: \`make fmt\` to reformat code."
+    exit 1
+fi
+
+exit 0