Skip to content

Terraform Language Server doesn't recognize variables defined in other file. #1729

Open
@crazyoptimist

Description

@crazyoptimist

Language Server Version

0.33.1

Terraform Version

Terraform v1.8.4 on windows_amd64

Client Version

Vim (coc.nvim) 9.1

Terraform Configuration

terraform {
  backend "azurerm" {
    storage_account_name = "redacted"
    container_name       = "redacted"
    key                  = "redacted/terraform.tfstate"
    use_azuread_auth     = true
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.106.1"
    }
  }
  required_version = ">= 1.5"
}

provider "azurerm" {
  features {}
}

locals {
  location = "westus"
}

resource "azurerm_resource_group" "main" {
  # Here! It complains: `No declaration found for "var.namespace" (Terraform)`
  name     = "${var.namespace}-tfbackend-test"
  location = local.location
}

Steps to Reproduce

  1. Create a very simple terraform project as shown above, you can even skip the remote backend configuration.
  2. Create variables.tf and define a variable namespace of string type.
  3. Run terraform init and terraform apply -auto-approve
  4. It runs successfully, but terraform-ls complains that the variable is not defined.

Expected Behavior

It should not complain because it's not a bug at all.

Actual Behavior

terraform-ls complains No declaration found for "var.namespace" (Terraform)

It shows up as an error.

Gist

No response

Workarounds

No workarounds I can find.

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions