Closed aidan-melen closed 3 years ago
I'm not sure if this deserves it's own issue but I find argument parsing of terraform-docs
broken in general.
I suspect this issue is of parsing arguments is related to the usage of https://github.com/agriffis/pure-getopt/ in lib_getopt
file. After reading some SO posts it says that normal getopts
stops parsing arguments after the first non-option
argument. And since terraform-docs
are using sub-commands
which are non-option
arguments getopt
or any other version of it is probably confused.
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.43.0
hooks:
- id: terraform_docs
args:
- '--args=--hide-all'
The above snippet only works because --hide-all
is a global argument.
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.43.0
hooks:
- id: terraform_docs
args:
- '--args=md document
Neither this
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.43.0
hooks:
- id: terraform_docs
args:
- 'md --indent=3 document'
While these 2 do not work because md
and document
are sub-commands (non-option arguments)
This issue also prevents more granular configuration of terraform-docs
without its config file.
So the challenge left here is to separate .tf
files from a string like this --hide-all md document main.tf output.tf
into
args --hide-all md document
and files main.tf output.tf
(which is basically what parse_cmdline_
is trying to do)
Bug for docker image confirmed
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.50.0
hooks:
- id: terraform_docs
language: docker_image
entry: quay.io/terraform-docs/terraform-docs:0.15.0
The good news is that pre-commit-terraform
with locally installed terraform-docs
work fine.
$ terraform-docs -v
terraform-docs version v0.15.0 f3b6eab linux/amd64
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.50.0
hooks:
- id: terraform_docs
Looks like there are 2 issues.
First - #155 (introduce breaking-changes)
Second - not supported docker_image
at all. Need to check after fix first issue
Tools versions used for the tests:
pre-commit 2.15.0
Terraform v1.0.8
Python 3.8.5
Python 3.8.5
checkov 2.0.395
terraform-docs version v0.15.0 f3b6eab linux/amd64
terragrunt SKIPPED
terrascan version: v1.10.0
TFLint version 0.32.1
+ ruleset.aws (0.7.2)
tfsec 0.58.6
The first example now not works during hide-all
option was removed from terraform_docs
config
The second example has problems, see usage examples
The third example works fine, as expected.
Looks like there are 2 issues. First - #155 (introduce breaking-changes) Second - not supported docker_image at all. Need to check after fix first issue
The first issue was effectively fixed.
The second issue is related to use terraform_docs as docker image, I'm right @aidan-melen?
docker_image
option works only for local hooks.
So, I propose to use a fully Dockerized pre-commit-terraform or setup repo local hook
Related: https://github.com/terraform-docs/terraform-docs/issues/324
PASS
result
FAIL
result
FAIL
result
context
The maintainers of
terraform-docs
upgraded the cli to use the popular cobra package in versionv0.10.0
and for some reason -- that change did not play nice with the terraform_doc.sh. I don't think the new release ofterraform-docs
is the issue because when I run it natively I don't run into any issues e.g.