Open theherk opened 1 week ago
Hi @theherk, thanks for the report! Unfortunately I can't reproduce the bug right away.
In a single directory with two files, everything seems to work as expected.
Can you share the LSP log?
Sure, given the basic directory with contents:
variables.tf
variable "cname_records" {
type = map(string)
description = "Map of CNAME records, where key is the domain and value is the record value."
}
terraform.tfvars
cname_records = {
"_cea53b5cd872a2d2d966a339ae031d59.foo.no." = "_8e50420392efe6ae6720f03fd2acd445.nhqijqilxf.acm-validations.aws."
}
The resulting lsp.log is:
I'm hitting the same issue. Or at least, it manifests with the same "Unexpected attribute" in terraform.tfvars
. This is with nvim. If I start nvim anew, there are no warnings. But if I so much as comment out a line (without even saving), I get "Unexpected attribute" for each and every variable in terraform.tfvars
. But I've observed something else that I'll get to in a moment.
For reference:
❯ terraform version
Terraform v1.9.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v5.68.0
+ provider registry.terraform.io/hashicorp/cloudinit v2.3.5
+ provider registry.terraform.io/hashicorp/http v3.4.5
+ provider registry.terraform.io/hashicorp/local v2.5.2
+ provider registry.terraform.io/hashicorp/null v3.2.3
+ provider registry.terraform.io/hashicorp/random v3.6.3
+ provider registry.terraform.io/hashicorp/time v0.12.1
+ provider registry.terraform.io/hashicorp/tls v4.0.6
❯ terraform-ls --version
0.34.3
❯ nvim --version
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1725453128
My observation is that if there is a .terraform
dir (post-terraform init
) that the reported issue is present. Indeed, I used @theherk 's example files and didn't even need to edit tfvars to get it to repro, as long as I also copied my .terraform
dir to the freshly created dir that has only the 2 files they provided.
In case it mattered: I deleted my .terraform
dir and lock file, re-ran terraform init
, and the reported issue is still there for my own case. I then copied the .terraform
dir over to the fresh dir again (after having removed the first copy from earlier) and am still able to repro using the files provided by @theherk .
I'm no doubt glossing over the importance of .terraform
at least as far as terraform-ls
is concerned. But to your point, @dbanck, if I drop just those 2 files into a freshly created dir (no other files or subdirs present) then I am also unable to repro the issue.
(Someone may be along shortly to tell me I've misconfigured something. And that's fine :slightly_smiling_face: I'm always happy to learn something useful.)
Language Server Version
0.34.3+Homebrew
Terraform Version
Terraform v1.6.6 on darwin_arm64
Client Version
NVIM v0.10.1
Terraform Configuration
Steps to Reproduce
Expected Behavior
I expect not to get any errors, as this is a correct and working configuration.
Actual Behavior
Receive the error
Unexpected attribute: An attribute named "cname_records" is not expected here
.Gist
No response
Workarounds
No response
References
No response
Help Wanted
Community Note