Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suport for terraform-docs mode: replace
Browse files Browse the repository at this point in the history
MaxymVlasov committed Aug 29, 2024

Verified

This commit was signed with the committer’s verified signature.
MaxymVlasov Maksym Vlasov
1 parent de61221 commit b5143bd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion hooks/terraform_docs.sh
Original file line number Diff line number Diff line change
@@ -200,6 +200,16 @@ function terraform_docs {
text_file=$output_file
fi

# Use `.terraform-docs.yml` `output.mode` if it set
local output_mode
output_mode=$(grep -A1000 -e '^output:$' "$config_file" | grep -E '^[[:space:]]+mode:' | tail -n 1) || true
if [[ $output_mode ]]; then
# Extract mode from `output.mode` line
output_mode=$(echo "$output_mode" | awk -F':' '{print $2}' | tr -d '[:space:]"' | tr -d "'")
else
output_mode="inject"
fi

# Suppress terraform_docs color
local config_file_no_color
config_file_no_color="$config_file$(date +%s).yml"
@@ -265,7 +275,7 @@ function terraform_docs {

if [[ "$terraform_docs_awk_file" == "0" ]]; then
# shellcheck disable=SC2086
terraform-docs --output-mode inject $tf_docs_formatter $args --output-file="$text_file" ./ > /dev/null
terraform-docs --output-mode="$output_mode" --output-file="$text_file" $tf_docs_formatter $args ./ > /dev/null
else
# Can't append extension for mktemp, so renaming instead
local tmp_file_docs

0 comments on commit b5143bd

Please sign in to comment.