terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.86k stars 354 forks source link

rule aws_instance_invalid_type doesn't verify invalid instance types in module block #1241

Closed evairmarinho closed 2 years ago

evairmarinho commented 2 years ago

Context

I have the following scenario:

main.tf

module "eks" {
  source               = "../modules/"
. . .
  instance_type        = var.instance_type
  subnets_id           = var.subnet_ids
  cluster_name         = var.cluster_name
. . .
}

.tflint.hcl

config {
  force               = false
  disabled_by_default = true
  module              = true
  plugin_dir          = "~/.tflint.d/plugins"
  varfile             = ["../pipeline/eks-ec2.tfvars"]
}

plugin "aws" {
  enabled    = true
  version    = "0.8.0"
  deep_check = false
  source     = "github.com/terraform-linters/tflint-ruleset-aws"
}

rule "terraform_documented_variables" {
  enabled = true
}

rule "terraform_unused_declarations" {
  enabled = true
}

rule "terraform_typed_variables" {
  enabled = true
}

rule "terraform_standard_module_structure" {
  enabled = true
}

rule "terraform_required_version" {
  enabled = true
}

rule "terraform_required_providers" {
  enabled = true
}

rule "terraform_deprecated_interpolation" {
  enabled = true
}

rule "terraform_comment_syntax" {
  enabled = true
}

rule "terraform_documented_outputs" {
  enabled = true
}

rule "terraform_module_pinned_source" {
  enabled = true
}

rule "terraform_naming_convention" {
  enabled = true
}

rule "aws_instance_previous_type" {
  enabled = true
}

rule "aws_instance_invalid_type" {
  enabled = true
}

eks-ec2.tfvars

instance_type        = "t1.medium"
subnet_ids           = ["subnet-25215521", "subnet-3233232231"]
cluster_name         = "eks-module"

Running tflint, it pass. It doesn`t check the invalid instance type value in the variables.

Feature

Rule aws_instance_invalid_type verfiy module block too instead of just resource blocks.

wata727 commented 2 years ago

It works in my environment:

# main.tf
variable "instance_type" {}

module "ec2" {
  source = "./module"

  instance_type = var.instance_type
}
# module/ec2.tf
variable "instance_type" {}

resource "aws_instance" "foo" {
  instance_type = var.instance_type
}
# input.tfvars
instance_type = "t1.medium"
% tflint --module --var-file input.tfvars
1 issue(s) found:

Error: "t1.medium" is an invalid value as instance_type (aws_instance_invalid_type)

  on main.tf line 6:
   6:   instance_type = var.instance_type

Callers:
   main.tf:6,19-36
   module/ec2.tf:4,19-36

It may be useful to check the log output with TFLINT_LOG=debug etc.

bendrucker commented 2 years ago

The original post is missing the module source and the command that you're running. As noted above this works and a full repro should indicate where there's a problem in your usage.

evairmarinho commented 2 years ago

The original post is missing the module source and the command that you're running. As noted above this works and a full repro should indicate where there's a problem in your usage.

Hey, i just use tflint command. My configs are in the .tflint.hcl.

In my case, the module contains other module (terraform-aws-eks), without aws_instance resource block.

Thanks!