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

decoder: validate required attributes more selectively #1485

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Nov 3, 2023

Depends on hashicorp/hcl-lang#341


Summary

This patch provides us a way to dampen the impact of hashicorp/vscode-terraform#1616 Note that it does not really solve the issue entirely since even resources and data sources may in theory have various dynamic defaults for attributes which are also marked as required.

We could've used schemacontext.WithUnknownSchema() here to indicate "unknown-ness" of the provider schema. This would currently achieve the same effect but it would mix up the abstraction layers (currently it's only hcl-lang which attaches the ctx value via schemacontext.WithUnknownSchema and then its own validators read it) and it would IMHO lead to abuse of that concept of "unknown-ness". By using a separate context value we can mostly isolate the handling of this edge case to the LS codebase as it is indeed a "Terraform schema edge case" and not necessarily HCL's problem or problem that will generally exist in other HCL-based languages.

Another new (more generic) upstream context value "block nesting level" is also leveraged here to ensure that we don't end up interpreting any block called provider (e.g. inside of resource or data blocks) as the actual provider block we mean.

UX Before

Screenshot 2023-11-06 at 11 05 13

UX After

Screenshot 2023-11-06 at 11 10 14

Copy link
Member

@dbanck dbanck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Feel free to merge after bumping hcl-lang

@radeksimko radeksimko merged commit 9ae6980 into main Nov 7, 2023
21 checks passed
@radeksimko radeksimko deleted the b-custom-req-attributes branch November 7, 2023 14:11
Copy link

github-actions bot commented Dec 8, 2023

I'm going to lock this pull request 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 related to this change, 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 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants