Skip to content
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

fix: Correctly handle arrays in terraform_docs.sh #141

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v3.2.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -9,7 +9,7 @@ repos:
- id: check-merge-conflict
- id: check-executables-have-shebangs
- repo: git://github.com/jumanjihouse/pre-commit-hooks
rev: 2.0.0
rev: 2.1.4
hooks:
- id: shfmt
args: ['-l', '-i', '2', '-ci', '-sr', '-w']
16 changes: 9 additions & 7 deletions terraform_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eo pipefail
main() {
initialize_
parse_cmdline_ "$@"
terraform_docs_ "$ARGS" "$FILES"
terraform_docs_ "${ARGS[*]}" "${FILES[@]}"
}

initialize_() {
Expand Down Expand Up @@ -48,7 +48,8 @@ parse_cmdline_() {

terraform_docs_() {
local -r args="$1"
local -r files="$2"
shift
local -a -r files=("$@")

local hack_terraform_docs
hack_terraform_docs=$(terraform version | head -1 | grep -c 0.12) || true
Expand All @@ -63,7 +64,7 @@ terraform_docs_() {

if [[ -z "$is_old_terraform_docs" ]]; then # Using terraform-docs 0.8+ (preferred)

terraform_docs "0" "$args" "$files"
terraform_docs "0" "$args" "${files[@]}"

elif [[ "$hack_terraform_docs" == "1" ]]; then # Using awk script because terraform-docs is older than 0.8 and terraform 0.12 is used

Expand All @@ -75,27 +76,28 @@ terraform_docs_() {
local tmp_file_awk
tmp_file_awk=$(mktemp "${TMPDIR:-/tmp}/terraform-docs-XXXXXXXXXX")
terraform_docs_awk "$tmp_file_awk"
terraform_docs "$tmp_file_awk" "$args" "$files"
terraform_docs "$tmp_file_awk" "$args" "${files[@]}"
rm -f "$tmp_file_awk"

else # Using terraform 0.11 and no awk script is needed for that

terraform_docs "0" "$args" "$files"
terraform_docs "0" "$args" "${files[@]}"

fi
}

terraform_docs() {
local -r terraform_docs_awk_file="$1"
local -r args="$2"
local -r files="$3"
shift 2
local -a -r files=("$@")

declare -a paths
declare -a tfvars_files

local index=0
local file_with_path
for file_with_path in $files; do
for file_with_path in "${files[@]}"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"

paths[index]=$(dirname "$file_with_path")
Expand Down