Skip to content

Commit

Permalink
don't update databricks_metastore during creation if not required
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong committed Jul 18, 2024
1 parent 165cda6 commit 0844b74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 7 additions & 4 deletions catalog/resource_metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func ResourceMetastore() common.Resource {
common.DataToStructPointer(d, s, &create)
common.DataToStructPointer(d, s, &update)
updateForceSendFields(&update)
emptyRequest, err := common.IsRequestEmpty(update)
if err != nil {
return err
}
return c.AccountOrWorkspaceRequest(func(acc *databricks.AccountClient) error {
mi, err := acc.Metastores.Create(ctx,
catalog.AccountsCreateMetastore{
Expand All @@ -75,10 +79,6 @@ func ResourceMetastore() common.Resource {
if err != nil {
return err
}
emptyRequest, err := common.IsRequestEmpty(update)
if err != nil {
return err
}
d.SetId(mi.MetastoreInfo.MetastoreId)
if emptyRequest {
return nil
Expand All @@ -97,6 +97,9 @@ func ResourceMetastore() common.Resource {
return err
}
d.SetId(mi.MetastoreId)
if emptyRequest {
return nil
}
update.Id = mi.MetastoreId
_, err = w.Metastores.Update(ctx, update)
if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions catalog/resource_metastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ func TestCreateMetastore(t *testing.T) {
}).Return(&catalog.MetastoreInfo{
MetastoreId: "abc",
}, nil)
e.Update(mock.Anything, catalog.UpdateMetastore{
Id: "abc",
}).Return(&catalog.MetastoreInfo{
Name: "a",
}, nil)
e.GetById(mock.Anything, "abc").Return(&catalog.MetastoreInfo{
StorageRoot: "s3://b/abc",
Name: "a",
Expand Down

0 comments on commit 0844b74

Please sign in to comment.