Skip to content

Commit babe2ef

Browse files
author
Benjamin Valiente (Contractor)
committed
fix: discover nested Terraform submodules in the SUBMODULES global
1 parent d0c8edd commit babe2ef

2 files changed

Lines changed: 77 additions & 5 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
MODULEFILES := $(wildcard *.tf)
2+
TFLINTRC ?= ../../.tflint.hcl
3+
TFDOCSRC ?= ../../.terraform-docs.yml
4+
5+
.PHONY: default
6+
default: checkfmt validate docs lint
7+
8+
.PHONY: checkfmt
9+
checkfmt: .fmt
10+
11+
.PHONY: fmt
12+
fmt: $(MODULEFILES)
13+
terraform fmt
14+
@touch .fmt
15+
16+
.PHONY: validate
17+
validate: .validate
18+
19+
.PHONY: docs
20+
docs: README.md
21+
22+
.PHONY: lint
23+
lint: .lint
24+
25+
.lint: $(MODULEFILES) .lintinit
26+
tflint --config=$(TFLINTRC)
27+
@touch .lint
28+
29+
.lintinit: $(TFLINTRC)
30+
tflint --init --config=$(TFLINTRC) --module
31+
@touch .lintinit
32+
33+
README.md: $(MODULEFILES)
34+
terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md
35+
36+
.fmt: $(MODULEFILES)
37+
terraform fmt -check
38+
@touch .fmt
39+
40+
.PHONY: init
41+
init: .init
42+
43+
.init: versions.tf .dependencies
44+
terraform init -backend=false
45+
@touch .init
46+
47+
.validate: .init $(MODULEFILES) $(wildcard *.tf.example)
48+
echo | cat - $(wildcard *.tf.example) > test.tf
49+
if AWS_DEFAULT_REGION=us-east-1 terraform validate; then \
50+
rm test.tf; \
51+
touch .validate; \
52+
else \
53+
rm test.tf; \
54+
false; \
55+
fi
56+
57+
.dependencies: *.tf
58+
@grep -ohE \
59+
"\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \
60+
sed "s/['\"]//" | sort | uniq | \
61+
tee /tmp/initdeps | \
62+
diff -q .dependencies - >/dev/null 2>&1 || \
63+
mv /tmp/initdeps .dependencies
64+
65+
.PHONY: clean
66+
clean:
67+
rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate

‎makefile‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ export TFDOCSRC := $(CURDIR)/.terraform-docs.yml
66

77
SUBMODULES := $(filter-out \
88
%.md,\
9-
$(wildcard \
10-
platform/modules/* \
11-
platform \
12-
aws/*/modules/*\
13-
aws/* \
9+
$(foreach dir,\
10+
$(wildcard \
11+
platform/modules/* \
12+
platform \
13+
aws/*/modules/* \
14+
aws/* \
15+
platform/modules/*/* \
16+
aws/*/modules/*/* \
17+
),\
18+
$(if $(wildcard $(dir)/*.tf),$(dir),)\
1419
)\
1520
)
1621
SUBMODULEMAKEFILES := $(foreach module,$(SUBMODULES),$(module)/makefile)

0 commit comments

Comments
 (0)