Skip to content

Commit

Permalink
feat(terraform-doc): add flag to set custom file header on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu committed Jan 15, 2025
1 parent fc53d0a commit 588842e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ Unlike most other hooks, this hook triggers once if there are any changed files
- --hook-config=--custom-marker-end # String. Defaults to "<!-- END_TF_DOCS -->" (v1.93+), "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" (<v1.93).
# Set to use custom marker which helps you with using other formats like asciidoc.
# For Asciidoc this could be "--hook-config=--custom-marker-end=// END_TF_DOCS"
- --hook-config=--custom-doc-header # String. Defaults to "# "
# Set to use custom marker which helps you with using other formats like asciidoc.
# For Asciidoc this could be "--hook-config=--custom-marker-end=\= "
```

4. If you want to use a terraform-docs config file, you must supply the path to the file, relative to the git repo root path:
Expand Down
7 changes: 6 additions & 1 deletion hooks/terraform_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readonly SCRIPT_DIR

insertion_marker_begin="<!-- BEGIN_TF_DOCS -->"
insertion_marker_end="<!-- END_TF_DOCS -->"
doc_header="# "

# Old markers used by the hook before the introduction of the terraform-docs markers
readonly old_insertion_marker_begin="<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->"
Expand Down Expand Up @@ -123,6 +124,10 @@ function terraform_docs {
insertion_marker_end=$value
common::colorify "yellow" "INFO: --custom-marker-end is used and the marker is set to \"$value\"."
;;
--custom-doc-header)
doc_header=$value
common::colorify "yellow" "INFO: --custom-doc-header is used and the marker is set to \"$value\"."
;;
esac
done

Expand Down Expand Up @@ -206,7 +211,7 @@ function terraform_docs {

# Use of insertion markers, where there is no existing README file
{
echo -e "# ${PWD##*/}\n"
echo -e "${doc_header}${PWD##*/}\n"
echo "$insertion_marker_begin"
echo "$insertion_marker_end"
} >> "$output_file"
Expand Down

0 comments on commit 588842e

Please sign in to comment.