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] Add maxItem=1 validator for object types in plugin framework schema #4094

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

edwardfeng-db
Copy link
Contributor

@edwardfeng-db edwardfeng-db commented Oct 10, 2024

Changes

  • Added object tag for object types in tfsdk struct
  • Added maxItem=1 validator for object types in the plugin framework schema

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

@edwardfeng-db edwardfeng-db marked this pull request as ready for review October 11, 2024 05:02
@edwardfeng-db edwardfeng-db requested review from a team as code owners October 11, 2024 05:02
@edwardfeng-db edwardfeng-db requested review from mgyucht and hectorcast-db and removed request for a team October 11, 2024 05:02
@edwardfeng-db edwardfeng-db force-pushed the edwardfeng-db/validator-list-max branch from 0b15ae7 to a3f639f Compare October 11, 2024 05:03
Comment on lines +34 to 35
{{if .IsJson}}tfsdk:"{{if and (ne .Entity.Terraform nil) (ne .Entity.Terraform.Alias "") }}{{.Entity.Terraform.Alias}}{{else}}{{.Name}}{{end}}" tf:"{{- $first := true -}}{{- if not .Required -}}{{- if not $first -}},{{end}}optional{{- $first = false -}}{{- end -}}{{- if .Entity.IsObject -}}{{- if not $first -}},{{end}}object{{- $first = false -}}{{- end -}}"{{else}}tfsdk:"-"{{end -}}
{{- end -}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is kinda ugly, mainly because I need to keep track of whether the item is the first one in the tf tags to add commas in the proper positions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hectorcast-db wondering if there's a better way

Copy link
Contributor

Choose a reason for hiding this comment

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

You can create a function in the Go code to return the tfsdk options already formatted. So you can have all this logic in Go, which is more readable.

{{if .IsJson}}tfsdk:".Entity.TFSDKOptions" tf:".Entify.TFOptions"{{end-}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, merging this PR for now to unblock and I'll work on the go function as a follow up

Copy link
Contributor

@hectorcast-db hectorcast-db left a comment

Choose a reason for hiding this comment

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

Added a comment on how to make it more readable. Otherwise, LGTM

Comment on lines +34 to 35
{{if .IsJson}}tfsdk:"{{if and (ne .Entity.Terraform nil) (ne .Entity.Terraform.Alias "") }}{{.Entity.Terraform.Alias}}{{else}}{{.Name}}{{end}}" tf:"{{- $first := true -}}{{- if not .Required -}}{{- if not $first -}},{{end}}optional{{- $first = false -}}{{- end -}}{{- if .Entity.IsObject -}}{{- if not $first -}},{{end}}object{{- $first = false -}}{{- end -}}"{{else}}tfsdk:"-"{{end -}}
{{- end -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can create a function in the Go code to return the tfsdk options already formatted. So you can have all this logic in Go, which is more readable.

{{if .IsJson}}tfsdk:".Entity.TFSDKOptions" tf:".Entify.TFOptions"{{end-}}

Copy link
Contributor

@mgyucht mgyucht left a comment

Choose a reason for hiding this comment

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

Behavior seems correct to me, but it would be good to take my points into account before merging.

@edwardfeng-db edwardfeng-db added this pull request to the merge queue Oct 11, 2024
Merged via the queue into main with commit 4a70e64 Oct 11, 2024
7 checks passed
@edwardfeng-db edwardfeng-db deleted the edwardfeng-db/validator-list-max branch October 11, 2024 18:01
hectorcast-db added a commit that referenced this pull request Oct 17, 2024
### New Features and Improvements

 * Add `databricks_registered_model` data source ([#4033](#4033)).
 * Add data source `databricks_notification_destinations` ([#4087](#4087)).

### Bug Fixes

 * Fix databricks_cluster_pluginframework data source ([#4097](#4097)).
 * Mark unity_catalog_provisioning_state as ReadOnly ([#4116](#4116)).
 * Tolerate invalid keys in `databricks_workspace_conf` ([#4102](#4102)).
 * force send `read_only` in `databricks_external_location` when it's changed ([#4067](#4067)).
 * force send `read_only` in `databricks_storage_credential` when it's changed ([#4083](#4083)).

### Documentation

 * Document `budget_policy_id` in `databricks_pipeline` and `databricks_job` ([#4110](#4110)).
 * Reformat code examples in documentation ([#4081](#4081)).
 * Update documentation for `databricks_model_serving` ([#4115](#4115)).
 * Updates to resource examples ([#4093](#4093)).

### Internal Changes

 * Add maxItem=1 validator for object types in plugin framework schema ([#4094](#4094)).
 * Fix acceptance test for `databricks_registered_model` data source ([#4105](#4105)).
 * Generate Effective Fields ([#4057](#4057)).
 * Generate Effective Fields ([#4112](#4112)).
 * Set SDK used in the useragent in context ([#4092](#4092)).
 * Support adding context in resources and data sources ([#4085](#4085)).
 * Update plugin framework schema to use ListNestedBlocks ([#4040](#4040)).
github-merge-queue bot pushed a commit that referenced this pull request Oct 18, 2024
### New Features and Improvements

* Add `databricks_registered_model` data source
([#4033](#4033)).
* Add data source `databricks_notification_destinations`
([#4087](#4087)).


### Bug Fixes

* Fix databricks_cluster_pluginframework data source
([#4097](#4097)).
* Mark unity_catalog_provisioning_state as ReadOnly
([#4116](#4116)).
* Tolerate invalid keys in `databricks_workspace_conf`
([#4102](#4102)).
* force send `read_only` in `databricks_external_location` when it's
changed
([#4067](#4067)).
* force send `read_only` in `databricks_storage_credential` when it's
changed
([#4083](#4083)).


### Documentation

* Document `budget_policy_id` in `databricks_pipeline` and
`databricks_job`
([#4110](#4110)).
* Reformat code examples in documentation
([#4081](#4081)).
* Update documentation for `databricks_model_serving`
([#4115](#4115)).
* Updates to resource examples
([#4093](#4093)).


### Internal Changes

* Add maxItem=1 validator for object types in plugin framework schema
([#4094](#4094)).
* Fix acceptance test for `databricks_registered_model` data source
([#4105](#4105)).
* Generate Effective Fields
([#4057](#4057)).
* Generate Effective Fields
([#4112](#4112)).
* Set SDK used in the useragent in context
([#4092](#4092)).
* Support adding context in resources and data sources
([#4085](#4085)).
* Update plugin framework schema to use ListNestedBlocks
([#4040](#4040)).
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