-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
70 lines (56 loc) · 1.78 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
SHELL := /bin/bash
.SHELLFLAGS = -o pipefail -c
TESTDIR = $(CURDIR)/test/
FIXTUREDIR = $(TESTDIR)/fixture/
TMPFILE := $(shell mktemp)
MODULES := $(wildcard modules/*/.)
EXAMPLES := $(wildcard examples/*/.)
TEST_FIXTURES := $(wildcard test/*/.)
.PHONY: all
## Default target
all: test pre-commit
.PHONY : init_all
init_all: init init_examples init_tests init_modules
.PHONY : test
## Run tests
test: init_tests
pushd $(TESTDIR) && go test -v -timeout 10m -run TestDocker && popd
.PHONY : test_aws
## Run tests
test_aws: init_tests
pushd $(TESTDIR) && go test -v -timeout 40m -run TestAws && popd
.PHONY : init
init:
terraform init -upgrade -input=false -backend=false
.PHONY : init_tests
init_tests:
for TEST in $(TEST_FIXTURES); do \
echo "terraform init $$TEST"; \
pushd $$TEST && terraform init -upgrade -input=false -backend=false && popd; \
done
.PHONY : init_examples
init_examples:
for EXAMPLE in $(EXAMPLES); do \
echo "terraform init $$EXAMPLE"; \
pushd $$EXAMPLE && terraform init -upgrade -input=false -backend=false && popd; \
done
.PHONY : init_modules
init_modules:
for MODULE in $(MODULES); do \
echo "terraform init $$MODULE"; \
pushd $$MODULE && terraform init -upgrade -input=false -backend=false && popd; \
done
.PHONY : pre-commit
pre-commit: pre-commit-check clean init_all terrascan-init tflint-init
pre-commit run -a
.PHONY : pre-commit-check
pre-commit-check:
$(if $(shell command -v pre-commit 2> /dev/null),,$(error pre-commit is required but not found, please follow https://github.com/antonbabenko/pre-commit-terraform#how-to-install)`)
tflint-init:
tflint --init
terrascan-init:
terrascan init
.PHONY : clean
## Clean up files
clean:
$(if $(shell find . -type d -name ".terraform" -print0),find . -type d -name ".terraform" -print0 | xargs -0 rm -r,)