terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.96k stars 357 forks source link

invalid variable definition does not use selected output format #1437

Closed dwardu89 closed 2 years ago

dwardu89 commented 2 years ago

Introduction

Please share the bug summary and assumptions first. I am trying to get the compact output to output correctly, i am using the stock configuration found in the documentation.

// Write code here
variable "test" {
  type = number
  default = "asdas"
}

Expected Behavior

Under the above assumptions, please explain what you expect and what you do.

Error format thats expected

// Write output or debug log
test.tf:1:1: Error - test (test_rule) 

Actual behavior

// Write output or debug log
TFLINT_LOG=DEBUG tflint -f compact terraform | pbcopy
14:26:44 config.go:115: [INFO] Load config: .tflint.hcl
14:26:44 config.go:242: [DEBUG] Config loaded
14:26:44 config.go:243: [DEBUG]   Module: true
14:26:44 config.go:244: [DEBUG]   Force: false
14:26:44 config.go:245: [DEBUG]   IgnoreModules:
14:26:44 config.go:249: [DEBUG]   Varfiles: terraform/backend.tfvars, terraform/terraform.tfvars
14:26:44 config.go:250: [DEBUG]   Variables: 
14:26:44 config.go:251: [DEBUG]   DisabledByDefault: false
14:26:44 config.go:252: [DEBUG]   PluginDir: ~/.tflint.d/plugins
14:26:44 config.go:253: [DEBUG]   Format: compact
14:26:44 config.go:254: [DEBUG]   Rules:
14:26:44 config.go:256: [DEBUG]     aws_instance_invalid_type: false
14:26:44 config.go:258: [DEBUG]   Plugins:
14:26:44 config.go:260: [DEBUG]     aws: enabled=true, version=0.15.0, source=github.com/terraform-linters/tflint-ruleset-aws
14:26:44 option.go:49: [DEBUG] CLI Options
14:26:44 option.go:50: [DEBUG]   Module: false
14:26:44 option.go:51: [DEBUG]   Force: false
14:26:44 option.go:52: [DEBUG]   IgnoreModules:
14:26:44 option.go:56: [DEBUG]   EnableRules: 
14:26:44 option.go:57: [DEBUG]   DisableRules: 
14:26:44 option.go:58: [DEBUG]   Only: 
14:26:44 option.go:59: [DEBUG]   EnablePlugins: 
14:26:44 option.go:60: [DEBUG]   Varfiles: 
14:26:44 option.go:61: [DEBUG]   Variables: 
14:26:44 option.go:62: [DEBUG]   Format: compact
14:26:44 loader.go:57: [INFO] Initialize new loader
14:26:44 loader.go:82: [INFO] Load configurations under terraform
14:26:44 loader.go:85: [ERROR] terraform/variables.tf:45,13-20: Invalid default value for variable; This default value is not compatible with the variable's type constraint: a number is required.
Failed to load configurations; terraform/variables.tf:45,13-20: Invalid default value for variable; This default value is not compatible with the variable's type constraint: a number is required.:

Error: Invalid default value for variable

  on terraform/variables.tf line 45, in variable "test":
  45:   default = "asdas"

This default value is not compatible with the variable's type constraint: a number is required.

Step to Reproduce

Create a variable with the following value. This is obviously an error, however tflint doesnt output it as the correct error

// Write code here

variable "test" {
  type = number
  default = "asdas"
}

Additional Context

Example:

$ tflint -v
TFLint version 0.38.1
+ ruleset.aws (0.15.0)
$ terraform -v
Terraform v1.2.3
on darwin_amd64
dwardu89 commented 2 years ago

irrespective if my terraform is at the root or in the terraform/ directory. The same problem happens.

bendrucker commented 2 years ago

None of the mentioned factors are influencing the behavior here. The variable definition is invalid.

See https://github.com/terraform-linters/tflint/issues/1163 for discussion of how this works currently.

Invalid configuration is not reported as part of the formatted issue list, it is treated as a generic error.