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

[Internal] Use Attributes by default for List Objects #4315

Merged
merged 18 commits into from
Dec 12, 2024

Conversation

mgyucht
Copy link
Contributor

@mgyucht mgyucht commented Dec 12, 2024

Changes

Resources implemented on the SDKv2 used blocks to represent two kinds of fields: traditional lists, and nested complex types (which were treated as a list of length at most 1). The Plugin Framework now has support for list attributes, and it is recommended to use this in general, except for places where compatibility with SDKv2 is needed.

To achieve this, this change ensures that *StructToSchema methods in the plugin framework generate attributes for lists by default. Then, for resources migrated from SDKv2, the implementer must call ConfigureForSdkV2Migration() in the customize callback. This will convert any list attributes into list blocks, preserving compatibility with SDKv2-implemented resources.

Additionally, this PR improves the handling of computed, non-optional fields. For lists annotated as tf:"computed", the resulting schema is invalid: it is marked as computed and as required because of the absence of the "optional" tag. When a field is labeled as computed, it can be marked as optional but should never be marked as required; that is addressed here as well.

Finally, this PR also includes some autogenerated changes modifying Apps to use types.Object in place of types.List for nested complex types.

Tests

  • make test run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@mgyucht mgyucht requested review from a team as code owners December 12, 2024 10:08
@mgyucht mgyucht requested review from tanmay-db and removed request for a team December 12, 2024 10:08
// ConfigureForSdkV2Migration modifies the underlying schema to be compatible with SDKv2. This method must
// be called on all resources that were originally implemented using the SDKv2 and are migrated to the plugin
// framework.
func (s *CustomizableSchema) ConfigureForSdkV2Migration() *CustomizableSchema {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why, but for me ConfigureForSdkV2Migration sends the message that it prepares it for a migration towards SDKv2, how about something with "compatibility", like MakeCompatibleWithSdkV2 or ConfigureAsSdkV2Compatible?

Copy link

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/terraform

Inputs:

  • PR number: 4315
  • Commit SHA: 86b8cce2870e63d35883125072f185a5ef6e0203

Checks will be approved automatically on success.

@eng-dev-ecosystem-bot
Copy link
Collaborator

Test Details: go/deco-tests/12295047523

@mgyucht mgyucht added this pull request to the merge queue Dec 12, 2024
@mgyucht mgyucht removed this pull request from the merge queue due to a manual request Dec 12, 2024
@mgyucht
Copy link
Contributor Author

mgyucht commented Dec 12, 2024

Note: the diff in schema on this PR is purely in data sources, converting block types to attributes for purely computed fields, in line with https://developer.hashicorp.com/terraform/plugin/framework/migrating/attributes-blocks/blocks-computed. There are no diffs in resource schemas.

@mgyucht mgyucht added this pull request to the merge queue Dec 12, 2024
Merged via the queue into main with commit aa13b25 Dec 12, 2024
12 checks passed
@mgyucht mgyucht deleted the use-attributes-by-default branch December 12, 2024 12:16
mgyucht added a commit that referenced this pull request Dec 12, 2024
### New Features and Improvements

 * Add `databricks_app` resource and data source ([#4099](#4099)).

### Documentation

 * Add a warning that attribute should be used in `databricks_permissions` for `databricks_vector_search_endpoint` ([#4312](#4312)).

### Internal Changes

 * Added TF Plugin Framework checkbox item to PR template and removed checkbox for integration tests passing ([#4227](#4227)).
 * Expose several integration test helpers for use in plugin framework integration tests ([#4310](#4310)).
 * Fix ReadOnly() for ListNestedAttribute and Validators for ListNestedBlock ([#4313](#4313)).
 * Panic if the provided path is invalid ([#4309](#4309)).
 * Simplify `databricks_storage_credential` code ([#4301](#4301)).
 * Use Attributes by default for List Objects ([#4315](#4315)).
 * Use Plugin Framework types internally in generated TF SDK structures ([#4291](#4291)).
github-merge-queue bot pushed a commit that referenced this pull request Dec 12, 2024
### New Features and Improvements

* Add `databricks_app` resource and data source
([#4099](#4099)).


### Documentation

* Add a warning that attribute should be used in
`databricks_permissions` for `databricks_vector_search_endpoint`
([#4312](#4312)).


### Internal Changes

* Added TF Plugin Framework checkbox item to PR template and removed
checkbox for integration tests passing
([#4227](#4227)).
* Expose several integration test helpers for use in plugin framework
integration tests
([#4310](#4310)).
* Fix ReadOnly() for ListNestedAttribute and Validators for
ListNestedBlock
([#4313](#4313)).
* Panic if the provided path is invalid
([#4309](#4309)).
* Simplify `databricks_storage_credential` code
([#4301](#4301)).
* Use Attributes by default for List Objects
([#4315](#4315)).
* Use Plugin Framework types internally in generated TF SDK structures
([#4291](#4291)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants