You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -486,13 +486,21 @@ Unlike most other hooks, this hook triggers once if there are any changed files
486
486
* create a documentation file
487
487
* extend existing documentation file by appending markers to the end of the file (see item 1 above)
488
488
* use different filename for the documentation (default is `README.md`)
489
+
* use the same insertion markers as `terraform-docs` by default. It will be default in `v2.0`.
490
+
To migrate to `terraform-docs` insertion markers, run in repo root:
491
+
492
+
```bash
493
+
grep -rl 'BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i 's/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/BEGIN_TF_DOCS/g'
494
+
grep -rl 'END OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs sed -i 's/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/END_TF_DOCS/g'
495
+
```
489
496
490
497
```yaml
491
498
- id: terraform_docs
492
499
args:
493
500
- --hook-config=--path-to-file=README.md # Valid UNIX path. I.e. ../TFDOC.md or docs/README.md etc.
494
501
- --hook-config=--add-to-existing-file=true # Boolean. true or false
495
502
- --hook-config=--create-file-if-not-exist=true # Boolean. true or false
503
+
- --hook-config=--use-standard-markers=true # Boolean. Defaults in v1.x to false. Set to true for compatibility with terraform-docs
496
504
```
497
505
498
506
4. You can provide [any configuration available in `terraform-docs`](https://terraform-docs.io/user-guide/configuration/) as an argument to `terraform_doc` hook, for example:
echo"<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->">>"$text_file"
200
-
echo"<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->">>"$text_file"
220
+
# Use of insertion markers, where addToExisting=true, with no markers in the existing file
221
+
echo"$insertion_marker_begin">>"$text_file"
222
+
echo"$insertion_marker_end">>"$text_file"
201
223
fi
202
224
fi
203
225
@@ -218,8 +240,10 @@ function terraform_docs {
218
240
rm -f "$tmp_file_docs_tf"
219
241
fi
220
242
243
+
# Use of insertion markers to insert the terraform-docs output between the markers
221
244
# Replace content between markers with the placeholder - https://stackoverflow.com/questions/1212799/how-do-i-extract-lines-between-two-line-delimiters-in-perl#1212834
222
-
perl -i -ne 'if (/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/../END OF PRE-COMMIT-TERRAFORM DOCS HOOK/) { print $_ if /BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/; print "I_WANT_TO_BE_REPLACED\n$_" if /END OF PRE-COMMIT-TERRAFORM DOCS HOOK/;} else { print $_ }'"$text_file"
245
+
perl_expression="if (/$insertion_marker_begin/../$insertion_marker_end/) { print \$_ if /$insertion_marker_begin/; print \"I_WANT_TO_BE_REPLACED\\n\$_\" if /$insertion_marker_end/;} else { print \$_ }"
246
+
perl -i -ne "$perl_expression""$text_file"
223
247
224
248
# Replace placeholder with the content of the file
0 commit comments