hashicorp / terraform-ls

Terraform Language Server
Mozilla Public License 2.0
984 stars 130 forks source link

Terraform LS `0.32.4` - tfe provider `0.51.0` - tfe_organization data source - LS not accounting for changes that occurred in this version #1523

Open zisom-hc opened 9 months ago

zisom-hc commented 9 months ago

Language Server Version

v0.32.4

Terraform Version

1.6.6

Client Version

VS Code 1.85.0

Terraform Configuration

terraform {
  required_providers {
    tfe = {
      source  = "hashicorp/tfe"
      version = "~> 0.51.0"
    }
  }
}

data "tfe_organization" "test-company" {
}

Steps to Reproduce

  1. init version 0.51.0 of the tfe provider
  2. Configure a tfe_organization data source block without a name argument configured
  3. Observe the error that LS states

Expected Behavior

LS should recognize that in version 0.51.0 of the tfe provider, a change was made to this data source where the name argument went from being required to optional in tfe 0.51.0

d/tfe_organization: Make name argument optional if configured for the provider, by @tmatilai https://github.com/hashicorp/terraform-provider-tfe/pull/1133

Actual Behavior

LS states: Required attribute "name" not specified: An attribute named "name" is required here

Gist

No response

Workarounds

You can perform a terraform plan/apply without issue, so the error is just misleading, not blocking operations from occurring.

References

No response

Help Wanted

Community Note

radeksimko commented 9 months ago

Hi @zisom-hc The mentioned attribute was added to the provider relatively recently, as you noticed.

Since we only bundle a single version of the tfe provider schema in the language server (just like for other official+partner providers), we cannot provide the level of accuracy out of the box at this point unfortunately. The latest version available at the time of the latest LS release was v0.50.0.

The good news is however that if you run terraform init to install the latest version of the provider (assuming you have the appropriate version constraint that matches 0.51.0 which you do), the extension will pick it up and use that schema to do the validation.

We plan to improve the experience in similar situations by eventually pulling the schema from the Registry API but this is a non-trivial project that will take some time to execute. You can follow https://github.com/hashicorp/vscode-terraform/issues/737 in the meantime.

zisom-hc commented 9 months ago

Hey Radek, thank you for the insight regarding this. That's understandable that the provider schema currently being used within the latest version of the LS is from 0.50.0 of the tfe provider. The purpose of this was to inform y'all of the current discrepancy between the two versions at the moment.

The good news is however that if you run terraform init to install the latest version of the provider (assuming you have the appropriate version constraint that matches 0.51.0 which you do), the extension will pick it up and use that schema to do the validation.

Do i understand correctly that you're saying that the LS should be grabbing the schema for 0.51.0 when i perform a terraform init within the working directory of my module? If that is the case, i am not seeing that behavior post-init, as in i'm still seeing the problem prompt exist, so let me know if the steps below were not correct:

  1. Opened module code within VS Code
  2. executed terraform init within the working directory
  3. Observe whether the problem prompt disappeared for the tfe_organization data source, which did not occur
  4. re-opened organization.tf in VS Code to see if the problem prompt would then go away, with no change to the result (This step

Here's a screenshot of what i'm seeing post-init: image

radeksimko commented 9 months ago

The purpose of this was to inform y'all of the current discrepancy between the two versions at the moment.

We appreciate it, although unfortunately this impacts users of all providers and it's not a problem isolated to tfe. Another example is in https://github.com/hashicorp/vscode-terraform/issues/1621

Do i understand correctly that you're saying that the LS should be grabbing the schema for 0.51.0 when i perform a terraform init within the working directory of my module?

That's correct - this is how it should work.

There is however one extra step you have to take today, which is to either type into the file or re-open it. We plan to do this refresh automatically in the future - I have yet to file an issue for that.

See my recordings below

typing

2023-12-20 14 31 08

re-opening

2023-12-20 14 34 48