pre-commit-terraform: Validate & linting doesn't work for projects with sub-directories
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 installedError: provider.aws: no suitable version installedError: 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:
inithas indeed been run in each of these sub-directories but the pre-commit hook (or perhaps Terraform) doesn’t seem to be aware- Running
terraform validatefrom 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(replaceecswith 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.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (6 by maintainers)
It seems that it is required to run
terraform initfor all sub directory modules. How can we workaround this or pre-executeterraform initautomatically?I would suggest updating the command
terraform inithere and pass-upgrade=trueso it will redownload the plugins again if they are corrupted