-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.12 support for terraform-docs (#152)
* 0.12 support for terraform-docs * portability fix * fix version check
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# This script converts Terraform 0.12 variables/outputs to something suitable for `terraform-docs` | ||
# As of terraform-docs v0.6.0, HCL2 is not supported. This script is a *dirty hack* to get around it. | ||
# https://github.com/segmentio/terraform-docs/ | ||
# https://github.com/segmentio/terraform-docs/issues/62 | ||
|
||
{ | ||
if ( /\{/ ) { | ||
braceCnt++ | ||
} | ||
|
||
if ( /\}/ ) { | ||
braceCnt-- | ||
} | ||
|
||
if ($0 ~ /(variable|output) "(.*?)"/) { | ||
blockCnt++ | ||
print $0 | ||
} | ||
|
||
if ($1 == "description") { | ||
print $0 | ||
} | ||
|
||
if ($1 == "default") { | ||
if (braceCnt > 1) { | ||
print " default = {}" | ||
} else { | ||
print $0 | ||
} | ||
} | ||
|
||
if ($1 == "type" ) { | ||
type=$3 | ||
if (type ~ "object") { | ||
print " type = \"object\"" | ||
} else { | ||
print " type = \"" $3 "\"" | ||
} | ||
} | ||
|
||
if (braceCnt == 0 && blockCnt > 0) { | ||
blockCnt-- | ||
print $0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
which awk 2>&1 >/dev/null || ( echo "awk not available"; exit 1) | ||
which terraform 2>&1 >/dev/null || ( echo "terraform not available"; exit 1) | ||
which terraform-docs 2>&1 >/dev/null || ( echo "terraform-docs not available"; exit 1) | ||
|
||
if [[ "`terraform version | head -1`" =~ 0\.12 ]]; then | ||
TMP_FILE="$(mktemp /tmp/terraform-docs-XXXXXXXXXX.tf)" | ||
awk -f ${BUILD_HARNESS_PATH}/bin/terraform-docs.awk $2/*.tf > ${TMP_FILE} | ||
terraform-docs $1 ${TMP_FILE} | ||
rm -f ${TMP_FILE} | ||
else | ||
terraform-docs $1 $2 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters