@@ -38,6 +38,27 @@ func updateForceSendFields(req *catalog.UpdateMetastore) {
3838 }
3939}
4040
41+ func toCreateAccountsMetastore (create * catalog.CreateMetastore ) * catalog.CreateAccountsMetastore {
42+ return & catalog.CreateAccountsMetastore {
43+ Name : create .Name ,
44+ Region : create .Region ,
45+ StorageRoot : create .StorageRoot ,
46+ ForceSendFields : create .ForceSendFields ,
47+ }
48+ }
49+
50+ func toUpdateAccountsMetastore (update * catalog.UpdateMetastore ) * catalog.UpdateAccountsMetastore {
51+ return & catalog.UpdateAccountsMetastore {
52+ DeltaSharingOrganizationName : update .DeltaSharingOrganizationName ,
53+ DeltaSharingRecipientTokenLifetimeInSeconds : update .DeltaSharingRecipientTokenLifetimeInSeconds ,
54+ DeltaSharingScope : update .DeltaSharingScope ,
55+ Owner : update .Owner ,
56+ PrivilegeModelVersion : update .PrivilegeModelVersion ,
57+ StorageRootCredentialId : update .StorageRootCredentialId ,
58+ ForceSendFields : update .ForceSendFields ,
59+ }
60+ }
61+
4162func ResourceMetastore () common.Resource {
4263 s := common .StructToSchema (MetastoreInfo {},
4364 func (m map [string ]* schema.Schema ) map [string ]* schema.Schema {
@@ -74,7 +95,7 @@ func ResourceMetastore() common.Resource {
7495 return c .AccountOrWorkspaceRequest (func (acc * databricks.AccountClient ) error {
7596 mi , err := acc .Metastores .Create (ctx ,
7697 catalog.AccountsCreateMetastore {
77- MetastoreInfo : & create ,
98+ MetastoreInfo : toCreateAccountsMetastore ( & create ) ,
7899 })
79100 if err != nil {
80101 return err
@@ -85,7 +106,7 @@ func ResourceMetastore() common.Resource {
85106 }
86107 _ , err = acc .Metastores .Update (ctx , catalog.AccountsUpdateMetastore {
87108 MetastoreId : mi .MetastoreInfo .MetastoreId ,
88- MetastoreInfo : & update ,
109+ MetastoreInfo : toUpdateAccountsMetastore ( & update ) ,
89110 })
90111 if err != nil {
91112 return err
@@ -131,12 +152,13 @@ func ResourceMetastore() common.Resource {
131152
132153 return c .AccountOrWorkspaceRequest (func (acc * databricks.AccountClient ) error {
133154 if d .HasChange ("owner" ) {
155+ ownerUpdate := catalog.UpdateMetastore {
156+ Id : update .Id ,
157+ Owner : update .Owner ,
158+ }
134159 _ , err := acc .Metastores .Update (ctx , catalog.AccountsUpdateMetastore {
135- MetastoreId : d .Id (),
136- MetastoreInfo : & catalog.UpdateMetastore {
137- Id : update .Id ,
138- Owner : update .Owner ,
139- },
160+ MetastoreId : d .Id (),
161+ MetastoreInfo : toUpdateAccountsMetastore (& ownerUpdate ),
140162 })
141163 if err != nil {
142164 return err
@@ -150,18 +172,19 @@ func ResourceMetastore() common.Resource {
150172 update .Owner = ""
151173 _ , err := acc .Metastores .Update (ctx , catalog.AccountsUpdateMetastore {
152174 MetastoreId : d .Id (),
153- MetastoreInfo : & update ,
175+ MetastoreInfo : toUpdateAccountsMetastore ( & update ) ,
154176 })
155177 if err != nil {
156178 if d .HasChange ("owner" ) {
157179 // Rollback
158180 old , new := d .GetChange ("owner" )
181+ rollbackUpdate := catalog.UpdateMetastore {
182+ Id : update .Id ,
183+ Owner : old .(string ),
184+ }
159185 _ , rollbackErr := acc .Metastores .Update (ctx , catalog.AccountsUpdateMetastore {
160- MetastoreId : d .Id (),
161- MetastoreInfo : & catalog.UpdateMetastore {
162- Id : update .Id ,
163- Owner : old .(string ),
164- },
186+ MetastoreId : d .Id (),
187+ MetastoreInfo : toUpdateAccountsMetastore (& rollbackUpdate ),
165188 })
166189 if rollbackErr != nil {
167190 return common .OwnerRollbackError (err , rollbackErr , old .(string ), new .(string ))
@@ -207,7 +230,8 @@ func ResourceMetastore() common.Resource {
207230 Delete : func (ctx context.Context , d * schema.ResourceData , c * common.DatabricksClient ) error {
208231 force := d .Get ("force_destroy" ).(bool )
209232 return c .AccountOrWorkspaceRequest (func (acc * databricks.AccountClient ) error {
210- return acc .Metastores .Delete (ctx , catalog.DeleteAccountMetastoreRequest {Force : force , MetastoreId : d .Id ()})
233+ _ , err := acc .Metastores .Delete (ctx , catalog.DeleteAccountMetastoreRequest {Force : force , MetastoreId : d .Id ()})
234+ return err
211235 }, func (w * databricks.WorkspaceClient ) error {
212236 return w .Metastores .Delete (ctx , catalog.DeleteMetastoreRequest {Force : force , Id : d .Id ()})
213237 })
0 commit comments