-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Internal] Add ConvertToAttribute() to convert blocks in a resource/d…
…ata source schema to attributes (#4284) ## Changes Blocks in the Plugin Framework cannot be computed. Terraform checks that the number of blocks in the plan matches the number in the config (https://github.com/hashicorp/terraform/blob/81441564dd29b4aa5fb9576323ef90b9787d1967/internal/plans/objchange/plan_valid.go#L115). Today, for compatibility with existing resources in the TF provider implemented with the SDKv2, we treat nested structures as lists with a single element. As a result, this precludes any nested structures from being read-only (since those would be converted into ListNestedBlocks, which cannot be computed). This blocks databricks_app from being implemented on the plugin framework, as its app_status and compute_status fields are objects and not primitives. Note that TF recommends computing computed-only blocks to attributes [here](https://developer.hashicorp.com/terraform/plugin/framework/migrating/attributes-blocks/blocks-computed). Other useful discussions can be found [here](https://discuss.hashicorp.com/t/set-list-attribute-migration-from-sdkv2-to-framework/56472) and [here](https://discuss.hashicorp.com/t/optional-computed-block-handling-in-plugin-framework/56337). The migration guide for blocks can be found [here](https://developer.hashicorp.com/terraform/plugin/framework/migrating/attributes-blocks/blocks). As an intermediate step, we add `ConvertToAttribute()` in `CustomizableSchema`. This allows resource maintainers to convert specific, known read-only blocks to attributes in accordance with [the migration guide](https://developer.hashicorp.com/terraform/plugin/framework/migrating/attributes-blocks/blocks-computed), which then can be marked as read-only. As blocks can contain other blocks, this method also recursively converts nested blocks into nested attributes. This is based on #4283, so we should wait for that PR to merge & rebase this before merging this. ## Tests Unit tests validate that ListNestedBlocks are converted to ListNestedAttributes and that SingleNestedBlocks are converted to SingleNestedAttributes.
- Loading branch information
Showing
8 changed files
with
329 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package tfschema | ||
|
||
type BlockToAttributeConverter interface { | ||
// ConvertBlockToAttribute converts a contained block to its corresponding attribute type. | ||
ConvertBlockToAttribute(string) BaseSchemaBuilder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.