Skip to content

Commit 36a99ea

Browse files
authored
Merge pull request #8 from cytopia/release-0.5
terraform-docs 0.12 parsing
2 parents 073c782 + d36b7b4 commit 36a99ea

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ View **[Dockerfile](https://github.com/cytopia/docker-terraform-docs/blob/master
2525
Tiny Alpine-based multistage-build dockerized version of [terraform-docs](https://github.com/segmentio/terraform-docs)<sup>[1]</sup>,
2626
which additionally implements `terraform-docs-replace` allowing you to automatically and safely
2727
replace the `terraform-docs` generated output infile.
28-
Furthermore this implementation is also **Terraform >= 0.12 ready**. See [Generic Usage](#generic) for more details.
28+
Furthermore this implementation is also **Terraform >= 0.12 ready**<sup>[2]</sup>. See [Generic Usage](#generic) for more details.
2929
The image is built nightly against multiple stable versions and pushed to Dockerhub.
3030

31-
<sub>[1] Official project: https://github.com/segmentio/terraform-docs</sub>
31+
* <sub>[1] Official project: https://github.com/segmentio/terraform-docs</sub>
32+
* <sub>[2] Based on an awk script by [cloudposse/build-harness](https://github.com/cloudposse/build-harness/blob/master/bin/terraform-docs.awk)</sub>
3233

3334

3435
## Available Docker image versions

data/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if [ "${#}" -ge "1" ]; then
144144
###
145145
elif [ "${1}" = "terraform-docs-012" ]; then
146146
mkdir -p /tmp-012
147-
awk -f /usr/bin/terraform-docs.awk *.tf > "/tmp-012/tmp.tf"
147+
awk -f /terraform-docs.awk *.tf > "/tmp-012/tmp.tf"
148148

149149
# Remove last argument (path)
150150
args="$(trim_last_arg "${@}")" # get all the args except the last arg

data/terraform-docs.awk

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,49 @@
1010
braceCnt++
1111
}
1212

13-
if ( /\}/ ) {
13+
if ( /\}/ ) {
1414
braceCnt--
1515
}
1616

17+
# [START] variable or output block started
1718
if ($0 ~ /(variable|output) "(.*?)"/) {
19+
# [CLOSE] "default" block
20+
if (blockDefCnt > 0) {
21+
blockDefCnt = 0
22+
}
1823
blockCnt++
1924
print $0
2025
}
2126

27+
# [START] multiline default statement started
2228
if (blockCnt > 0) {
23-
if ($1 == "description") {
29+
if ($1 == "default") {
2430
print $0
31+
if ($NF ~ /[\[\(\{]/) {
32+
blockDefCnt++
33+
blockDefStart=1
34+
}
2535
}
2636
}
2737

28-
if (blockCnt > 0) {
29-
if ($1 == "default") {
30-
if (braceCnt > 1) {
31-
print " default = {}"
32-
} else {
33-
print $0
38+
# [PRINT] single line "description"
39+
if (blockDefCnt == 0) {
40+
if ($1 == "description") {
41+
# [CLOSE] "default" block
42+
if (blockDefCnt > 0) {
43+
blockDefCnt = 0
3444
}
45+
print $0
3546
}
3647
}
3748

49+
# [PRINT] single line "type"
3850
if (blockCnt > 0) {
3951
if ($1 == "type" ) {
52+
# [CLOSE] "default" block
53+
if (blockDefCnt > 0) {
54+
blockDefCnt = 0
55+
}
4056
type=$3
4157
if (type ~ "object") {
4258
print " type = \"object\""
@@ -46,10 +62,20 @@
4662
}
4763
}
4864

65+
# [CLOSE] variable/output block
4966
if (blockCnt > 0) {
5067
if (braceCnt == 0 && blockCnt > 0) {
5168
blockCnt--
5269
print $0
5370
}
5471
}
72+
73+
# [PRINT] Multiline "default" statement
74+
if (blockCnt > 0 && blockDefCnt > 0) {
75+
if (blockDefStart == 1) {
76+
blockDefStart = 0
77+
} else {
78+
print $0
79+
}
80+
}
5581
}

0 commit comments

Comments
 (0)