tflint: Unknown variable Accessed
Variables are set in var files and those files are specified in tflint.config. Yet, when running the lint, I get:
Evaluation error: 1:3: unknown variable accessed: var.environment
Every time I run the lint, a different variable appears, all of which have been defined inside the vars file. All files are on the same directory.
Configuration file
config { terraform_version = “0.11.2”
aws_credentials = { access_key = “key” secret_key = “secret” region = “us-east-1” }
varfile = [“global.tfvars”, “external.tfvars”] }
Globals - global.tfvars
variable “environment” { description = “Environment” default = “stg” }
Command
$ tflint --config tflint.config --deep *.tf -d
Output:
DEBUG:/loader.go:191 [INFO] Load HCL file: tflint.config
DEBUG:/loader.go:53 [INFO] Load HCL file: tflint.config
DEBUG:/loader.go:120 [INFO] Load environment…
DEBUG:/loader.go:128 [ERROR] open .terraform/environment: no such file or directory
DEBUG:/loader.go:131 [INFO] Load tfstate…
DEBUG:/loader.go:135 [ERROR] stat terraform.tfstate: no such file or directory
DEBUG:/loader.go:141 [INFO] Remote state detected
DEBUG:/loader.go:161 [INFO] Load tfvars…
DEBUG:/loader.go:164 [INFO] Load terraform.tfvars
DEBUG:/loader.go:166 [ERROR] stat terraform.tfvars: no such file or directory
DEBUG:/loader.go:164 [INFO] Load global.tfvars
DEBUG:/loader.go:191 [INFO] Load HCL file: global.tfvars
DEBUG:/loader.go:164 [INFO] Load external.tfvars
DEBUG:/loader.go:191 [INFO] Load HCL file: external.tfvars
DEBUG:/loader.go:191 [INFO] Load HCL file: cluster.tf
DEBUG:/loader.go:53 [INFO] Load HCL file: cluster.tf
Evaluation error: 1:3: unknown variable accessed: var.environment in cluster.tf:41
Terraform plan works perfectly fine, and apply also, the cluster is already built. It’s all the same if I use --deep, or if I don’t.
Also, the same problem presents when giving the var files on the command line: $ tflint --config tflint.config *.tf --var-file=vaglobal.tfvars,external.tfvars -d
Versions
$ tflint --version TFLint version 0.5.4
$ terraform version Terraform v0.11.2
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 22 (13 by maintainers)
I ran into this issue when there are unquoted values in the tfvars file. Ensure all strings, bools and integers are quoted.
I believe this is still a bug though, as things should be allowed to be unquoted in tfvar files
Currently, I’m working on big refactoring to fix this problem #209 Please wait a moment…
It depends on Terraform v0.12 release schedule. All tasks have been completed, but for that reason, I can’t merge #209.
debug run log
This issue can be reproduced by passing an
aws_s3_bucketattribute to a module as an input, e.g.and then inside
./moduleplace a filevars.tfwith the following:In our case we have a hard requirement for the functionality our module provides to use the bucket, so it absolutely must exist already before the module runs. Since modules cannot use
depends_on, we are simulating the dependency relationship by passing in an attribute of the bucket in to the module.