terraform-linters / tflint-ruleset-aws

TFLint ruleset for terraform-provider-aws
Mozilla Public License 2.0
327 stars 71 forks source link

Provider with alias doesn't exist error with v0.24.0 #507

Closed adamstirk-ct closed 1 year ago

adamstirk-ct commented 1 year ago

With v0.24.0 of the ruleset I'm now getting the error below, even though the provider exists.

Failed to check ruleset; failed to check "aws_resource_missing_tags" rule: The aws provider with alias "us-east-1" doesn't exist.

Below is a simple example that replicates this issue

File: .tflint.hcl

plugin "terraform" {
  enabled = true
  preset  = "all"
}

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

rule "aws_resource_missing_tags" {
  enabled = true
  tags    = ["Environment"]
}

File: main.tf

provider "aws" {
  region = eu-west-1
}

provider "aws" {
  region = "us-east-1"
  alias  = "us-east-1"
}

terraform {
  required_version = ">= 1.3.7"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 4.59"
    }
  }
}

resource "aws_ssm_parameter" "test1" {
  name  = "test1"
  type  = "String"
  value = "test"

  tags = {
    Environment = "test"
  }
}

resource "aws_ssm_parameter" "test2" {
  name  = "test2"
  type  = "String"
  value = "test"

  provider = aws.us-east-1

  tags = {
    Environment = "test"
  }
}

File: outputs.tf

# Empty file

File: variables.tf

# Empty file
wata727 commented 1 year ago

@JorgeReus Can you investigate this?

JorgeReus commented 1 year ago

On it

JorgeReus commented 1 year ago

Found the issue, I ignored providers without tags, which introduced this error, this is fixed in https://github.com/terraform-linters/tflint-ruleset-aws/pull/508, sorry!

@adamstirk-ct As a temporal workaround, you could add an empty default tags block, until the PR gets merged:

provider "aws" {
  region = "us-west-1"
  alias  = "west"
  default_tags {
    tags = {}
  }
}