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

config attribute not expected in terraform_remote_state data source #1606

Closed
1 task
pawwe opened this issue Oct 24, 2023 · 4 comments
Closed
1 task

config attribute not expected in terraform_remote_state data source #1606

pawwe opened this issue Oct 24, 2023 · 4 comments
Assignees
Labels
bug Something isn't working diagnostics

Comments

@pawwe
Copy link

pawwe commented Oct 24, 2023

Extension Version

v2.28.2

VS Code Version

Version: 1.83.1
Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc
Date: 2023-10-10T23:45:31.402Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Linux x64 6.5.7-200.fc38.x86_64

Operating System

Linux fws 6.5.7-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 11 04:07:58 UTC 2023 x86_64 GNU/Linux

Terraform Version

Terraform v1.6.2 on linux_amd64

Steps to Reproduce

Create a terraform_remote_state data source with a config argument where the backend argument is a variable.

Expected Behavior

Should not throw "Unexpected attribute" error.

Actual Behavior

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

Terraform Configuration

variable "terraform_rs" {
  default = {
    backend              = "azurerm"
    workspace            = "***"
    storage_account_name = "***"
    container_name       = "***"
    key                  = "***"
    access_key           = "***"
  }
}

data "terraform_remote_state" "this" {
  backend   = var.terraform_rs.backend
  workspace = var.terraform_rs.workspace
  config = {
    storage_account_name = var.terraform_rs.storage_account_name
    container_name       = var.terraform_rs.container_name
    key                  = var.terraform_rs.key
    access_key           = var.terraform_rs.access_key
  }
}

Project Structure

No response

Gist

No response

Anything Else?

No response

Workarounds

Downgrading to v2.27.2 or "hard coding" the backend attribute to "azurerm" resolves this problem.

References

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
@pawwe pawwe added the bug Something isn't working label Oct 24, 2023
@radeksimko
Copy link
Member

I was able to reproduce the bug, thank you for attaching the configuration @pawwe

It indeed looks like that we don't account for the possibility of backend being dynamically provided inside of terraform_remote_state data source. 🤔

@radeksimko
Copy link
Member

Notes for whoever gets to work on the fix:

I think we may need to update the logic in https://github.com/hashicorp/hcl-lang/blob/cc41e378f3a4c832a8e8e1fdde1c3705ee66e20c/decoder/internal/schemahelper/block_schema.go#L95-L98 to ensure that in this context dependent body lookup is treated as unsuccessful (unless it is already?) and that should in turn make sure that the validator receives the appropriate context, as per https://github.com/hashicorp/hcl-lang/blob/cc41e378f3a4c832a8e8e1fdde1c3705ee66e20c/decoder/internal/walker/walker.go#L91-L94 and unknown attributes won't be flagged up.

On a separate note we could create a follow-up issue to enable validation in such a dynamic context but I expect that will be a bit more involved.

@radeksimko
Copy link
Member

This was addressed in hashicorp/hcl-lang#339 and will be part of the next release.

Copy link

github-actions bot commented Dec 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working diagnostics
Projects
None yet
Development

No branches or pull requests

2 participants