terraform-linters / tflint

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

Terraform 1.8.x builtin functions break tflint syntax parsing #2028

Closed lonelyelk closed 5 months ago

lonelyelk commented 5 months ago

Summary

Terraform code with builtin functions (e.g. provider::terraform::decode_tfvars or provider::terraform::encode_tfvars) will always fail in tflint as if it was incorrect code without specific linter rule. At the same time code is correct and running.

For example:

terraform {
  required_providers {
    terraform = {
      source = "terraform.io/builtin/terraform"
    }
  }
  required_version = "~> 1.8"
}

locals {
  test = provider::terraform::decode_tfvars(
    <<EOT
      example = "Hello!"
    EOT
  )
}

output "example" {
  value = local.test["example"]
}

Gives:

tflint.tf:10,18-19: Missing newline after argument; An argument definition must end with a newline.:

Error: Missing newline after argument

  on tflint.tf line 10, in locals:
  10:   test = provider::terraform::decode_tfvars(

An argument definition must end with a newline.

And another one:

terraform {
  required_providers {
    terraform = {
      source = "terraform.io/builtin/terraform"
    }
  }
  required_version = "~> 1.8"
}

locals {
  test = lookup(
    provider::terraform::decode_tfvars(
      <<EOT
        example = "Hello!"
      EOT
    ),
    "example",
    "default"
  )
}

output "example" {
  value = local.test
}

Gives:

tflint.tf:11,13-14: Missing argument separator; A comma is required to separate each function argument from the next.:

Error: Missing argument separator

  on tflint.tf line 11, in locals:
  10:   test = lookup(
  11:     provider::terraform::decode_tfvars(

A comma is required to separate each function argument from the next.

The underscode in both errors is under the first ":" character after provider namespace.

Command

tflint

Terraform Configuration

terraform {
  required_providers {
    terraform = {
      source = "terraform.io/builtin/terraform"
    }
  }
  required_version = "~> 1.8"
}

TFLint Configuration

any

Output

tflint.tf:10,18-19: Missing newline after argument; An argument definition must end with a newline.:

Error: Missing newline after argument

  on tflint.tf line 10, in locals:
  10:   test = provider::terraform::decode_tfvars(

An argument definition must end with a newline.

--------

tflint.tf:11,13-14: Missing argument separator; A comma is required to separate each function argument from the next.:

Error: Missing argument separator

  on tflint.tf line 11, in locals:
  10:   test = lookup(
  11:     provider::terraform::decode_tfvars(

A comma is required to separate each function argument from the next.

TFLint Version

0.50.3

Terraform Version

1.8.x

Operating System

lonelyelk commented 5 months ago

In both cases terraform fmt . and terraform apply run without problems

wata727 commented 5 months ago

Duplicate of https://github.com/terraform-linters/tflint/issues/1878