terraform-linters / tflint-ruleset-terraform

TFLint ruleset for Terraform Language
Mozilla Public License 2.0
65 stars 24 forks source link

terraform_required_providers throws incorrect "Missing version constraint" warning #190

Closed grimm26 closed 4 months ago

grimm26 commented 4 months ago
❯ tflint --version
TFLint version 0.51.2
+ ruleset.aws (0.31.0)
+ ruleset.terraform (0.7.0-bundled)
rule "terraform_required_providers" {
  enabled = true
  version = false
}
❯ cat main.tf
terraform {
  required_version = "~> 1.7"
}

module "test" {
  providers = {
    aws.this = aws.us-west-2
  }
  source = "../testmod"
  thing  = "foo"
}
❯ cat ../testmod/main.tf
terraform {
  required_version = "~> 1.7"
  required_providers {
    aws = {
      source                = "hashicorp/aws"
      version               = ">= 5.0"
      configuration_aliases = [aws.this]
    }
  }
}

variable "thing" {
  description = "the thing"
  type        = string
}

output "thing" {
  value = var.thing
}
❯ tflint
1 issue(s) found:

Warning: Missing version constraint for provider "aws" in `required_providers` (terraform_required_providers)

  on main.tf line 5:
   5: module "test" {

Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.7.0/docs/rules/terraform_required_providers.md

If I add

  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
  }

to the terraform block in main.tf, tflint runs cleanly. I would think it should run clean with my initial config as well.

bendrucker commented 4 months ago

Duplicate of #21. TFLint isn't aware of the idea of passing providers between modules. It's a tricky problem so there hasn't been any movement towards a fix.