-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
141 lines (130 loc) · 4.93 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
.PHONY: help gen lint test _gen-main _gen-examples _gen-modules
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TF_EXAMPLES = $(sort $(dir $(wildcard $(CURRENT_DIR)examples/*/)))
TF_MODULES = $(sort $(dir $(wildcard $(CURRENT_DIR)modules/*/)))
TF_VERSION = 0.11.14
TF_DOCS_VERSION = 0.6.0-0.2
# Adjust your delimiter here or overwrite via make arguments
DELIM_START = <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
DELIM_CLOSE = <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
help:
@echo "gen Generate terraform-docs output and replace in all README.md's"
@echo "lint Static source code analysis"
@echo "test Integration tests"
gen:
@echo "################################################################################"
@echo "# Terraform-docs generate"
@echo "################################################################################"
@$(MAKE) _gen-main
@$(MAKE) _gen-examples
@$(MAKE) _gen-modules
lint:
@# Lint all Terraform files
@echo "################################################################################"
@echo "# Terraform fmt"
@echo "################################################################################"
@if docker run -it --rm -v "$(CURRENT_DIR):/t:ro" --workdir "/t" hashicorp/terraform:$(TF_VERSION) \
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 "# examples/$$( basename $${DOCKER_PATH} )"; \
echo "################################################################################"; \
echo; \
echo "------------------------------------------------------------"; \
echo "# Terraform init"; \
echo "------------------------------------------------------------"; \
if docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
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:$(TF_VERSION) -rf .terraform/ || true; \
exit 1; \
fi; \
echo; \
echo "------------------------------------------------------------"; \
echo "# Terraform validate"; \
echo "------------------------------------------------------------"; \
if docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
validate \
-check-variables=true $(ARGS) \
.; then \
echo "OK"; \
docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:$(TF_VERSION) -rf .terraform/ || true; \
else \
echo "Failed"; \
docker run -it --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:$(TF_VERSION) -rf .terraform/ || true; \
exit 1; \
fi; \
echo; \
)
_gen-main:
@echo "------------------------------------------------------------"
@echo "# Main module"
@echo "------------------------------------------------------------"
@if docker run --rm \
-v $(CURRENT_DIR):/docs \
-e DELIM_START='$(DELIM_START)' \
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
cytopia/terraform-docs:${TF_DOCS_VERSION} \
terraform-docs-replace --sort-inputs-by-required --with-aggregate-type-defaults md README.md; then \
echo "OK"; \
else \
echo "Failed"; \
exit 1; \
fi
_gen-examples:
@$(foreach example,\
$(TF_EXAMPLES),\
DOCKER_PATH="examples/$(notdir $(patsubst %/,%,$(example)))"; \
echo "------------------------------------------------------------"; \
echo "# $${DOCKER_PATH}"; \
echo "------------------------------------------------------------"; \
if docker run --rm \
-v $(CURRENT_DIR):/docs \
-e DELIM_START='$(DELIM_START)' \
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
cytopia/terraform-docs:${TF_DOCS_VERSION} \
terraform-docs-replace --sort-inputs-by-required --with-aggregate-type-defaults md $${DOCKER_PATH}/README.md; then \
echo "OK"; \
else \
echo "Failed"; \
exit 1; \
fi; \
)
_gen-modules:
@$(foreach module,\
$(TF_MODULES),\
DOCKER_PATH="modules/$(notdir $(patsubst %/,%,$(module)))"; \
echo "------------------------------------------------------------"; \
echo "# $${DOCKER_PATH}"; \
echo "------------------------------------------------------------"; \
if docker run --rm \
-v $(CURRENT_DIR):/docs \
-e DELIM_START='$(DELIM_START)' \
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
cytopia/terraform-docs:${TF_DOCS_VERSION} \
terraform-docs-replace --sort-inputs-by-required --with-aggregate-type-defaults md $${DOCKER_PATH}/README.md; then \
echo "OK"; \
else \
echo "Failed"; \
exit 1; \
fi; \
)