Skip to content

Commit 1bcddf6

Browse files
authored
Merge pull request #33 from cytopia/release-0.18
Release 0.18
2 parents 89c0c46 + 40d6e0f commit 1bcddf6

File tree

106 files changed

+3917
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+3917
-49
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ env:
3737
- VERSION=0.8.0-rc.2
3838
- VERSION=0.8.0-rc.3
3939
- VERSION=0.8.0
40+
- VERSION=0.8.1
4041
- VERSION=latest
4142

4243

Diff for: Dockerfile-0.11

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ COPY --from=builder /usr/local/bin/terraform-docs /usr/local/bin/terraform-docs
6666
COPY ./data/docker-entrypoint-0.11.sh /docker-entrypoint.sh
6767
COPY ./data/terraform-docs.awk /terraform-docs.awk
6868

69-
ENV WORKDIR /data
7069
WORKDIR /data
7170

7271
CMD ["terraform-docs", "--version"]

Diff for: Dockerfile-0.12

-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ RUN set -x \
2424
# Build terraform-docs latest
2525
&& if [ "${VERSION}" = "latest" ]; then \
2626
go get github.com/mitchellh/gox \
27-
&& make test \
2827
&& make build-all GOOS=linux GOARCH=amd64 \
2928
&& mv bin/terraform-docs-${VERSION}-linux-amd64 /usr/local/bin/terraform-docs; \
3029
# Build terraform-docs 0.8.0-rc.1 and above
3130
else \
3231
go get github.com/mitchellh/gox \
33-
&& make test \
3432
&& make build-all GOOS=linux GOARCH=amd64 \
3533
&& mv bin/terraform-docs-${VERSION}-linux-amd64 /usr/local/bin/terraform-docs; \
3634
fi \
@@ -53,7 +51,6 @@ LABEL \
5351
COPY --from=builder /usr/local/bin/terraform-docs /usr/local/bin/terraform-docs
5452
COPY ./data/docker-entrypoint-0.12.sh /docker-entrypoint.sh
5553

56-
ENV WORKDIR /data
5754
WORKDIR /data
5855

5956
CMD ["terraform-docs", "--version"]

Diff for: Makefile

+79-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ifneq (,)
22
.error This Makefile requires GNU Make.
33
endif
44

5-
.PHONY: build rebuild lint test _test-version _test-run-one _test-run-two tag pull login push enter
5+
.PHONY: build rebuild lint test _test-version _test-run-generate-one _test-run-generate-two _test-run-replace-one _test-run-replace-two tag pull login push enter
66

77
# --------------------------------------------------------------------------------------------------
88
# VARIABLES
@@ -64,8 +64,10 @@ lint:
6464
# --------------------------------------------------------------------------------------------------
6565
test:
6666
@$(MAKE) --no-print-directory _test-version
67-
@$(MAKE) --no-print-directory _test-run-one
68-
@$(MAKE) --no-print-directory _test-run-two
67+
@$(MAKE) --no-print-directory _test-run-generate-one
68+
@$(MAKE) --no-print-directory _test-run-generate-two
69+
@$(MAKE) --no-print-directory _test-run-replace-one
70+
@$(MAKE) --no-print-directory _test-run-replace-two
6971

7072
_test-version:
7173
@echo "------------------------------------------------------------"
@@ -94,28 +96,25 @@ _test-version:
9496
fi; \
9597
echo "Success"; \
9698

97-
_test-run-one:
99+
_test-run-generate-one:
98100
@echo "------------------------------------------------------------"
99101
@echo "- Testing terraform-docs (1/2)"
100102
@echo "------------------------------------------------------------"
101-
@echo '<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' > tests/basic/TEST-$(TAG).md
102-
@echo >> tests/basic/TEST-$(TAG).md
103-
@echo '<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' >> tests/basic/TEST-$(TAG).md
104-
@if ! docker run --rm -v $(PWD)/tests/basic:/data $(IMAGE) terraform-docs-replace md TEST-$(TAG).md; then \
103+
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs md /data/output/generate/basic/ > tests/output/generate/basic/TEST-$(TAG).md; then \
105104
echo "Failed"; \
106105
exit 1; \
107106
fi; \
108-
if ! grep '## Inputs' tests/basic/TEST-$(TAG).md; then \
107+
if ! grep '## Inputs' tests/output/generate/basic/TEST-$(TAG).md; then \
109108
echo "Failed"; \
110109
exit 1; \
111110
fi; \
112-
if ! grep 'test description' tests/basic/TEST-$(TAG).md; then \
111+
if ! grep -E '^variable.*$$' tests/output/generate/basic/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/generate/basic/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
113112
echo "Failed"; \
114113
exit 1; \
115114
fi; \
116115
echo "Success";
117116

118-
_test-run-two:
117+
_test-run-generate-two:
119118
@echo "------------------------------------------------------------"
120119
@echo "- Testing terraform-docs (2/2)"
121120
@echo "------------------------------------------------------------"
@@ -130,12 +129,79 @@ _test-run-two:
130129
fi; \
131130
))
132131
@# ---- Test Terraform < 0.12 ----
133-
@if ! docker run --rm -v $(PWD)/tests/default:/data $(IMAGE) terraform-docs-replace $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
132+
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/generate/default/ > tests/output/generate/default/TEST-$(TAG).md; then \
133+
echo "Failed"; \
134+
exit 1; \
135+
fi; \
136+
if ! grep -E '^variable.*$$' tests/output/generate/default/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/generate/default/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
134137
echo "Failed"; \
135138
exit 1; \
136139
fi
137140
@# ---- Test Terraform >= 0.12 ----
138-
@if ! docker run --rm -v $(PWD)/tests/0.12:/data $(IMAGE) terraform-docs-replace-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md TEST-$(TAG).md; then \
141+
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/generate/0.12/ > tests/output/generate/0.12/TEST-$(TAG).md; then \
142+
echo "Failed"; \
143+
exit 1; \
144+
fi; \
145+
if ! grep -E '^variable.*$$' tests/output/generate/0.12/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/generate/0.12/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
146+
echo "Failed"; \
147+
exit 1; \
148+
fi
149+
@echo "Success";
150+
151+
_test-run-replace-one:
152+
@echo "------------------------------------------------------------"
153+
@echo "- Testing terraform-docs-replace (1/2)"
154+
@echo "------------------------------------------------------------"
155+
@echo '<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' > tests/output/replace/basic/TEST-$(TAG).md
156+
@echo >> tests/output/replace/basic/TEST-$(TAG).md
157+
@echo '<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->' >> tests/output/replace/basic/TEST-$(TAG).md
158+
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-replace md /data/output/replace/basic/TEST-$(TAG).md; then \
159+
echo "Failed"; \
160+
exit 1; \
161+
fi; \
162+
if ! grep '## Inputs' tests/output/replace/basic/TEST-$(TAG).md; then \
163+
echo "Failed"; \
164+
exit 1; \
165+
fi; \
166+
if ! grep 'test description' tests/output/replace/basic/TEST-$(TAG).md; then \
167+
echo "Failed"; \
168+
exit 1; \
169+
fi; \
170+
if ! grep -E '^variable.*$$' tests/output/replace/basic/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/replace/basic/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
171+
echo "Failed"; \
172+
exit 1; \
173+
fi; \
174+
echo "Success";
175+
176+
_test-run-replace-two:
177+
@echo "------------------------------------------------------------"
178+
@echo "- Testing terraform-docs-replace (2/2)"
179+
@echo "------------------------------------------------------------"
180+
$(eval TFDOC_ARG_SORT = $(shell \
181+
if [ "$(TAG)" != "0.1.0" ] && [ "$(TAG)" != "0.1.1" ] && [ "$(TAG)" != "0.2.0" ] && [ "$(TAG)" != "0.3.0" ] && [ "$(TAG)" != "0.4.0" ] && [ "$(TAG)" != "0.4.5" ]; then \
182+
echo "--sort-inputs-by-required"; \
183+
fi; \
184+
))
185+
$(eval TFDOC_ARG_AGGREGATE = $(shell \
186+
if [ "$(TAG)" != "0.1.0" ] && [ "$(TAG)" != "0.1.1" ] && [ "$(TAG)" != "0.2.0" ] && [ "$(TAG)" != "0.3.0" ]; then \
187+
echo "--with-aggregate-type-defaults"; \
188+
fi; \
189+
))
190+
@# ---- Test Terraform < 0.12 ----
191+
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-replace $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/replace/default/TEST-$(TAG).md; then \
192+
echo "Failed"; \
193+
exit 1; \
194+
fi; \
195+
if ! grep -E '^variable.*$$' tests/output/replace/default/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/replace/default/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
196+
echo "Failed"; \
197+
exit 1; \
198+
fi
199+
@# ---- Test Terraform >= 0.12 ----
200+
@if ! docker run --rm -v $(PWD)/tests:/data $(IMAGE) terraform-docs-replace-012 $(TFDOC_ARG_SORT) $(TFDOC_ARG_AGGREGATE) md /data/output/replace/0.12/TEST-$(TAG).md; then \
201+
echo "Failed"; \
202+
exit 1; \
203+
fi; \
204+
if ! grep -E '^variable.*$$' tests/output/replace/0.12/main.tf | awk -F'"' '{print $$2}' | xargs -n1 sh -c 'if ! cat tests/output/replace/0.12/TEST-$(TAG).md | sed "s/\\\//g" | grep -E "[[:space:]]$$1[[:space:]]" >/dev/null; then echo "[ERROR] $$1"; false; else echo "[SUCC] $$1"; true; fi' -- ; then \
139205
echo "Failed"; \
140206
exit 1; \
141207
fi; \

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ changes will be introduced).
6464
| Docker tag | Build from docker-terraform-docs | Build from terraform-docs |
6565
|------------|----------------------------------|---------------------------|
6666
| `latest` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Branch: master](https://github.com/segmentio/terraform-docs) |
67+
| `0.8.1` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.1](https://github.com/segmentio/terraform-docs/tree/v0.8.1) |
6768
| `0.8.0` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.0](https://github.com/segmentio/terraform-docs/tree/v0.8.0) |
6869
| `0.8.0-rc.3` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.0-rc.3](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.3) |
6970
| `0.8.0-rc.2` | [Branch: master](https://github.com/cytopia/docker-terraform-docs) | [Tag: v0.8.0-rc.2](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.2) |
@@ -86,6 +87,7 @@ you will have to take care yourself and update your CI tools every time a new ta
8687
| Docker tag | Build from docker-terraform-docs | Build from terraform-docs |
8788
|----------------|----------------------------------|---------------------------|
8889
| `latest-<tag>` | Tag: `<tag>` | [Branch: master](https://github.com/segmentio/terraform-docs) |
90+
| `0.8.1-<tag>` | Tag: `<tag>` | [Tag: v0.8.1](https://github.com/segmentio/terraform-docs/tree/v0.8.1) |
8991
| `0.8.0-<tag>` | Tag: `<tag>` | [Tag: v0.8.0](https://github.com/segmentio/terraform-docs/tree/v0.8.0) |
9092
| `0.8.0-rc.3-<tag>` | Tag: `<tag>` | [Tag: v0.8.0-rc.3](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.3) |
9193
| `0.8.0-rc.2-<tag>` | Tag: `<tag>` | [Tag: v0.8.0-rc.2](https://github.com/segmentio/terraform-docs/tree/v0.8.0-rc.2) |

Diff for: data/docker-entrypoint-0.11.sh

+24-18
Original file line numberDiff line numberDiff line change
@@ -79,41 +79,41 @@ if [ "${#}" -ge "1" ]; then
7979

8080

8181
# Check if file exists
82-
if [ ! -f "${WORKDIR}/${MY_FILE}" ]; then
83-
>&2 echo "Error, ${MY_FILE} not found in: ${WORKDIR}/${MY_FILE}"
82+
if [ ! -f "${MY_FILE}" ]; then
83+
>&2 echo "Error, File not found in: ${MY_FILE}"
8484
exit 1
8585
fi
8686
# Check if starting delimiter exists in file
87-
if ! grep -Fq "${DELIM_START}" "${WORKDIR}/${MY_FILE}"; then
87+
if ! grep -Fq "${DELIM_START}" "${MY_FILE}"; then
8888
>&2 echo "Error, Starting delimiter not found ${MY_FILE}: '${DELIM_START}'"
8989
exit 1
9090
fi
9191
# Check if closint delimiter exists in file
92-
if ! grep -Fq "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}"; then
92+
if ! grep -Fq "${DELIM_CLOSE}" "${MY_FILE}"; then
9393
>&2 echo "Error, Closing delimiter not found ${MY_FILE}: '${DELIM_CLOSE}'"
9494
exit 1
9595
fi
9696

9797
# Get owner and permissions of current file
98-
UID="$(stat -c %u "${WORKDIR}/${MY_FILE}")"
99-
GID="$(stat -c %g "${WORKDIR}/${MY_FILE}")"
100-
PERM="$(stat -c %a "${WORKDIR}/${MY_FILE}")"
98+
UID="$(stat -c %u "${MY_FILE}")"
99+
GID="$(stat -c %g "${MY_FILE}")"
100+
PERM="$(stat -c %a "${MY_FILE}")"
101101

102102
# Terraform < 0.12
103103
if [ "${1}" = "terraform-docs-replace" ]; then
104104
# Remove first argument "replace"
105105
shift;
106106
# Get terraform-docs output
107-
>&2 echo "terraform-docs ${*} ${WORKDIR}"
108-
DOCS="$(terraform-docs "${@}" "${WORKDIR}")"
107+
>&2 echo "terraform-docs ${*} $(dirname "${MY_FILE}")"
108+
DOCS="$(terraform-docs "${@}" "$(dirname "${MY_FILE}")")"
109109
# Terraform >= 0.12
110110
else
111111
# Remove first argument "replace"
112112
shift;
113113
mkdir -p /tmp-012
114-
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"
114+
awk -f /terraform-docs.awk -- "$(dirname "${MY_FILE}")/"*.tf > "/tmp-012/tmp.tf"
115115
# Get terraform-docs output
116-
>&2 echo "terraform-docs-012 ${*} ${WORKDIR}"
116+
>&2 echo "terraform-docs-012 ${*} $(dirname "${MY_FILE}")"
117117
if ! DOCS="$(terraform-docs "${@}" "/tmp-012")"; then
118118
cat -n "/tmp-012/tmp.tf" >&2
119119
exit 1
@@ -122,16 +122,16 @@ if [ "${#}" -ge "1" ]; then
122122

123123
# Create temporary README.md
124124
mkdir -p /tmp
125-
grep -B 100000000 -F "${DELIM_START}" "${WORKDIR}/${MY_FILE}" > /tmp/README.md
125+
grep -B 100000000 -F "${DELIM_START}" "${MY_FILE}" > /tmp/README.md
126126
printf "%s\\n\\n" "${DOCS}" >> /tmp/README.md
127-
grep -A 100000000 -F "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}" >> /tmp/README.md
127+
grep -A 100000000 -F "${DELIM_CLOSE}" "${MY_FILE}" >> /tmp/README.md
128128

129129
# Adjust permissions of temporary file
130130
chown "${UID}:${GID}" /tmp/README.md
131131
chmod "${PERM}" /tmp/README.md
132132

133133
# Overwrite existing file
134-
mv -f /tmp/README.md "${WORKDIR}/${MY_FILE}"
134+
mv -f /tmp/README.md "${MY_FILE}"
135135
exit 0
136136

137137
###
@@ -141,19 +141,25 @@ if [ "${#}" -ge "1" ]; then
141141

142142
# Terraform < 0.12
143143
if [ "${1}" = "terraform-docs" ]; then
144+
>&2 echo "${*}"
144145
exec "${@}"
145146

146147
# Terraform >= 0.12
147148
else
148-
mkdir -p /tmp-012
149-
awk -f /terraform-docs.awk -- *.tf > "/tmp-012/tmp.tf"
150149

151-
# Remove last argument (path)
150+
# Store and Remove last argument (filename)
151+
eval MY_DIR="\${$#}" # store last argument
152152
args="$(trim_last_arg "${@}")" # get all the args except the last arg
153153
eval "set -- ${args}" # update the shell's arguments with the new value
154-
# Remove first argument (terraform-docs-012)
154+
155+
mkdir -p /tmp-012
156+
awk -f /terraform-docs.awk -- "${MY_DIR}/"*.tf > "/tmp-012/tmp.tf"
157+
158+
# Remove first argument
155159
shift
160+
156161
# Execute
162+
>&2 echo "terraform-docs ${*} ${MY_DIR}"
157163
if ! terraform-docs "${@}" "/tmp-012/"; then
158164
cat -n "/tmp-012/tmp.tf" >&2
159165
exit 1

Diff for: data/docker-entrypoint-0.12.sh

+17-13
Original file line numberDiff line numberDiff line change
@@ -81,51 +81,55 @@ if [ "${#}" -ge "1" ]; then
8181

8282

8383
# Check if file exists
84-
if [ ! -f "${WORKDIR}/${MY_FILE}" ]; then
85-
>&2 echo "Error, ${MY_FILE} not found in: ${WORKDIR}/${MY_FILE}"
84+
if [ ! -f "${MY_FILE}" ]; then
85+
>&2 echo "Error, File not found in: ${MY_FILE}"
8686
exit 1
8787
fi
8888
# Check if starting delimiter exists in file
89-
if ! grep -Fq "${DELIM_START}" "${WORKDIR}/${MY_FILE}"; then
89+
if ! grep -Fq "${DELIM_START}" "${MY_FILE}"; then
9090
>&2 echo "Error, Starting delimiter not found ${MY_FILE}: '${DELIM_START}'"
9191
exit 1
9292
fi
9393
# Check if closint delimiter exists in file
94-
if ! grep -Fq "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}"; then
94+
if ! grep -Fq "${DELIM_CLOSE}" "${MY_FILE}"; then
9595
>&2 echo "Error, Closing delimiter not found ${MY_FILE}: '${DELIM_CLOSE}'"
9696
exit 1
9797
fi
9898

9999
# Get owner and permissions of current file
100-
UID="$(stat -c %u "${WORKDIR}/${MY_FILE}")"
101-
GID="$(stat -c %g "${WORKDIR}/${MY_FILE}")"
102-
PERM="$(stat -c %a "${WORKDIR}/${MY_FILE}")"
100+
UID="$(stat -c %u "${MY_FILE}")"
101+
GID="$(stat -c %g "${MY_FILE}")"
102+
PERM="$(stat -c %a "${MY_FILE}")"
103103

104104
# Remove first argument "replace"
105105
shift;
106106
# Get terraform-docs output
107-
>&2 echo "terraform-docs ${*} ${WORKDIR}"
108-
DOCS="$(terraform-docs "${@}" "${WORKDIR}")"
107+
>&2 echo "terraform-docs ${*} $(dirname "${MY_FILE}")"
108+
DOCS="$(terraform-docs "${@}" "$(dirname "${MY_FILE}")")"
109109

110110
# Create temporary README.md
111111
mkdir -p /tmp
112-
grep -B 100000000 -F "${DELIM_START}" "${WORKDIR}/${MY_FILE}" > /tmp/README.md
112+
grep -B 100000000 -F "${DELIM_START}" "${MY_FILE}" > /tmp/README.md
113113
printf "%s\\n\\n" "${DOCS}" >> /tmp/README.md
114-
grep -A 100000000 -F "${DELIM_CLOSE}" "${WORKDIR}/${MY_FILE}" >> /tmp/README.md
114+
grep -A 100000000 -F "${DELIM_CLOSE}" "${MY_FILE}" >> /tmp/README.md
115115

116116
# Adjust permissions of temporary file
117117
chown "${UID}:${GID}" /tmp/README.md
118118
chmod "${PERM}" /tmp/README.md
119119

120120
# Overwrite existing file
121-
mv -f /tmp/README.md "${WORKDIR}/${MY_FILE}"
121+
mv -f /tmp/README.md "${MY_FILE}"
122122
exit 0
123123

124124
###
125125
### terraform-docs command
126126
###
127127
elif [ "${1}" = "terraform-docs" ] || [ "${1}" = "terraform-docs-012" ]; then
128-
exec "${@}"
128+
129+
# Remove first argument "replace"
130+
shift
131+
>&2 echo "terraform-docs ${*}"
132+
terraform-docs "${@}"
129133

130134
###
131135
### Unsupported command
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)