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

Validate & linting doesn't work for projects with sub-directories #87

Closed
zacharyabresch opened this issue Jan 24, 2020 · 14 comments
Closed

Comments

@zacharyabresch
Copy link

I'm sad to be posting this because I've been struggling for days to get these simple pre-commit hooks to work. So far, the only one I've actually gotten functional is terraform_fmt. I'm aware of #59 but there's been no response there since October of 2019. Here are some details:

terraform_validate

Fails with several errors:

  • Error: Module not installed
  • Error: provider.aws: no suitable version installed
  • Error: Could not satisfy plugin requirements

All of these are basically indicating the same thing, init has not been run in the sub-directory. There are a few problems with this:

  1. init has indeed been run in each of these sub-directories but the pre-commit hook (or perhaps Terraform) doesn't seem to be aware
  2. Running terraform validate from the project root directory succeeds without error

What is the pre-commit hook doing that the CLI command isn't (or vice-versa)?

terraform_tflint

I see several variations of the following error:

  • ERROR: unable to resolve endpoint for service "ecs", region "", err: UnknownEndpointError: could not resolve endpoint (replace ecs with any other service we're using)
  • also: Error: An error occurred while invoking DescribeSecurityGroups; MissingRegion: could not find region configuration

Now, running tflint --deep --module returns one error (the first one detailed above) so this is also probably an issue with that tool but ... is no one else using sub-directories? I find that incredibly hard to believe.

So, in the end, the only pre-commit hook I've gotten to work is terraform_fmt. Kind of disappointing as I've been extolling the value of validating & linting but am unable to deliver a working MVP to prove it due to the above problems.

Has anyone experienced these pains? Are there any workarounds or fixes for the above issues? Any advice at all? Thanks for your time & effort.

@antonbabenko
Copy link
Owner

Hi @zacharyabresch !

v1.25.0 of pre-commit-terraform has been just released after #77 was merged. This should make terraform_tflint usable for you. Check comments for passing arguments in #76 for some examples.

@tpdownes
Copy link

I am using v1.25.0 and, outwardly, it looks the issue still exists for that. I think the CWD of the terraform validate command has to be the subdirectory and I'm guessing that ins't how it is exec'd within the shell script that implements the hook.

@zacharyabresch
Copy link
Author

I finally got a chance to hook this up and tflint worked flawlessly this time. Thanks for the update and effort!

@barryib
Copy link
Contributor

barryib commented Mar 9, 2020

@zacharyabresch can we close this issue ?

@antonbabenko
Copy link
Owner

terraform_validate hook has been just updated in #100, and v1.29.0 is now released. Please give it a try!

@ghostsquad
Copy link

I don't think this is fixed. I just installed v1.29.0 and I'm seeing lots of:

Error: Module not installed

for terraform validate

@nidr0x
Copy link

nidr0x commented May 7, 2020

@ghostsquad Same behaviour in my case

@stevie-
Copy link
Contributor

stevie- commented Aug 25, 2020

It seems that it is required to run terraform init for all sub directory modules. How can we workaround this or pre-execute terraform init automatically?

@yashbhutwala
Copy link

yashbhutwala commented Nov 4, 2020

Ping! Still facing this issue for both terraform_validate and terraform_tflint. Any known workarounds for running terraform init for all sub-directories?

@yashbhutwala
Copy link

I just realized terraform_validate only did not work the first time (when all subfolders had no .terraform folders). It worked after the first time.

@antonbabenko
Copy link
Owner

I have released an updated version (v1.44.0 ) where terraform_validate runs if no .terraform folder found.

See #158 and updated README.md file.

terraform-aws-modules/terraform-aws-lambda#68 - here you can see how I use both terraform_validate and terraform_tflint.

@yashbhutwala
Copy link

To be fair, I was already using v1.44.0 version and still ran into the first time problem.

@antonbabenko
Copy link
Owner

It may be that .terraform folder was not correct. See note in point 3 here.

@ahmad-hamade
Copy link

I would suggest updating the command terraform init here and pass -upgrade=true so it will redownload the plugins again if they are corrupted

init_output=$(terraform init -backend=false -upgrade=true 2>&1)

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

No branches or pull requests

9 participants