decoder: validate required attributes more selectively #1485
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 onlyhcl-lang
which attaches the ctx value viaschemacontext.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 ofresource
ordata
blocks) as the actualprovider
block we mean.UX Before
UX After