Skip to content
Merged
Changes from 4 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
18 changes: 14 additions & 4 deletions hooks/terraform_docs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
set -eo pipefail

# globals variables
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
readonly SCRIPT_DIR
Expand Down Expand Up @@ -88,6 +87,7 @@ function terraform_docs {
local add_to_existing=false
local create_if_not_exist=false
local use_standard_markers=true
local have_config_flag=false

IFS=";" read -r -a configs <<< "$hook_config"

Expand Down Expand Up @@ -142,10 +142,16 @@ function terraform_docs {
local tf_docs_formatter="md"

else

have_config_flag=true
local config_file=${args#*--config}
config_file=${config_file#*=}
config_file=${config_file% *}
# If there are more parameters after config path, trim until --
if [[ $config_file == *" --"* ]]; then
config_file=${config_file%% --*}
fi
# Trim trailing whitespace but preserve internal spaces

config_file="${config_file%"${config_file##*[![:space:]]}"}" args=${args/--config=$config_file/}

# Prioritize `.terraform-docs.yml` `output.file` over
# `--hook-config=--path-to-file=` if it set
Expand Down Expand Up @@ -231,8 +237,12 @@ function terraform_docs {
have_marker=$(grep -o "$insertion_marker_begin" "$output_file") || unset have_marker
[[ ! $have_marker ]] && popd > /dev/null && continue
fi
local config_options=""
if [[ $have_config_flag == true ]]; then
config_options="--config=$config_file"
fi
# shellcheck disable=SC2086
terraform-docs --output-mode="$output_mode" --output-file="$output_file" $tf_docs_formatter $args ./ > /dev/null
terraform-docs --output-mode="$output_mode" --output-file="$output_file" $tf_docs_formatter "$config_options" $args ./ > /dev/null

popd > /dev/null
done
Expand Down
Loading