-
Notifications
You must be signed in to change notification settings - Fork 397
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
[Internal] Remove unused configuration from blocks #4283
Conversation
@mgyucht Maybe we can apply |
@alexott That's a great point. Going forward, we're going to follow the advice from https://developer.hashicorp.com/terraform/plugin/framework/migrating/attributes-blocks/blocks-computed to migrate those blocks to nested attributes. Once this is done, we can mark the entire nested attribute with ReadOnly(). I will make another PR to handle that conversion. |
|
||
// SetOptional sets the attribute as optional in the schema. This does not affect whether the attribute is computed. | ||
// It fails if the attribute is already optional. | ||
SetOptional() BaseSchemaBuilder | ||
|
||
// SetRequired sets the attribute as required in the schema. This does not affect whether the attribute is computed. | ||
// It fails if the attribute is already required. | ||
SetRequired() BaseSchemaBuilder | ||
|
||
// SetSensitive sets the attribute as sensitive in the schema. It fails if the attribute is already sensitive. | ||
SetSensitive() BaseSchemaBuilder | ||
|
||
// SetComputed sets the attribute as computed in the schema. It fails if the attribute is already computed. | ||
SetComputed() BaseSchemaBuilder | ||
|
||
// Sets the attribute as read-only in the schema, i.e. computed and neither optional or required. It fails if the | ||
// attribute is already read-only. | ||
SetReadOnly() BaseSchemaBuilder | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these return BaseSchemaBuilder
or AttributeBuilder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, they can return AttributeBuilder.
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Test Details: go/deco-tests/12120241554 |
…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.
### New Features and Improvements * Add `databricks_credential` resource ([#4219](#4219)). * Allow to filter jobs by name in `databricks_jobs` data source ([#3395](#3395)). ### Bug Fixes * Add client side validation for `volume_type` ([#4289](#4289)). * Add missing H2 header in `mws_network_connectivity_configs.md` and optimization in `data_mws_network_connectivity_configs` ([#4256](#4256)). * Forced send `auto_stop_mins` for `databricks_sql_endpoint` resource ([#4265](#4265)). * Handle deleted cluster gracefully ([#4280](#4280)). * Remove config drift if Azure SP is used in `databricks_credential` ([#4294](#4294)). * Use correct domain for Azure Gov and China ([#4274](#4274)). * don't start cluster if `warehouse_id` is specified for `databricks_sql_table` resource ([#4259](#4259)). ### Documentation * Document import support for `databricks_notification_destination` ([#4276](#4276)). * Update documentation for importing some MWS resources ([#4281](#4281)). * Update mws_log_delivery.md to add time_sleep ([#4258](#4258)). ### Internal Changes * Add ConvertToAttribute() to convert blocks in a resource/data source schema to attributes ([#4284](#4284)). * Bump Go SDK and generate TF structs ([#4300](#4300)). * Generate effective fields based of isServiceProposedIfEmpty ([#4282](#4282)). * Ignore Databricks Go SDK updates by dependabot ([#4253](#4253)). * Move TFSDK model template to universe ([#4303](#4303)). * Remove unused configuration from blocks ([#4283](#4283)). * Use isServiceProposedIfEmpty annotations for effective fields ([#4270](#4270)). * Use tf_v1 genkit mode ([#4278](#4278)). ### Dependency Updates * Bump github.com/stretchr/testify from 1.9.0 to 1.10.0 ([#4269](#4269)). * Bump github.com/zclconf/go-cty from 1.15.0 to 1.15.1 ([#4273](#4273)). ### Exporter * Fix generation of references to users for user directories ([#4297](#4297)). * better handling of online tables/vsis in listing ([#4288](#4288)).
### New Features and Improvements * Add `databricks_credential` resource ([#4219](#4219)). * Allow to filter jobs by name in `databricks_jobs` data source ([#3395](#3395)). ### Bug Fixes * Add client side validation for `volume_type` ([#4289](#4289)). * Add missing H2 header in `mws_network_connectivity_configs.md` and optimization in `data_mws_network_connectivity_configs` ([#4256](#4256)). * Forced send `auto_stop_mins` for `databricks_sql_endpoint` resource ([#4265](#4265)). * Handle deleted cluster gracefully ([#4280](#4280)). * Remove config drift if Azure SP is used in `databricks_credential` ([#4294](#4294)). * Use correct domain for Azure Gov and China ([#4274](#4274)). * don't start cluster if `warehouse_id` is specified for `databricks_sql_table` resource ([#4259](#4259)). ### Documentation * Document import support for `databricks_notification_destination` ([#4276](#4276)). * Update documentation for importing some MWS resources ([#4281](#4281)). * Update mws_log_delivery.md to add time_sleep ([#4258](#4258)). ### Internal Changes * Add ConvertToAttribute() to convert blocks in a resource/data source schema to attributes ([#4284](#4284)). * Bump Go SDK and generate TF structs ([#4300](#4300)). * Generate effective fields based of isServiceProposedIfEmpty ([#4282](#4282)). * Ignore Databricks Go SDK updates by dependabot ([#4253](#4253)). * Move TFSDK model template to universe ([#4303](#4303)). * Remove unused configuration from blocks ([#4283](#4283)). * Use isServiceProposedIfEmpty annotations for effective fields ([#4270](#4270)). * Use tf_v1 genkit mode ([#4278](#4278)). ### Dependency Updates * Bump github.com/stretchr/testify from 1.9.0 to 1.10.0 ([#4269](#4269)). * Bump github.com/zclconf/go-cty from 1.15.0 to 1.15.1 ([#4273](#4273)). ### Exporter * Fix generation of references to users for user directories ([#4297](#4297)). * better handling of online tables/vsis in listing ([#4288](#4288)).
Changes
Currently, our schema builder elements in the plugin framework components allow you to set Computed/Optional/Required/Sensitive fields on Block schema elements. However, these are simply dropped when converting to actual schema elements: only attributes have these fields. This PR moves the SetComputed/SetOptional/SetRequired/SetSensitive/SetReadOnly methods to the AttributeBuilder interface and panics if you attempt to set them on a block.
Tests
Added a unit test to verify that these methods panic when called on an element that is converted into a block.