From 3a07570ddb9f8e5a6a3d3fd9164ef6ae8694883e Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 12 Nov 2020 05:55:53 -0500 Subject: [PATCH] fix: Correct deprecated parameter to terraform-docs (#156) --- README.md | 6 +++--- pre_commit_hooks/terraform_docs_replace.py | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5647336..03fcf00 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ There are several [pre-commit](https://pre-commit.com/) hooks to keep Terraform | `terraform_validate` | Validates all Terraform configuration files. | | `terraform_docs` | Inserts input and output documentation into `README.md`. Recommended. | | `terraform_docs_without_aggregate_type_defaults` | Inserts input and output documentation into `README.md` without aggregate type defaults. | -| `terraform_docs_replace` | Runs `terraform-docs` and pipes the output directly to README.md | +| `terraform_docs_replace` | Runs `terraform-docs` and pipes the output directly to README.md (requires terraform-docs v0.10.0 or later) | | `terraform_tflint` | Validates all Terraform configuration files with [TFLint](https://github.com/terraform-linters/tflint). | | `terragrunt_fmt` | Rewrites all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) to a canonical format. | | `terragrunt_validate` | Validates all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) | @@ -91,13 +91,13 @@ Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blo ``` if they are present in `README.md`. -1. `terraform_docs_replace` replaces the entire README.md rather than doing string replacement between markers. Put your additional documentation at the top of your `main.tf` for it to be pulled in. The optional `--dest` argument lets you change the name of the file that gets created/modified. +1. `terraform_docs_replace` replaces the entire README.md rather than doing string replacement between markers. Put your additional documentation at the top of your `main.tf` for it to be pulled in. The optional `--dest` argument lets you change the name of the file that gets created/modified. This hook requires terraform-docs v0.10.0 or later. 1. Example: ```yaml hooks: - id: terraform_docs_replace - args: ['--with-aggregate-type-defaults', '--sort-inputs-by-required', '--dest=TEST.md'] + args: ['--sort-by-required', '--dest=TEST.md'] ``` 1. It is possible to pass additional arguments to shell scripts when using `terraform_docs` and `terraform_docs_without_aggregate_type_defaults`. Send pull-request with the new hook if there is something missing. diff --git a/pre_commit_hooks/terraform_docs_replace.py b/pre_commit_hooks/terraform_docs_replace.py index 05fec62..e1777b3 100644 --- a/pre_commit_hooks/terraform_docs_replace.py +++ b/pre_commit_hooks/terraform_docs_replace.py @@ -15,9 +15,14 @@ def main(argv=None): ) parser.add_argument( '--sort-inputs-by-required', dest='sort', action='store_true', + help='[deprecated] use --sort-by-required instead', + ) + parser.add_argument( + '--sort-by-required', dest='sort', action='store_true', ) parser.add_argument( '--with-aggregate-type-defaults', dest='aggregate', action='store_true', + help='[deprecated]', ) parser.add_argument('filenames', nargs='*', help='Filenames to check.') args = parser.parse_args(argv) @@ -35,9 +40,7 @@ def main(argv=None): procArgs = [] procArgs.append('terraform-docs') if args.sort: - procArgs.append('--sort-inputs-by-required') - if args.aggregate: - procArgs.append('--with-aggregate-type-defaults') + procArgs.append('--sort-by-required') procArgs.append('md') procArgs.append("./{dir}".format(dir=dir)) procArgs.append("| sed -e '$ d' -e 'N;/^\\n$/D;P;D'")