Comments (6)
Hi Przemyslaw!
Thanks for opening this issue. Yes, terraform validate
has slightly changed behavior in 0.12.
$ terraform validate -help
...
Validation requires an initialized working directory with any referenced
plugins and modules installed. To initialize a working directory for
validation without accessing any configured remote backend, use:
terraform init -backend=false
To verify configuration in the context of a particular run (a particular
target workspace, operation variables, etc), use the terraform plan
subcommand instead, which includes an implied validation check.
I have not tried to reproduce the issue you are talking about, and I am not sure what we can do with this in this project (and whether we should?).
Please share your ideas.
from pre-commit-terraform.
Greetings,
Sorry to "reopen" this issue after two months. But I ran into kind of same problem today.
I will try to be as explicit as possible so everyone can understand how to reproduce it.
Architecture
.
├── parent_module_1
│ │
│ ├── child_module
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ │
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
│
├── parent_module_2
│ │
│ ├──child_module
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ │
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
│
├── main.tf
├── outputs.tf
└── variables.tf
Problem
If you have a module inside another module and that the modules are all defined with a source type local_path; then the pre-commit terraform validate will not work and return errors.
It is kind of logical since in the documentation of Terraform, it is written that the local_path modules are not really installed.
Of course, I try all the basics, such as terraform get
, terraform init
, terraform init -upgrade
etc...
Errors
Error: Module not installed
on main.tf line 32:
32: module "test" {
This module's local cache directory could not be read. Run "terraform init"
to install all modules required by this configuration.
Suggestion
I discovered that the terraform validate
packaged inside the 0.12.9 version of Terraform is working properly.
If you have any suggestion or workaround to help us with this problem, thank you for sharing them.
from pre-commit-terraform.
This may be a known issue with Terraform. See hashicorp/terraform#21769. Specifically:
With all of this said, we recommend not relying on the directory arguments to these commands in general, because in any configuration that uses path.module and/or path.root it can cause details about the specific system running Terraform to be exposed into the state, making the configuration unportable to run on different systems. By far the most common and recommended way is to cd into the configuration directory and run all commands from there without any overriding path arguments.
Manually, I validated that running terraform validate
works after changing directories:
[AutoScaling]$ terraform validate
Success! The configuration is valid.
[AutoScaling]$ echo $?
0
[AutoScaling]$ cd test/
[test]$ terraform validate
Success! The configuration is valid.
[test]$ echo $?
0
While
[AutoScaling]$ terraform validate test
Error: Module not installed
on test/main.tf line 5:
5: module "autoscaling" {
This module is not yet installed. Run "terraform init" to install all modules
required by this configuration.
[AutoScaling]$ terraform validate test
Error: Module not installed
on test/main.tf line 5:
5: module "autoscaling" {
This module is not yet installed. Run "terraform init" to install all modules
required by this configuration.
from pre-commit-terraform.
So, reading into hashicorp/terraform#21769, running terraform validate
against a subdirectory or module is just not something that is supported. I have to remove this check from my pre-commit configuration for now given the repository structure that I need to support.
Does terraform validate from the root validate all referenced files from submodules? At least variable references, I believe it does.
from pre-commit-terraform.
terraform_validate
hook has been just updated in #100, and v1.29.0 is now released. Please give it a try!
from pre-commit-terraform.
Closing this issue.
I have released an updated version (v1.44.0 ) where terraform_validate
runs terraform init
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
.
from pre-commit-terraform.
Related Issues (20)
- [trivy always recursive] terraform_trivy not excluding paths HOT 4
- [fedora, grep 3.8] grep: warning: stray \ before / HOT 4
- Custom Docker image - Pre-install pre-commit hooks inside image HOT 6
- mapfile: command not found in zsh HOT 4
- Add `terragrunt_providers_lock` hook HOT 11
- terraform_checkov hook fails in Docker container since version v1.83.5 HOT 5
- Checkov install silently fails during image build (and is also missing when pulling from ghcr.io) HOT 4
- Bash environment variable expansion not working for trivy HOT 26
- Provide non-root docker build HOT 4
- terraform validate: Force rerun `t init` when plugin cache is enabled and parrallelism conflit happens HOT 8
- Ability to use terraform_plan framework of checkov HOT 8
- [trivy/pre-commit] Terraform trivy configuration excludes .trivyignore files, forcing repetitive ignore statements HOT 7
- Windows Support / Rewrite hooks to Python HOT 11
- Quotation Marks in Environment Variables HOT 2
- Get docker image running in github action HOT 10
- [tf aws provider version] terraform_validate false negative on `aws_kinesis_firehose_delivery_stream.extended_s3_configuration.file_extension` HOT 3
- Add PATH to terraform_docs HOT 7
- [terraform outdated provider] New Data Source: aws_ecr_lifecycle_policy_document HOT 4
- Remove Political Banners from Repo
- [`trivy:ignore:` usage] Terraform Security Check AVD-AWS-0342 HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pre-commit-terraform.