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

Use common.Resource consistently throughout the provider #3193

Merged
merged 8 commits into from
Feb 1, 2024

Conversation

mgyucht
Copy link
Contributor

@mgyucht mgyucht commented Jan 31, 2024

Changes

Purely a refactor of existing resources to consistently use common.Resource throughout the provider, instead of a mixture of *schema.Resource and common.Resource. This is needed for #3188, in which I'll add a field in common.Resource indicating whether or not the workspace_id attribute needs to be added to the schema.

Tests

Passes integration tests (with one exception, which is being fixed in #3200).

  • 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 January 31, 2024 20:54
@mgyucht mgyucht requested review from tanmay-db and removed request for a team January 31, 2024 20:54
@@ -654,8 +654,8 @@ func DataToStructPointer(d *schema.ResourceData, scm map[string]*schema.Schema,
}

// DataToReflectValue reads reflect value from data
func DataToReflectValue(d *schema.ResourceData, r *schema.Resource, rv reflect.Value) error {
return readReflectValueFromData([]string{}, d, rv, r.Schema)
func DataToReflectValue(d *schema.ResourceData, s map[string]*schema.Schema, rv reflect.Value) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only places where this is used construct a resource in-line purely to pass the schema, so I changed it to accept the schema instead.

Comment on lines -617 to -618
diags := r.ReadContext(context.Background(), d, nil)
assert.Len(t, diags, 1)
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 an unnecessary test case, as the provider will ensure that the meta argument is always set to a non-nil *DatabricksClient.

Comment on lines +28 to +29
DeprecationMessage string
Importer *schema.ResourceImporter
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the only fields from schema.Resource that need to be added to this Resource structure.

@@ -161,6 +161,10 @@ func getCommonClusterObject(clustersAPI clusters.ClustersAPI, clusterName string
func getOrCreateMountingCluster(clustersAPI clusters.ClustersAPI) (string, error) {
cluster, err := clustersAPI.GetOrCreateRunningCluster("terraform-mount", getCommonClusterObject(clustersAPI, "terraform-mount"))
if err != nil {
// Do not treat missing cluster like a missing resource.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed because common.Resource has a blanket catch-all for missing responses from APIs, but in this case, we need to prevent that from being triggered.

@codecov-commenter
Copy link

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (510fd60) 83.20% compared to head (26234c7) 83.26%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3193      +/-   ##
==========================================
+ Coverage   83.20%   83.26%   +0.05%     
==========================================
  Files         168      168              
  Lines       15013    15018       +5     
==========================================
+ Hits        12492    12505      +13     
+ Misses       1787     1781       -6     
+ Partials      734      732       -2     
Files Coverage Δ
access/resource_ip_access_list.go 80.95% <ø> (ø)
access/resource_permission_assignment.go 95.45% <ø> (ø)
access/resource_sql_permissions.go 86.11% <ø> (ø)
aws/data_instance_profiles.go 90.00% <ø> (ø)
aws/resource_group_instance_profile.go 100.00% <ø> (ø)
aws/resource_instance_profile.go 65.89% <ø> (ø)
aws/resource_service_principal_role.go 73.33% <ø> (ø)
aws/resource_user_instance_profile.go 100.00% <ø> (ø)
aws/resource_user_role.go 100.00% <ø> (ø)
catalog/data_catalogs.go 100.00% <ø> (ø)
... and 118 more

... and 1 file with indirect coverage changes

d := r.TestResourceData()
d.Set("name", "a name")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual resource definition adds a "preprocessing" step that checks whether the name and uri attributes are set.

Copy link
Contributor

@nfx nfx left a comment

Choose a reason for hiding this comment

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

lgtm

@mgyucht mgyucht added this pull request to the merge queue Feb 1, 2024
Merged via the queue into main with commit d3acc7b Feb 1, 2024
5 checks passed
@mgyucht mgyucht deleted the use-common-resource-everywhere branch February 1, 2024 12:18
tanmay-db added a commit that referenced this pull request Feb 5, 2024
### New Features and Improvements
* Exporter: timestamps are now added to log entries ([#3146](#3146)).
* Validate metastore id for databricks_grant and databricks_grants resources ([#3159](#3159)).
* Exporter: Skip emitting of clusters that come from more cluster sources ([#3161](#3161)).
* Fix typo in docs ([#3166](#3166)).
* Migrate cluster schema to use the go-sdk struct ([#3076](#3076)).
* Introduce Generic Settings Resource ([#2997](#2997)).
* Update actions/setup-go to v5 ([#3154](#3154)).
* Change default branch from `master` to `main` ([#3174](#3174)).
* Add .codegen.json configuration ([#3180](#3180)).
* Exporter: performance improvements for big workspaces ([#3167](#3167)).
* update ([#3192](#3192)).
* Exporter: fix generation of cluster policy resources ([#3185](#3185)).
* Fix unit test ([#3201](#3201)).
* Suppress diff should apply to new fields added in the same chained call to CustomizableSchema ([#3200](#3200)).
* Various documentation updates ([#3198](#3198)).
* Use common.Resource consistently throughout the provider ([#3193](#3193)).
* Extending customizable schema with `AtLeastOneOf`, `ExactlyOneOf`, `RequiredWith` ([#3182](#3182)).
* Fix `databricks_connection` regression when creating without owner ([#3186](#3186)).
* add test code for job task order ([#3183](#3183)).
* Allow using empty strings as job parameters ([#3158](#3158)).
* Fix notebook parameters in acceptance test ([#3205](#3205)).
* Exporter: Add retries for `Search`, `ReadContext` and `Import` operations when importing the resource ([#3202](#3202)).
* Fixed updating owners for UC resources ([#3189](#3189)).
* Adds `databricks_volumes` as data source  ([#3150](#3150)).

### Documentation Changes

### Exporter

### Internal Changes
@tanmay-db tanmay-db mentioned this pull request Feb 5, 2024
github-merge-queue bot pushed a commit that referenced this pull request Feb 6, 2024
* Release v1.35.1

### New Features and Improvements
* Exporter: timestamps are now added to log entries ([#3146](#3146)).
* Validate metastore id for databricks_grant and databricks_grants resources ([#3159](#3159)).
* Exporter: Skip emitting of clusters that come from more cluster sources ([#3161](#3161)).
* Fix typo in docs ([#3166](#3166)).
* Migrate cluster schema to use the go-sdk struct ([#3076](#3076)).
* Introduce Generic Settings Resource ([#2997](#2997)).
* Update actions/setup-go to v5 ([#3154](#3154)).
* Change default branch from `master` to `main` ([#3174](#3174)).
* Add .codegen.json configuration ([#3180](#3180)).
* Exporter: performance improvements for big workspaces ([#3167](#3167)).
* update ([#3192](#3192)).
* Exporter: fix generation of cluster policy resources ([#3185](#3185)).
* Fix unit test ([#3201](#3201)).
* Suppress diff should apply to new fields added in the same chained call to CustomizableSchema ([#3200](#3200)).
* Various documentation updates ([#3198](#3198)).
* Use common.Resource consistently throughout the provider ([#3193](#3193)).
* Extending customizable schema with `AtLeastOneOf`, `ExactlyOneOf`, `RequiredWith` ([#3182](#3182)).
* Fix `databricks_connection` regression when creating without owner ([#3186](#3186)).
* add test code for job task order ([#3183](#3183)).
* Allow using empty strings as job parameters ([#3158](#3158)).
* Fix notebook parameters in acceptance test ([#3205](#3205)).
* Exporter: Add retries for `Search`, `ReadContext` and `Import` operations when importing the resource ([#3202](#3202)).
* Fixed updating owners for UC resources ([#3189](#3189)).
* Adds `databricks_volumes` as data source  ([#3150](#3150)).

### Documentation Changes

### Exporter

### Internal Changes

* upd

* readable

* upd

* upd
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