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 tfvars hcl does not generate tfvars file #558

Closed
Philbow opened this issue Aug 17, 2023 · 3 comments
Closed

terraform-docs tfvars hcl does not generate tfvars file #558

Philbow opened this issue Aug 17, 2023 · 3 comments
Labels

Comments

@Philbow
Copy link

Philbow commented Aug 17, 2023

Describe the bug

Running terraform-docs does not produce auto generated tfvars files (but indicates success in output)

How can we reproduce it?

.pre-commit-config.yaml

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.82.0
    hooks:
      - id: terraform_docs
        name: Generating / updating terraform.tfvars.auto (terraform_docs)
        args:
          - tfvars hcl --output-file terraform.tfvars.auto .

Trigger container

TAG=v1.82.0
docker run -e "USERID=$(id -u):$(id -g)" -v $(pwd):/lint -w /lint ghcr.io/antonbabenko/pre-commit-terraform:$TAG run -a

Output

    Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
    [INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
    Generating / updating terraform.tfvars.auto (terraform_docs).......................Passed

Directory structure

.
├── README.md
├── bootstrapping_node.puml
├── data.tf
├── locals.tf
├── main.tf
├── outputs.tf
├── precommit.sh   # can be ignored
├── providers.tf
├── templates         # can be ignored
│   ├── metadata.tpl
│   └── userdata.yaml.tpl
└── variables.tf

Additional information

Running terraform-docs binary directly on the same project generates the corresponding file containing all variables (incl. defaults)

terraform-docs tfvars hcl --output-file terraform.tfvars.auto .

Running terraform_docs in .pre-commit-config.yaml to generate markdown works like a charm

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.82.0
    hooks:
      - id: terraform_docs
        name: Generating / updating README.md (terraform_docs)
        args:
          - --hook-config=--create-file-if-not-exist=true
          - --hook-config=--path-to-file=README.md

Environment information

  • OS: Windows 10 (WSL / Podman Desktop)
  • Docker image tag: ghcr.io/antonbabenko/pre-commit-terraform:v1.82.0 (official)
@Philbow Philbow added area/docker bug Something isn't working labels Aug 17, 2023
@MaxymVlasov
Copy link
Collaborator

It is a subset of #179

@MaxymVlasov MaxymVlasov closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
@MaxymVlasov MaxymVlasov added hook/terraform_docs Bash hook and removed bug Something isn't working area/docker labels Aug 17, 2023
@Philbow
Copy link
Author

Philbow commented Aug 18, 2023

@MaxymVlasov : I am not 100% sure why this issue is closed.

Is it because pre-commit-terraform does not support the --output-file parameter?

All other prerequisistes for the linked ticket are already given (terraform-docs uses v0.16.0 and directly executing "terraform-docs tfvars hcl . --output-file test.tfvars" seems to work in the container).

In case this is the issue, may I kindly request to get rid of the official documentation stating the support for tfvars example file generation? This is the corresponding documentation that mentions exactly this command: https://github.com/antonbabenko/pre-commit-terraform/blob/master/README.md?plain=1#L502C14

Side Note / Question
Generation of tfvars files could be also achieved without using the --output-file parameter by piping the stdout to a file.

What I tried was this, but it seems like it is not working (no errors, but file is as well not created). Directly executing the command works fine.

  - id: terraform_docs
    name: Generating / updating terraform.tfvars.auto (terraform_docs)
    args:
      - tfvars hcl . > terraform.tfvars.auto

Any tips on how to get this working?

@MaxymVlasov
Copy link
Collaborator

@MaxymVlasov : I am not 100% sure why this issue is closed.

This issue will be resolved during #179 resolution because that problem goes from unmaintainable logic located somewhere in https://github.com/antonbabenko/pre-commit-terraform/blob/master/hooks/terraform_docs.sh

Any tips on how to get this working?

Feel free to submit PR to make #179 live, that's the only possibility which I see here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants