We use Terraspace instead of native Terraform. This gives us the ability to use generic configurations that are made available to all of our stacks, from a single source: /config/terraform/<file_name>.tf. In this folder we have a common.tf with a bunch of locals that have their value generated by Terraspace upon initialization, and then referenced in our various stacks; those locals are ignored by tflint and instead we have hundreds of Error: Reference to undeclared local value errors when running tflint when executing our pre-commit hooks.
I've tried looking at a rule that we could disable for this, but I can't find anything.
I had previously opened an issue when Hashicorp updated their VSCode extension, which started flagging the same thing as errors everywhere. They said we could disable something called "Enhanced Validation", which when we did started working properly, REF: https://github.com/hashicorp/vscode-terraform/issues/1584
But around the same time as the extension starting throwing the errors, we had to disable our tflint pre-commit hook because it would always return the above-mentioned hundreds of errors.
Terraform validate with tflint...........................................Failed
- hook id: terraform_tflint
- exit code: 1
Command 'tflint --init' successfully done:
Plugin "azurerm" is already installed
TFLint in app/stacks/cbc-profilage/:
Failed to prepare rule checking; main.tf:5,17-34: Reference to undeclared local value; A local value with the name "environment" has not been declared., and 8 other diagnostic(s):
Error: Reference to undeclared local value
on main.tf line 5, in module "resource_group":
5: environment = local.environment
A local value with the name "environment" has not been declared.
TFLint validates Terraform modules. If you use another tool that takes some other input and turns it into valid Terraform modules, TFLint is inherently not going to handle that. This is not a bug.
Summary
We use Terraspace instead of native Terraform. This gives us the ability to use generic configurations that are made available to all of our stacks, from a single source:
/config/terraform/<file_name>.tf
. In this folder we have acommon.tf
with a bunch oflocals
that have their value generated by Terraspace upon initialization, and then referenced in our various stacks; thoselocals
are ignored bytflint
and instead we have hundreds ofError: Reference to undeclared local value
errors when runningtflint
when executing our pre-commit hooks.I've tried looking at a rule that we could disable for this, but I can't find anything.
I had previously opened an issue when Hashicorp updated their VSCode extension, which started flagging the same thing as errors everywhere. They said we could disable something called "Enhanced Validation", which when we did started working properly, REF: https://github.com/hashicorp/vscode-terraform/issues/1584
But around the same time as the extension starting throwing the errors, we had to disable our
tflint
pre-commit hook because it would always return the above-mentioned hundreds of errors.Command
tflint --config=GIT_WORKING_DIR/.tflint.hcl
Terraform Configuration
TFLint Configuration
Output
TFLint Version
0.50.1
Terraform Version
1.8.4
Operating System