terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.96k stars 357 forks source link

SARIF reports are reporting the endLine as 1 in all cases #1745

Closed tbutler-qontigo closed 1 year ago

tbutler-qontigo commented 1 year ago

Summary

Given a simple variables.tf file:

variable "subscription_id" {}
variable "resource_group_name" {}
variable "resource_group_location" {}
variable "agw_monitoring_log_analytics_workspace_name" {}
variable "tags" {
  type = map(string)
}

If I analyse this with tflint 0.45.0 then, for each variable, the start and end line are correctly reported as the same value for each one - e.g. resource_group_location has a startLine and endLine of `3.

Analyzing the same file with tflint 0.46.0, all issues are reporting the correct startLine but endLine is reported as 1 in all cases.

Command

tflint.exe --config ./.tflint.ci.hcl --format=sarif

Terraform Configuration

The `variables.tf` referenced in the summary is the only terraform file in the folder

TFLint Configuration

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

plugin "azurerm" {
  enabled = true
  version = "0.20.0"
  source  = "github.com/terraform-linters/tflint-ruleset-azurerm"
}

plugin "google" {
    enabled = true
    version = "0.22.2"
    source  = "github.com/terraform-linters/tflint-ruleset-google"
}

Output

`0.45.0` - correct:

        {
          "ruleId": "terraform_documented_variables",
          "level": "note",
          "message": {
            "text": "`resource_group_location` variable has no description"
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "variables.tf"
                },
                "region": {
                  "startLine": 3,
                  "startColumn": 1,
                  "endLine": 3,
                  "endColumn": 35
                }
              }
            }
          ]
        },

0.46.0 - incorrect:

        {
          "ruleId": "terraform_documented_variables",
          "level": "note",
          "message": {
            "text": "`resource_group_location` variable has no description"
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "variables.tf"
                },
                "region": {
                  "startLine": 3,
                  "startColumn": 1,
                  "endLine": 1,
                  "endColumn": 35
                }
              }
            }
          ]
        },

The same happens for all other variables



### TFLint Version

0.46.0

### Terraform Version

1.3.9

### Operating System

- [ ] Linux
- [ ] macOS
- [X] Windows
tbutler-qontigo commented 1 year ago

If I were a betting man, I'd say the problem was introduced here: https://github.com/terraform-linters/tflint/blob/49aa87383f61895be7b89cade221ffbfa05d1bb4/formatter/sarif.go#L52