-
Notifications
You must be signed in to change notification settings - Fork 400
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 TF annotations on TFSDK models #4383
Conversation
1fe1eb3
to
17098ad
Compare
17098ad
to
62118b5
Compare
62118b5
to
f81d9ec
Compare
d62b492
to
10d702a
Compare
60f2b80
to
ae1fc5f
Compare
Imho, it's making it harder to understand from looking into struct what fields are optional/computed/... |
@@ -18,19 +18,16 @@ import ( | |||
) | |||
|
|||
type CustomizableSchemaProvider interface { | |||
ApplySchemaCustomizations(cs CustomizableSchema, path ...string) CustomizableSchema | |||
ApplySchemaCustomizations(map[string]AttributeBuilder) map[string]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.
If we only expose the underlying map, some customizations are a bit more cumbersome right?
3e368ec
to
58c5329
Compare
@alexott you're right, but it does simplify the reflection parts and moving forward, tf annotations will limit us from further describing the schema with things like descriptions, plan modifiers and validators. It's basically a language we invented which will grow in maintenance. Will it help if we add these as inline comments? For example, type CreateRepoRequest struct {
Url types.String `tfsdk:"url"` // tf:optional
} |
comment may help. another question - how would we additionally tune the behavior? Right now, many structs in Go SDK just blindly declare everything as |
@alexott OpenAPI should be the preferred way, as it'll help things stay consistent across the board. However, if that process is problematic, you could still provide a |
JobSettings_SdkV2{}.ApplySchemaCustomizations(cs, append(path, "new_settings")...) | ||
func (c ResetJob_SdkV2) ApplySchemaCustomizations(attrs map[string]tfschema.AttributeBuilder) map[string]tfschema.AttributeBuilder { | ||
attrs["job_id"] = attrs["job_id"].SetRequired() | ||
attrs["new_settings"] = attrs["new_settings"].SetRequired() |
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.
Missing list validator for single object
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.
This is fixed now. I had the conditional order wrong and now it's rendering properly. I do wonder how the missing list validator didn't pop up during make diff-schema
.
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.
Validators may not show up on diff-schema, I don't know if they are part of the JSON representation (because they are code), similar to plan modifiers.
@alexott Our goal is to ensure that there is no extra customization needed in TF beyond what is in the API spec. The real issue is actually that the OpenAPI spec maintained by teams doesn't reflect reality of their API (defined using Protobuf). We are asking all teams to migrate to the OpenAPI generator to eliminate this discrepancy; then, there should be perfect alignment between the API and SDKs/Terraform. |
58c5329
to
c313cf2
Compare
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. |
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.
LGTM, but I'm just curious if .(tfschema.AttributeBuilder)
is needed when assigning the attributebuilder updated with validator to the attribute builder map.
Unfortunately that results in a |
### New Features and Improvements * Add `fallback` to `databricks_external_location` ([#4372](#4372)). ### Bug Fixes * Send only what is required in Update of `databricks_credential` ([#4349](#4349)). ### Documentation * Add `MANAGE` privilege to the relevant UC resources ([#4371](#4371)). * Add a note about schema evolution and `databricks_sql_table` ([#4352](#4352)). * Add description of `clean_rooms_notebook_task` in `databricks_job` ([#4368](#4368)). * Add docs for cluster attributes for clusters assigned to groups ([#4359](#4359)). * Add note about use of `azurerm_databricks` for enhanced security settings ([#4393](#4393)). * Clarify views sharing in `databricks_share` ([#4378](#4378)). * Document job edit_mode ([#4354](#4354)). ### Internal Changes * Auto generated customizable schemas ([#4356](#4356)). * Disable `terraform fmt` in exporter to workaround build issues ([#4394](#4394)). * Fixed redundant optional owners in share resource and bumped Go SDK ([#4396](#4396)). * Load auto-generated resources and data sources ([#4367](#4367)). * Migrate workflows that need write access to use hosted runners ([#4377](#4377)). * Remove TF annotations on TFSDK models ([#4383](#4383)). * Restart Cluster before Library Installation ([#4384](#4384)). ### Dependency Updates * Bump github.com/zclconf/go-cty from 1.15.1 to 1.16.0 ([#4374](#4374)). * Bump github.com/zclconf/go-cty from 1.16.0 to 1.16.1 ([#4397](#4397)). ### Exporter * Add exporting of `for_each_task` in jobs ([#4347](#4347)). * Add references for missing permissions/grants types ([#4390](#4390)). * Support for group assigned clusters ([#4361](#4361)). * Use Go SDK to list clusters ([#4385](#4385)). * Use `Workspace.Export` from Go SDK for notebooks/files ([#4391](#4391)).
### New Features and Improvements * Add `fallback` to `databricks_external_location` ([#4372](#4372)). ### Bug Fixes * Send only what is required in Update of `databricks_credential` ([#4349](#4349)). ### Documentation * Add `MANAGE` privilege to the relevant UC resources ([#4371](#4371)). * Add a note about schema evolution and `databricks_sql_table` ([#4352](#4352)). * Add description of `clean_rooms_notebook_task` in `databricks_job` ([#4368](#4368)). * Add docs for cluster attributes for clusters assigned to groups ([#4359](#4359)). * Add note about use of `azurerm_databricks` for enhanced security settings ([#4393](#4393)). * Clarify views sharing in `databricks_share` ([#4378](#4378)). * Document job edit_mode ([#4354](#4354)). ### Internal Changes * Auto generated customizable schemas ([#4356](#4356)). * Disable `terraform fmt` in exporter to workaround build issues ([#4394](#4394)). * Fixed redundant optional owners in share resource and bumped Go SDK ([#4396](#4396)). * Load auto-generated resources and data sources ([#4367](#4367)). * Migrate workflows that need write access to use hosted runners ([#4377](#4377)). * Remove TF annotations on TFSDK models ([#4383](#4383)). * Restart Cluster before Library Installation ([#4384](#4384)). ### Dependency Updates * Bump github.com/zclconf/go-cty from 1.15.1 to 1.16.0 ([#4374](#4374)). * Bump github.com/zclconf/go-cty from 1.16.0 to 1.16.1 ([#4397](#4397)). ### Exporter * Add exporting of `for_each_task` in jobs ([#4347](#4347)). * Add references for missing permissions/grants types ([#4390](#4390)). * Support for group assigned clusters ([#4361](#4361)). * Use Go SDK to list clusters ([#4385](#4385)). * Use `Workspace.Export` from Go SDK for notebooks/files ([#4391](#4391)).
Changes
This PR changes how schemas are defined for plugin framework resources and data sources. Instead of encoding the schema attributes in a
tf
tag, which involves reflection and code that's harder to reason about, structs must now implement theApplySchemaCustomizations
method and declare schema customizations explicitly there. All TFSDK structs will have this method generated for them, and if you want to declare a schema for your own struct, you should do so as follows:Tests
make test
run locallydocs/
folderinternal/acceptance