diff options
author | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-06-28 11:23:27 +0200 |
---|---|---|
committer | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-06-28 11:23:27 +0200 |
commit | e17f219ab8ff104f73e3c0f7515a7bb437b03d56 (patch) | |
tree | de70594e9645a382a3a4cb4addec966e96bf71eb | |
parent | e2966ba7a0ba5e3f87787f0a276ca5f7f6b21bd7 (diff) | |
download | terraform-provider-mailgun-e17f219ab8ff104f73e3c0f7515a7bb437b03d56.tar.gz terraform-provider-mailgun-e17f219ab8ff104f73e3c0f7515a7bb437b03d56.tar.zst terraform-provider-mailgun-e17f219ab8ff104f73e3c0f7515a7bb437b03d56.zip |
add provider without ressources and makefile
-rw-r--r-- | GNUmakefile | 44 | ||||
-rw-r--r-- | mailgun/provider.go | 34 | ||||
-rw-r--r-- | mailgun/provider_test.go | 38 | ||||
-rw-r--r-- | main.go | 11 | ||||
-rwxr-xr-x | scripts/errcheck.sh | 24 | ||||
-rwxr-xr-x | scripts/gofmtcheck.sh | 13 |
6 files changed, 164 insertions, 0 deletions
diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..0e2ce73 --- /dev/null +++ b/GNUmakefile | |||
@@ -0,0 +1,44 @@ | |||
1 | TEST?=$$(go list ./... |grep -v 'vendor') | ||
2 | GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) | ||
3 | PKG_NAME=mailgun | ||
4 | |||
5 | default: build | ||
6 | |||
7 | build: fmtcheck | ||
8 | go install | ||
9 | |||
10 | test: fmtcheck | ||
11 | go test -i $(TEST) || exit 1 | ||
12 | echo $(TEST) | \ | ||
13 | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 | ||
14 | |||
15 | testacc: fmtcheck | ||
16 | TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m | ||
17 | |||
18 | vet: | ||
19 | @echo "go vet ." | ||
20 | @go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ | ||
21 | echo ""; \ | ||
22 | echo "Vet found suspicious constructs. Please check the reported constructs"; \ | ||
23 | echo "and fix them if necessary before submitting the code for review."; \ | ||
24 | exit 1; \ | ||
25 | fi | ||
26 | |||
27 | fmt: | ||
28 | gofmt -w $(GOFMT_FILES) | ||
29 | |||
30 | fmtcheck: | ||
31 | @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" | ||
32 | |||
33 | errcheck: | ||
34 | @sh -c "'$(CURDIR)/scripts/errcheck.sh'" | ||
35 | |||
36 | |||
37 | test-compile: | ||
38 | @if [ "$(TEST)" = "./..." ]; then \ | ||
39 | echo "ERROR: Set TEST to a specific package. For example,"; \ | ||
40 | echo " make test-compile TEST=./$(PKG_NAME)"; \ | ||
41 | exit 1; \ | ||
42 | fi | ||
43 | go test -c $(TEST) $(TESTARGS) | ||
44 | |||
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 @@ | |||
1 | package mailgun | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/terraform/helper/schema" | ||
5 | "github.com/hashicorp/terraform/terraform" | ||
6 | "github.com/mailgun/mailgun-go" | ||
7 | ) | ||
8 | |||
9 | func 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 | |||
32 | func 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 @@ | |||
1 | package mailgun | ||
2 | |||
3 | import ( | ||
4 | "os" | ||
5 | "testing" | ||
6 | |||
7 | "github.com/hashicorp/terraform/helper/schema" | ||
8 | "github.com/hashicorp/terraform/terraform" | ||
9 | ) | ||
10 | |||
11 | var testAccProviders map[string]terraform.ResourceProvider | ||
12 | var testAccProvider *schema.Provider | ||
13 | |||
14 | func init() { | ||
15 | testAccProvider = Provider().(*schema.Provider) | ||
16 | testAccProviders = map[string]terraform.ResourceProvider{ | ||
17 | "mailgun": testAccProvider, | ||
18 | } | ||
19 | } | ||
20 | |||
21 | func TestProvider(t *testing.T) { | ||
22 | if err := Provider().(*schema.Provider).InternalValidate(); err != nil { | ||
23 | t.Fatalf("err: %s", err) | ||
24 | } | ||
25 | } | ||
26 | |||
27 | func TestProvider_impl(t *testing.T) { | ||
28 | var _ terraform.ResourceProvider = Provider() | ||
29 | } | ||
30 | |||
31 | func 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 | } | ||
@@ -0,0 +1,11 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "github.com/alexandreFre/terraform-provider-mailgun/mailgun" | ||
5 | "github.com/hashicorp/terraform/plugin" | ||
6 | ) | ||
7 | |||
8 | func main() { | ||
9 | plugin.Serve(&plugin.ServeOpts{ | ||
10 | ProviderFunc: mailgun.Provider}) | ||
11 | } | ||
diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh new file mode 100755 index 0000000..15464f5 --- /dev/null +++ b/scripts/errcheck.sh | |||
@@ -0,0 +1,24 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # Check gofmt | ||
4 | echo "==> Checking for unchecked errors..." | ||
5 | |||
6 | if ! which errcheck > /dev/null; then | ||
7 | echo "==> Installing errcheck..." | ||
8 | go get -u github.com/kisielk/errcheck | ||
9 | fi | ||
10 | |||
11 | err_files=$(errcheck -ignoretests \ | ||
12 | -ignore 'github.com/hashicorp/terraform/helper/schema:Set' \ | ||
13 | -ignore 'bytes:.*' \ | ||
14 | -ignore 'io:Close|Write' \ | ||
15 | $(go list ./...| grep -v /vendor/)) | ||
16 | |||
17 | if [[ -n ${err_files} ]]; then | ||
18 | echo 'Unchecked errors found in the following places:' | ||
19 | echo "${err_files}" | ||
20 | echo "Please handle returned errors. You can check directly with \`make errcheck\`" | ||
21 | exit 1 | ||
22 | fi | ||
23 | |||
24 | exit 0 | ||
diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh new file mode 100755 index 0000000..1c05581 --- /dev/null +++ b/scripts/gofmtcheck.sh | |||
@@ -0,0 +1,13 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # Check gofmt | ||
4 | echo "==> Checking that code complies with gofmt requirements..." | ||
5 | gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`) | ||
6 | if [[ -n ${gofmt_files} ]]; then | ||
7 | echo 'gofmt needs running on the following files:' | ||
8 | echo "${gofmt_files}" | ||
9 | echo "You can use the command: \`make fmt\` to reformat code." | ||
10 | exit 1 | ||
11 | fi | ||
12 | |||
13 | exit 0 | ||