-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
68 lines (62 loc) · 2.35 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
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TF_EXAMPLES = $(sort $(dir $(wildcard $(CURRENT_DIR)examples/*/)))
help:
@echo "lint Static source code analysis"
@echo "test Integration tests"
lint:
@# Lint all Terraform files
@echo "################################################################################"
@echo "# Terraform fmt"
@echo "################################################################################"
@if docker run -it --rm -v "$(CURRENT_DIR):/t:ro" --workdir "/t" hashicorp/terraform:light \
fmt -check=true -diff=true -write=false -list=true .; then \
echo "OK"; \
else \
echo "Failed"; \
exit 1; \
fi;
@echo
test:
@$(foreach example,\
$(TF_EXAMPLES),\
DOCKER_PATH="/t/examples/$(notdir $(patsubst %/,%,$(example)))"; \
echo "################################################################################"; \
echo "# Terraform init: $${DOCKER_PATH}"; \
echo "################################################################################"; \
if docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" hashicorp/terraform:light \
init \
-verify-plugins=true \
-lock=false \
-upgrade=true \
-reconfigure \
-input=false \
-get-plugins=true \
-get=true \
.; then \
echo "OK"; \
else \
echo "Failed"; \
docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:light -rf .terraform/ || true; \
exit 1; \
fi; \
echo; \
)
@$(foreach example,\
$(TF_EXAMPLES),\
DOCKER_PATH="/t/examples/$(notdir $(patsubst %/,%,$(example)))"; \
echo "################################################################################"; \
echo "# Terraform validate: $${DOCKER_PATH}"; \
echo "################################################################################"; \
if docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" hashicorp/terraform:light \
validate \
-check-variables=true \
.; then \
echo "OK"; \
docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:light -rf .terraform/ || true; \
else \
echo "Failed"; \
docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:light -rf .terraform/ || true; \
exit 1; \
fi; \
echo; \
)