This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
forked from fastly/terraform-provider-fastly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
125 lines (102 loc) · 4.65 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=fastly
FULL_PKG_NAME=github.com/fastly/terraform-provider-fastly
VERSION_PLACEHOLDER=version.ProviderVersion
VERSION=$(shell git describe --tags --always)
VERSION_SHORT=$(shell git describe --tags --always --abbrev=0)
DOCS_PROVIDER_VERSION=$(subst v,,$(VERSION_SHORT))
# XAT001: missing resource.TestCase ErrorCheck.
# R018: replace sleep with either resource.Retry() or WaitForState().
# R001: for complex d.Set() calls use a string literal instead.
TFPROVIDERLINTX_DEFAULT_FLAGS=-XAT001=false -R018=false -R001=false -R019=false
GOHOSTOS ?= $(shell go env GOHOSTOS || echo unknown)
GOHOSTARCH ?= $(shell go env GOHOSTARCH || echo unknown)
# Use a parallelism of 4 by default for tests, overriding whatever GOMAXPROCS is
# set to. For the acceptance tests especially, the main bottleneck affecting the
# tests is network bandwidth and Fastly API rate limits. Therefore using the
# system default value of GOMAXPROCS, which is usually determined by the number
# of processors available, doesn't make the most sense.
TEST_PARALLELISM?=4
default: build
build: clean
go build -o bin/terraform-provider-$(PKG_NAME)_$(VERSION) -ldflags="-X $(FULL_PKG_NAME)/$(VERSION_PLACEHOLDER)=$(VERSION)"
@sh -c "'$(CURDIR)/scripts/generate-dev-overrides.sh'"
test:
go test $(TEST) || exit 1
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=$(TEST_PARALLELISM)
# prefix `go test` with TF_LOG=debug or 'trace' for additional terraform output
# such as all the requests and responses it handles.
#
# reference:
# https://www.terraform.io/docs/internals/debugging.html
#
# TF_ACC is a recognised Terraform configuration that indicates we want to run an acceptance test, and which will result in creating REAL resources.
#
# reference:
# https://www.terraform.io/docs/extend/testing/acceptance-tests/index.html#running-acceptance-tests
#
testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -parallel=$(TEST_PARALLELISM) -timeout 360m -ldflags="-X=$(FULL_PKG_NAME)/$(VERSION_PLACEHOLDER)=acc"
# WARNING: This target will delete infrastructure.
clean_test:
@printf 'WARNING: This will delete infrastructure. Continue? (y/n) '; \
read answer; \
if echo "$$answer" | grep -iq '^y'; then \
SILENCE=true make sweep || true; \
fastly service list --token $$FASTLY_API_KEY | grep -E '^tf\-' | awk '{print $$2}' | xargs -I % fastly service delete --token $$FASTLY_API_KEY -f -s %; \
TEST_PARALLELISM=8 make testacc; \
fi
vet:
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo "\nVet 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'"
goreleaser-bin:
go install github.com/goreleaser/goreleaser@latest
# You can pass flags to goreleaser via GORELEASER_ARGS
# --skip-validate will skip the checks
# --rm-dist will save you deleting the dist dir
# --single-target will be quicker and only build for your os & architecture
# e.g.
# make goreleaser GORELEASER_ARGS="--skip-validate --rm-dist"
goreleaser: goreleaser-bin
@GOHOSTOS="${GOHOSTOS}" GOHOSTARCH="${GOHOSTARCH}" goreleaser build ${GORELEASER_ARGS}
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)
BIN=$(CURDIR)/bin
$(BIN)/%:
@echo "Installing tools from tools/tools.go"
@cat tools/tools.go | grep _ | awk -F '"' '{print $$2}' | GOBIN=$(BIN) xargs -tI {} go install {}
generate-docs: $(BIN)/tfplugindocs
$(shell sed -e "s/__VERSION__/$(DOCS_PROVIDER_VERSION)/g" examples/index-fastly-provider.tf.tmpl > examples/index-fastly-provider.tf)
$(BIN)/tfplugindocs generate
rm examples/index-fastly-provider.tf
validate-docs: $(BIN)/tfplugindocs
$(BIN)/tfplugindocs validate
tfproviderlintx: $(BIN)/tfproviderlintx
$(BIN)/tfproviderlintx $(TFPROVIDERLINTX_DEFAULT_FLAGS) $(TFPROVIDERLINTX_ARGS) ./...
tfproviderlint: $(BIN)/tfproviderlint
$(BIN)/tfproviderlint $(TFPROVIDERLINT_ARGS) ./...
sweep:
@if [ "$(SILENCE)" != "true" ]; then \
echo "WARNING: This will destroy infrastructure. Use only in development accounts."; \
fi
go test ./fastly -v -sweep=ALL $(SWEEPARGS) -timeout 30m || true
clean:
rm -rf ./bin
.PHONY: all build clean clean_test default errcheck fmt fmtcheck generate-docs goreleaser goreleaser-bin sweep test test-compile testacc validate-docs vet