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

Fix provider attribute to block conversion #288

Merged
merged 2 commits into from Nov 1, 2023

Conversation

dbanck
Copy link
Member

@dbanck dbanck commented Oct 25, 2023

To mimic Terraform's built-in backwards-compatible logic, where list(object) or set(object) attributes are also accessible as blocks, we check all attributes to see if they match those types. But we only did this for the top-level attributes of a block, and didn't check nested attributes. This PR fixes that.

The example in hashicorp/vscode-terraform#1594 had three attributes, that were also available as a block: managed_disk, network_interface, and unmanaged_disk. All three are of type set(object) and encoded as such in the provider schema.

We convert them to blocks in

func convertibleAttributesToBlocks(attributes map[string]*tfjson.SchemaAttribute) map[string]*schema.BlockSchema {
blocks := make(map[string]*schema.BlockSchema, 0)
for name, attr := range attributes {
if typeCanBeBlocks(attr.AttributeType) {
blockSchema, ok := blockSchemaForAttribute(attr)
if !ok {
continue
}
blocks[name] = blockSchema
}
}

and so they show up for completion in the top-level dynamic block
CleanShot 2023-10-27 at 14 57 22@2x

managed_disk contains the attribute target_disk_encryption with type list(object) that also could be a block, but we never tried to convert it. So it never showed up for completion in a nested dynamic block and was marked as a problem by the schema validation.

UX

Before
CleanShot 2023-10-26 at 11 08 45@2x
CleanShot 2023-10-26 at 11 08 15@2x

After
CleanShot 2023-10-26 at 11 07 43@2x
CleanShot 2023-10-26 at 11 07 34@2x


@dbanck dbanck added the bug Something isn't working label Oct 25, 2023
@dbanck dbanck self-assigned this Oct 25, 2023
@dbanck dbanck marked this pull request as ready for review October 27, 2023 13:05
@dbanck dbanck requested a review from a team as a code owner October 27, 2023 13:05
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix and the test as well.

schema/convert_json.go Show resolved Hide resolved
@dbanck dbanck merged commit 18e2fd7 into main Nov 1, 2023
5 checks passed
@dbanck dbanck deleted the b-fix-provider-attributes-conversion branch November 1, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrectly flagging nested dynamic blocks as errors
3 participants