Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform-docs fail when recursive is activated #380

Closed
ppodevlabs opened this issue May 11, 2022 · 3 comments · Fixed by #381
Closed

terraform-docs fail when recursive is activated #380

ppodevlabs opened this issue May 11, 2022 · 3 comments · Fixed by #381
Assignees
Labels
documentation Improvements or additions to documentation estimate/1h Need 1 hour to be done hook/terraform_docs Bash hook

Comments

@ppodevlabs
Copy link

Describe the bug

My repository looks like this

├── README.md
├── backend.tf
├── main.tf
├── modules
 │   └── techdocs
 │       ├── README.md
 │       ├── main.tf
├── outputs.tf
├── terraform.tfvars
├── variables.tf
└── versions.tf

When running the pre-commit hook using the docker image terraform-docs fails stating:

Error: stat modules: no such file or directory

Tested in MacOs and linux

How can we reproduce it?

#terraform docs config file
formatter: "md doc" 
version: ">= 0.13.0, < 1.0.0"

header-from: main.tf

recursive:
  enabled: true

output:
  file: "README.md"
  mode: inject
  template: |-
    <!-- BEGIN_TF_DOCS -->
    {{ .Content }}
    <!-- END_TF_DOCS -->

output-values:
  enabled: false
  from: ""

sort:
  enabled: true
  by: name

settings:
  anchor: true
  color: true
  default: true
  description: false
  escape: true
  hide-empty: false
  html: true
  indent: 2
  lockfile: true
  read-comments: true
  required: true
  sensitive: true
  type: true
docker run --rm -v $(pwd):/lint -w /lint ghcr.io/antonbabenko/pre-commit-terraform:v1.71.0 run -a

Environment information

  • OS:
    OS: MacOS

  • docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2)
  compose: Docker Compose (Docker Inc., v2.5.0)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 30
  Running: 1
  Paused: 0
  Stopped: 29
 Images: 18
 Server Version: 20.10.14
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.104-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.675GiB
 Name: docker-desktop
 ID: ZGLM:IVTP:VB43:VC7R:UK4A:7WXL:X2LT:L356:D4YG:J6AF:GWT4:JDCC
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false
  • Docker image tag/git commit: ghcr.io/antonbabenko/pre-commit-terraform:v1.71.0

  • Tools versions. Don't forget to specify right tag in command -
    TAG=latest && docker run --entrypoint cat pre-commit:$TAG /usr/bin/tools_versions_info

INSERT_OUTPUT_HERE
  • .pre-commit-config.yaml:
repos:
- repo: https://github.com/gruntwork-io/pre-commit
  rev: v0.1.17
  hooks:
    - id: terraform-validate
    - id: tflint
      args:
        - "--module"
        - "--config=.tflint.hcl"
- repo: https://github.com/antonbabenko/pre-commit-terraform
  rev: v1.71.0
  hooks:
    - id: terraform_fmt
    - id: terraform_tfsec
    - id: terraform_docs
      args:
        - --args=--config=.tfdocs-config.yaml
    - id: terraform_checkov
      args:
        - --args=--quiet
        - --args=--skip-check CKV_AWS_144 --skip-check CKV_AWS_19
@ppodevlabs ppodevlabs added area/docker bug Something isn't working labels May 11, 2022
@MaxymVlasov MaxymVlasov added documentation Improvements or additions to documentation hook/terraform_docs Bash hook estimate/1h Need 1 hour to be done and removed bug Something isn't working area/docker labels May 11, 2022
@MaxymVlasov
Copy link
Collaborator

That's expected.

Don't use recursive with pre-commit hooks, because that violates how pre-commit should work.

Also, the section below could conflict with terraform_docs hook.

output:
  file: "README.md"
  mode: inject
  template: |-
    <!-- BEGIN_TF_DOCS -->
    {{ .Content }}
    <!-- END_TF_DOCS -->

When that hook was wroten, terraform-docs configs were not available/not widely used, so all settings in hook sets in .pre-commit-config.yaml, check https://github.com/antonbabenko/pre-commit-terraform#terraform_docs

I think this issue relates to #179

@ppodevlabs
Copy link
Author

That's expected.

Don't use recursive with pre-commit hooks, because that violates how pre-commit should work.

Also, the section below could conflict with terraform_docs hook.

output:
  file: "README.md"
  mode: inject
  template: |-
    <!-- BEGIN_TF_DOCS -->
    {{ .Content }}
    <!-- END_TF_DOCS -->

When that hook was wroten, terraform-docs configs were not available/not widely used, so all settings in hook sets in .pre-commit-config.yaml, check https://github.com/antonbabenko/pre-commit-terraform#terraform_docs

I think this issue relates to #179

Then i think then point 4 in https://github.com/antonbabenko/pre-commit-terraform#terraform_docs should be modify as it states

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:

@antonbabenko
Copy link
Owner

This issue has been resolved in version 1.72.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation estimate/1h Need 1 hour to be done hook/terraform_docs Bash hook
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants