-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for terraform-docs 0.8.0 with proper support for Terraform 0.12 syntax (bye-bye awk) #85
Added support for terraform-docs 0.8.0 with proper support for Terraform 0.12 syntax (bye-bye awk) #85
Changes from 10 commits
8dbff1a
7f529b1
e962c24
7f739ab
e7a6117
b3258a0
7b73590
2465b56
15c6343
3b85047
f6486eb
5f798cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,14 @@ main() { | |
|
||
local hack_terraform_docs=$(terraform version | head -1 | grep -c 0.12) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not enable @antonbabenko @konstantin-recurly Any thoughts ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. It makes perfect sense to stay compatible for as long as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the logic and added the check for terraform-docs version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are some testing results: terraform-docs version
terraform-docs version v0.0.0- v0.7.0 darwin/amd64 BuildDate: 2019-12-15T00:53:30+0000
❯ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
❯ terraform-docs version
terraform-docs version v0.8.0-rc.2 d52122d darwin/amd64 BuildDate: 2020-01-12T20:38:24+0000
❯ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Failed
hookid: terraform_docs
Files were modified by this hook.
❯ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
❯ terraform-docs version
zsh: command not found: terraform-docs
❯ pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Failed
hookid: terraform_docs
terraform-docs is required |
||
|
||
if [[ "$hack_terraform_docs" == "1" ]]; then | ||
which terraform-docs 2>&1 >/dev/null || ( echo "terraform-docs is required"; exit 1) | ||
local terraform_docs_version=$(terraform-docs version | head -1 | egrep -o "([0-9]{1,}\.)+[0-9]{1,}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can update to use |
||
|
||
if [[ "$(check_terraform_docs_version "$terraform_docs_version")" == "1" ]]; then | ||
|
||
terraform_docs "0" "$args" "$files" | ||
|
||
elif [[ "$hack_terraform_docs" == "1" ]]; then | ||
which awk 2>&1 >/dev/null || ( echo "awk is required for terraform-docs hack to work with Terraform 0.12"; exit 1) | ||
|
||
tmp_file_awk=$(mktemp "${TMPDIR:-/tmp}/terraform-docs-XXXXXXXXXX") | ||
|
@@ -40,6 +47,17 @@ main() { | |
|
||
} | ||
|
||
check_terraform_docs_version() { | ||
readonly currentver="$1" | ||
|
||
requiredver="0.8.0" | ||
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not critical, but try to follow this point from Shell Style Guide by Google - https://google.github.io/styleguide/shell.xml?showone=Test,_%5B_and_%5B%5B#Test,_%5B_and_%5B%5B Please update to use |
||
echo "1" | ||
else | ||
echo "0" | ||
fi | ||
} | ||
|
||
terraform_docs() { | ||
readonly terraform_docs_awk_file="$1" | ||
readonly args="$2" | ||
|
@@ -108,19 +126,14 @@ terraform_docs_awk() { | |
# 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 | ||
|
||
# Script was originally found here: https://github.com/cloudposse/build-harness/blob/master/bin/terraform-docs.awk | ||
|
||
{ | ||
if ( $0 ~ /\{/ ) { | ||
braceCnt++ | ||
} | ||
|
||
if ( $0 ~ /\}/ ) { | ||
braceCnt-- | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# variable|output "..." { | ||
# ---------------------------------------------------------------------------------------------- | ||
|
@@ -142,8 +155,6 @@ terraform_docs_awk() { | |
# Print variable|output line | ||
print $0 | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# default = ... | ||
# ---------------------------------------------------------------------------------------------- | ||
|
@@ -177,8 +188,6 @@ terraform_docs_awk() { | |
} | ||
} | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# type = ... | ||
# ---------------------------------------------------------------------------------------------- | ||
|
@@ -211,7 +220,6 @@ terraform_docs_awk() { | |
} else { | ||
type = $3 | ||
} | ||
|
||
# legacy quoted types: "string", "list", and "map" | ||
if (type ~ /^[[:space:]]*"(.*?)"[[:space:]]*$/) { | ||
print " type = " type | ||
|
@@ -229,8 +237,6 @@ terraform_docs_awk() { | |
blockTypeCnt -= gsub(/\}/, "") | ||
} | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# description = ... | ||
# ---------------------------------------------------------------------------------------------- | ||
|
@@ -240,8 +246,6 @@ terraform_docs_awk() { | |
print $0 | ||
} | ||
} | ||
|
||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# value = ... | ||
# ---------------------------------------------------------------------------------------------- | ||
|
@@ -251,8 +255,6 @@ terraform_docs_awk() { | |
# print $0 | ||
# } | ||
#} | ||
|
||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# Newlines, comments, everything else | ||
# ---------------------------------------------------------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHANGELOG is automatically generated during release from the commit messages which is going to be like the title of this PR.
There is no need to write anything in CHANGELOG.md, because it will be overridden.