terraform-linters / tflint

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

Failed to initialize plugins. An error occurred: Error: Incompatible API version with plugin "azurerm". Plugin version: 10, TFLint versions: [9] #1341

Closed Walluce closed 2 years ago

Walluce commented 2 years ago

What do I do when I get this error? I have the latest version of terraform and tflint: Failed to initialize plugins. An error occurred:

Error: Incompatible API version with plugin "azurerm". Plugin version: 10, TFLint versions: [9]

Walluce commented 2 years ago

Using version 14 instead of 15 of the AzureRm plugin seemed to resolve this.

PatMyron commented 2 years ago

see https://github.com/terraform-linters/tflint-ruleset-aws/issues/325#issuecomment-1081290187

sxlijin commented 2 years ago

The error message here is really misleading; it's not clear what API it's talking about. It should be more clear to users what's going on here, ideally saying something about min/max plugin version, not whichever version is being shoved into the error string.

sxlijin@sxlijin-devbox:2022-04-01T13:26:08-0700:~/playground4 [1]
$ cat .tflint.hcl
++ 2022-04-01T13:26:18-0700 ++ cat .tflint.hcl
plugin "aws" {
  enabled = true
  version = "0.11.0"
  source  = "github.com/terraform-linters/tflint-ruleset-aws"
}
sxlijin@sxlijin-devbox:2022-04-01T13:26:18-0700:~/playground4 [0]
$ ~/.cache/trunk/linters/tflint/0.35.0/tflint --format sarif aws.tf
++ 2022-04-01T13:26:20-0700 ++ /home/sxlijin/.cache/trunk/linters/tflint/0.35.0/tflint --format sarif aws.tf
{
  "version": "2.1.0",
  "$schema": "https://json.schemastore.org/sarif-2.1.0-rtm.5.json",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "tflint",
          "informationUri": "https://github.com/terraform-linters/tflint"
        }
      },
      "results": []
    },
    {
      "tool": {
        "driver": {
          "name": "tflint-errors",
          "informationUri": "https://github.com/terraform-linters/tflint"
        }
      },
      "results": [
        {
          "ruleId": "application_error",
          "level": "error",
          "message": {
            "text": "Failed to initialize plugins; Incompatible API version with plugin \"aws\". Plugin version: 9, TFLint versions: [10]"
          }
        }
      ]
    }
  ]
}
bendrucker commented 2 years ago

See https://github.com/hashicorp/go-plugin/pull/191 for an effort towards getting ready access to the client version(s) and server version for improved error messaging. This would allow for clearer messaging about which component, CLI vs plugin, needs updating.

Specific version advice, while theoretically achievable through significant enhancements to the plugin discovery system, is not practical at the moment.

sxlijin commented 2 years ago

Is the CLI not guaranteed to know the version of the plugin? I assumed it was always specified in .tflint.hcl.

Failed to initialize plugins; Incompatible API version with plugin \"aws\". Plugin version: 9, TFLint versions: [10]

This is the thing that's most baffling to me as a user: if tflint --version is 0.34.1 and my plugin version is 0.11.0 then I have no idea what "plugin version" and "TFLint versions" in this error message are.

bendrucker commented 2 years ago

TFLint speaks to plugins over RPC, this is that protocol (API) version. Sometimes changes in ruleset functionality necessitate a new plugin protocol.

The context of errors being unclear is a pretty standard programming problem. Users would like errors that are prescriptive but the reality actual errors are low level and assigning higher level meaning requires a bunch of code to inspect and interpret errors.

wata727 commented 2 years ago

Since we have already tweaked the error message for end-users, I think it is possible to make the incompatible API version error more user-friendly. See also https://github.com/terraform-linters/tflint/pull/885 https://github.com/terraform-linters/tflint/blob/4521a66ed0b9c6ea99875a65fe98376af1416a42/plugin/discovery.go#L137-L156

I don't think this is the best way, but at least it does prevent end-user confusion. Lower level protocol version errors are important to plugin developers, but many users want to know which plugin version is compatible.

Ideally, the plugin should return a plugin version constraint that is compatible with the currently running TFLint, but this can be difficult if the TFLint version is newer (e.g. tflint-ruleset-aws v0.11.0 doesn't know the plugin version that works with TFLint v0.35.0)

Probably, I think that it can be solved by printing a message such as "TFLint and the plugin version are not compatible, please check the compatibility".