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

Support tflint modules with differing module dependencies #534

Open
davidjb opened this issue Jun 20, 2023 · 5 comments
Open

Support tflint modules with differing module dependencies #534

davidjb opened this issue Jun 20, 2023 · 5 comments
Labels
estimate/4h Need 4 hours to be done feature New feature or request good first issue Good for newcomers hook/terraform_providers_lock Bash hook hook/terraform_tflint Bash hook

Comments

@davidjb
Copy link

davidjb commented Jun 20, 2023

What problem are you facing?

In my configuration, I have a number of different modules in the same repo but each module has differing dependencies (either local or published). At present, I'm linting by running cd {dir} && terraform get && tflint for each module directory to ensure all dependencies are available and installed. When trying to use the terraform_tflint hook, it fails for modules with dependencies.

How could pre-commit-terraform help solve your problem?

Have the ability to automatically invoke terraform get per-directory when running the tflint hook, either by default or with a flag. Whilst terraform get is a noop when nothing needs to be done, it still takes time to be invoked so an opt-in hook flag may be the better option.

Happy to help craft a PR if this is something that could be incorporated.

@davidjb davidjb added the feature New feature or request label Jun 20, 2023
@MaxymVlasov
Copy link
Collaborator

MaxymVlasov commented Jun 20, 2023

You can do next as a workaround (because t init took more time than t get)

- id: terraform_validate
  args:
    - --hook-config=--retry-once-with-cleanup=true
    # - --tf-init-args=-upgrade
- id: terraform_tflint
  args:
    - --args=--config=__GIT_WORKING_DIR__/.tflint.hcl

Also, because tflint and t validate can't fully replace each other, it can be a solution, not a temporary workaround

@davidjb
Copy link
Author

davidjb commented Jun 21, 2023

Thanks @MaxymVlasov - I appreciate the workaround. It is fairly slow to re-init Terraform each tune, as you say, especially when multiple modules and configurations are changing in a given commit, but workable for small changes.

@MaxymVlasov
Copy link
Collaborator

Side note: terraform_providers_lock could use t get too, rather depend on terraform_validate

@MaxymVlasov MaxymVlasov added estimate/4h Need 4 hours to be done good first issue Good for newcomers labels Jun 21, 2023
@MaxymVlasov
Copy link
Collaborator

What should be done:

  1. create by analog common::terraform_get function

    function common::terraform_init {

  2. Include it in terraform_tflint by analogue how common::terraform_init used in terraform_validate hook

  3. (Optional) Add it to terraform_providers_lock hook too

@rquadling
Copy link

Not sure if anyone is aware, but TFLint 0.50.0 has some specific changes relating to the handling of modules and has marked that change as a BC (but is documented more like a deprecation notice).

https://github.com/terraform-linters/tflint/releases/tag/v0.50.0

Hopefully, the work undertaken there can be integrated/supported by pre-commit-terraform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
estimate/4h Need 4 hours to be done feature New feature or request good first issue Good for newcomers hook/terraform_providers_lock Bash hook hook/terraform_tflint Bash hook
Projects
None yet
Development

No branches or pull requests

3 participants