Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override files are not compliant with the Terraform spec #2114

Closed
3 tasks done
wata727 opened this issue Sep 8, 2024 · 0 comments · Fixed by #2124
Closed
3 tasks done

Override files are not compliant with the Terraform spec #2114

wata727 opened this issue Sep 8, 2024 · 0 comments · Fixed by #2124
Labels

Comments

@wata727
Copy link
Member

wata727 commented Sep 8, 2024

Summary

TFLint supports Terraform override files, but is not fully compliant with the spec.

For these reasons, using override files can sometimes produce different results than Terraform would, or can lead to inconsistent results like those in terraform-linters/tflint-ruleset-terraform#205.

Command

tflint

Terraform Configuration

# main.tf
terraform {}
provider "aws" {}

# main2.tf
terraform {
  required_providers {}
}

# main_override.tf
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 5.64.0"
    }
  }
  required_version = "1.0.0"
}

TFLint Configuration

# empty file

Output

@wata727 ➜ /tmp/work $ tflint
@wata727 ➜ /tmp/work $ tflint
@wata727 ➜ /tmp/work $ tflint
1 issue(s) found:

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

  on main.tf line 3:
   3: provider "aws" {}

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

This inconsistent result is caused by which the terraform block is overwritten and which block is retrieved by the terraform_required_providers rule. If the block is retrieved that was not overwritten, this rule will emit an issue.

Ideally, the Terraform blocks in main.tf and main2.tf should be merged first.

TFLint Version

0.53.0

Terraform Version

No response

Operating System

  • Linux
  • macOS
  • Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant