Skip to content

Commit 2215c1b

Browse files
authored
[Internal] Add client support in CustomizeDiff for SDKv2 resources (#5171)
## Changes <!-- Summary of your changes that are easy to understand --> - Pass the DatabricksClient in CustomizeDiff for resources and data sources - The client would be used to validate the workspace_id supplied in provider_config during plan phase. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - Unit tests
1 parent 4643592 commit 2215c1b

16 files changed

+30
-28
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
* Initial support for resources implemented with plugin framework ([#5176](https://github.com/databricks/terraform-provider-databricks/pull/5176)).
2222

2323
### Internal Changes
24+
* Add client support in CustomizeDiff for SDKv2 resources and data sources ([#5171](https://github.com/databricks/terraform-provider-databricks/pull/5171)).

access/resource_permission_assignment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ func ResourcePermissionAssignment() common.Resource {
148148
})
149149
return common.Resource{
150150
Schema: s,
151-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
152-
return common.NamespaceCustomizeDiff(d)
151+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *common.DatabricksClient) error {
152+
return common.NamespaceCustomizeDiff(ctx, d, c)
153153
},
154154
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
155155
c, err := c.DatabricksClientForUnifiedProvider(ctx, d)

catalog/resource_catalog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func ResourceCatalog() common.Resource {
216216
}
217217
return w.Catalogs.Delete(ctx, catalog.DeleteCatalogRequest{Force: force, Name: d.Id()})
218218
},
219-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
219+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *common.DatabricksClient) error {
220220
// The only scenario in which we can update options is for the `authorized_paths` key. Any
221221
// other changes to the options field will result in an error.
222222
if d.HasChange("options") {

catalog/resource_sql_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ func ResourceSqlTable() common.Resource {
611611
tableSchema := common.StructToSchema(SqlTableInfo{}, nil)
612612
return common.Resource{
613613
Schema: tableSchema,
614-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
614+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *common.DatabricksClient) error {
615615
if d.HasChange("column") {
616616
var newTableStruct SqlTableInfo
617617
common.DiffToStructPointer(d, tableSchema, &newTableStruct)

catalog/resource_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func ResourceTable() common.Resource {
7878
"view_definition", "comment", "properties"})
7979
return common.Resource{
8080
Schema: tableSchema,
81-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
81+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *common.DatabricksClient) error {
8282
if d.Get("table_type") != "EXTERNAL" {
8383
return nil
8484
}

clusters/resource_cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const (
3131

3232
func ResourceCluster() common.Resource {
3333
return common.Resource{
34-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
35-
return common.NamespaceCustomizeDiff(d)
34+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *common.DatabricksClient) error {
35+
return common.NamespaceCustomizeDiff(ctx, d, c)
3636
},
3737
Create: resourceClusterCreate,
3838
Read: resourceClusterRead,

clusters/resource_library.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func ResourceLibrary() common.Resource {
4545
}
4646
return common.Resource{
4747
Schema: libraySdkSchema,
48-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
49-
return common.NamespaceCustomizeDiff(d)
48+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *common.DatabricksClient) error {
49+
return common.NamespaceCustomizeDiff(ctx, d, c)
5050
},
5151
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
5252
w, err := c.WorkspaceClientUnifiedProvider(ctx, d)

common/resource.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/resource_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func TestRecoverableFromPanic(t *testing.T) {
259259

260260
func TestCustomizeDiffRobustness(t *testing.T) {
261261
r := Resource{
262-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
262+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *DatabricksClient) error {
263263
return fmt.Errorf("nope")
264264
},
265265
}.ToResource()
@@ -268,16 +268,16 @@ func TestCustomizeDiffRobustness(t *testing.T) {
268268
ctx = context.WithValue(ctx, ResourceName, "sample")
269269

270270
err := r.CustomizeDiff(ctx, nil, nil)
271-
assert.EqualError(t, err, "cannot customize diff for sample: nope")
271+
assert.EqualError(t, err, "cannot customize diff for sample: expected *DatabricksClient, got <nil>")
272272

273273
r = Resource{
274-
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff) error {
274+
CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, c *DatabricksClient) error {
275275
panic("oops")
276276
},
277277
}.ToResource()
278278

279279
err = r.CustomizeDiff(ctx, nil, nil)
280-
assert.EqualError(t, err, "cannot customize diff for sample: panic: oops")
280+
assert.EqualError(t, err, "cannot customize diff for sample: expected *DatabricksClient, got <nil>")
281281
}
282282

283283
func TestWorkspacePathPrefixDiffSuppress(t *testing.T) {

common/unified_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func NamespaceCustomizeSchemaMap(m map[string]*schema.Schema) map[string]*schema
8585

8686
// NamespaceCustomizeDiff is used to customize the diff for the provider configuration
8787
// in a resource diff.
88-
func NamespaceCustomizeDiff(d *schema.ResourceDiff) error {
88+
func NamespaceCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, c *DatabricksClient) error {
8989
// Force New
9090
workspaceIDKey := workspaceIDSchemaKey
9191
oldWorkspaceID, newWorkspaceID := d.GetChange(workspaceIDKey)

0 commit comments

Comments
 (0)