Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected attribute: An attribute named "content" is not expected here #3642

Closed
3 tasks done
liamdawson opened this issue Aug 15, 2024 · 17 comments
Closed
3 tasks done
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/debug-log-attached Indicates an issue or PR has a complete Terraform debug log.

Comments

@liamdawson
Copy link

liamdawson commented Aug 15, 2024

Confirmation

  • This is a bug with an existing resource and is not a feature request or enhancement. Feature requests should be submitted with Cloudflare Support or your account team.
  • I have searched the issue tracker and my issue isn't already found.
  • I have replicated my issue using the latest version of the provider and it is still present.

Terraform and Cloudflare provider version

Terraform v1.9.4
on darwin_arm64
+ provider registry.terraform.io/cloudflare/cloudflare v4.39.0

Affected resource(s)

cloudflare_record

Terraform configuration files

terraform {
  required_providers {
    cloudflare = {
      source  = "cloudflare/cloudflare"
      version = "4.39.0"
    }
  }
}

provider "cloudflare" { }

resource "cloudflare_record" "record" {
  zone_id = "my-zone-id"
  name    = "my-record"

  type    = "A"
  content = "127.0.0.1"
  proxied = false
}

Link to debug output

https://gist.github.com/liamdawson/15b2dc72cdc9e2a3447a7fda541c79b4

Panic output

No response

Expected output

The resource would validate correctly in the Visual Studio Code Terraform extension (which uses the Terraform LSP).

Actual output

The line with content is marked with an error:

Unexpected attribute: An attribute named "content" is not expected here    Terraform  [Ln 6, Col 3]

Steps to reproduce

  1. Open a folder in Visual Studio Code
  2. Enable the hashicorp.terraform extension
  3. Create a main.tf with the resource above
  4. terraform init
  5. Close and re-open main.tf

Additional factoids

Interesting snippet in the verbose terraform plan output:

2024-08-17T13:17:54.982+1000 [WARN]  Provider "registry.terraform.io/cloudflare/cloudflare" produced an invalid plan for cloudflare_record.record, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .allow_overwrite: planned value cty.False for a non-computed attribute

References

@liamdawson liamdawson added kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 15, 2024
Copy link
Contributor

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

Copy link
Contributor

github-actions bot commented Aug 15, 2024

Terraform debug log detected ✅

@github-actions github-actions bot added triage/needs-information Indicates an issue needs more information in order to work on it. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 15, 2024
@liamdawson
Copy link
Author

liamdawson commented Aug 17, 2024

Added log file: https://gist.github.com/liamdawson/15b2dc72cdc9e2a3447a7fda541c79b4

I've also reproduced the same issue in the zed editor.

@github-actions github-actions bot added triage/debug-log-attached Indicates an issue or PR has a complete Terraform debug log. and removed triage/needs-information Indicates an issue needs more information in order to work on it. labels Aug 17, 2024
@BenJackGill
Copy link

Can confirm I am also seeing this error with 4.39.0

@jacobbednarz
Copy link
Member

this isn't a provider (or version) specific issue but instead, how the LSP determines what version of the provider to use in order to validate the configuration. for this to work properly, you'll need to:

  • update the version in your configuration (4.38.0 => 4.39.0)
  • terraform init -upgrade
  • open your editor

from there, you'll get the correct LSP feedback.

@jacobbednarz jacobbednarz closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2024
@billinghamj
Copy link

@jacobbednarz I don't think that's right. Even on the latest version, even having explicitly updated the provider version constraint from "~> 4.2" to "~> 4.39", and restarting the language server, the issue remains

@angelcabrera-nr
Copy link

The bug is still present in version 4.40

provider "registry.terraform.io/cloudflare/cloudflare" {
version = "4.40.0"
...

"Unexpected attribute: An attribute named "content" is not expected here"

@jacobbednarz
Copy link
Member

providers don't do anything specifically for the LSP to work other than define the schema (which here, is identical to value). it relies on the output from terraform providers schema -json output which is why you see errors between versions if you don't upgrade/select the correct version. very common issue with version managers (asdf, tf env, etc).

@BenJackGill
Copy link

BenJackGill commented Aug 22, 2024

Did you run terraform init -upgrade? Mine seems to be fixed now, using 4.39.0

EDIT: I spoke too soon. I am also still seeing this error even after running terraform init -upgrade. Not sure why it temporarily disappeared.

@BenJackGill
Copy link

I have no idea why this error keeps popping up. After upgrading to 4.39.0 and running terraform init -upgrade sometimes the error shows, and sometimes it disappears.

I've had to downgrade to 4.38.0 and use value instead until this is resolved. But also the issue is now closed so I'm not holding my breath.

If someone can shed more light onto whats happening please let me know!

@jacobbednarz
Copy link
Member

there is no further answers from me. it comes down to how it is being picked locally.

@hfsaito
Copy link

hfsaito commented Aug 29, 2024

Isn't this a breaking change added in v4.39.0? Looks like it should have been applied in v5.0.0
Everyone using ~> 4.0 now have to change the required version to ~> 4.39
(including the example shown in provider page https://registry.terraform.io/providers/cloudflare/cloudflare/4.39.0/docs)

I manage to fix my case

  1. I ran terraform init -upgrade and cli commands started work like terraform validate and terraform plan
    But the lsp is not picking the correct schema, which is really annoying
    I installed it through vscode extension and left with default settings
    I ran terraform providers schema -json, looks correct, I could find the attribute in json structure
  2. I have 3 different environments which share modules and the error message was showing in one of the modules
    root folder
    |-- dev
    |-- staging
    |-- prod
    |-- modules
    
  3. I changed provider version to ~> 4.39 in dev and modules folders, didn't work
  4. I ran terraform init -upgrade in all environments, didn't work
  5. I changed provider version to ~> 4.39 in all folders it worked!

@jacobbednarz
Copy link
Member

Isn't this a breaking change added in v4.39.0? Looks like it should have been applied in v5.0.0

no it is not a breaking change. value is still usable and will be until 5.x. content is introduced now to make the transition possible before 5.x is out.

@SeanKilleen
Copy link

I also hit this behavior and found it confusing.

  • Run terraform init -upgrade with latest version of provider (4.40.0)
  • Run tf plan
  • See message: value is deprecated in favour of content and will be removed in the next major release.
  • Change value field to content

Expected behavior: TF file appears valid with no issues
Actual behavior: see issue surfaced by LSP that content is not an expected field (even after reopening file or VSCode)

Personal workaround: Explicitly run terraform validate after changing the field. I couldn't get the LSP to pick up on the new schema on its own but running the validate command seemed to resolve things.

YMMV. Hope it helps someone out.

@hfsaito
Copy link

hfsaito commented Aug 29, 2024

Isn't this a breaking change added in v4.39.0? Looks like it should have been applied in v5.0.0

no it is not a breaking change. value is still usable and will be until 5.x. content is introduced now to make the transition possible before 5.x is out.

Makes sense
There could be a warning message in the documentation below this new attribute
To tell us to change the required version to 4.39

@jacobbednarz
Copy link
Member

the change is documented in the changelog (https://github.com/cloudflare/terraform-provider-cloudflare/blob/master/CHANGELOG.md#4390-august-7th-2024) and in the terraform output itself when using the deprecated value.

@domenikk
Copy link

I ran into the same issue with latest version (4.40). The only thing that worked for me was switching to pre-release version of HashiCorp Terraform extension in VSCode: v2.33.2024082314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/debug-log-attached Indicates an issue or PR has a complete Terraform debug log.
Projects
None yet
Development

No branches or pull requests

8 participants