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

Ability to use -chdir=DIR with tf validate and tf fmt #106

Open
lexicalunit opened this issue Nov 23, 2023 · 1 comment
Open

Ability to use -chdir=DIR with tf validate and tf fmt #106

lexicalunit opened this issue Nov 23, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@lexicalunit
Copy link

Describe the solution you'd like
I need to be able to set the dir via the global terraform argument -chdir=... before running validate:

repos:
- repo: https://github.com/gruntwork-io/pre-commit
  rev: v0.1.23
  hooks:
      - id: terraform-validate
        args: [-chdir=whatever]

However, what the above configuration actually does is attempt to pass -chidr=whatever to the validate subcommand. In other words, it executes this:

terraform validate -chdir=whatever

But that's an error because -chdir is not a valid argument for terraform validate.

What I need is a way to execute this:

terraform -chdir=whatever validate

Describe alternatives you've considered
I haven't found a way to set the working directory via some other means.

@lexicalunit lexicalunit added the enhancement New feature or request label Nov 23, 2023
@lexicalunit
Copy link
Author

lexicalunit commented Nov 23, 2023

A workaround I found was to use the entry option and passing a short script to /bin/sh. I could have also passed something like terraform -chdir=/path/to/dir validate to the shell, either way is fine 🤷🏻‍♀️

repos:
- repo: https://github.com/gruntwork-io/pre-commit
  rev: v0.1.23
  hooks:
      - id: terraform-validate
        name: terraform validate
        entry: /bin/sh -c 'cd /path/to/dir && terraform validate'

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

No branches or pull requests

1 participant