66 "log"
77
88 "github.com/databricks/databricks-sdk-go/service/catalog"
9+ "github.com/databricks/terraform-provider-databricks/catalog/bindings"
910 "github.com/databricks/terraform-provider-databricks/common"
1011 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1112 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -86,14 +87,7 @@ func ResourceCatalog() common.Resource {
8687 d .SetId (ci .Name )
8788
8889 // Update owner, isolation mode or predictive optimization if it is provided
89- updateRequired := false
90- for _ , key := range []string {"owner" , "isolation_mode" , "enable_predictive_optimization" } {
91- if d .Get (key ) != "" {
92- updateRequired = true
93- break
94- }
95- }
96- if ! updateRequired {
90+ if ! updateRequired (d , []string {"owner" , "isolation_mode" , "enable_predictive_optimization" }) {
9791 return nil
9892 }
9993 var updateCatalogRequest catalog.UpdateCatalog
@@ -104,25 +98,7 @@ func ResourceCatalog() common.Resource {
10498 return err
10599 }
106100
107- if d .Get ("isolation_mode" ) != "ISOLATED" {
108- return nil
109- }
110- // Bind the current workspace if the catalog is isolated, otherwise the read will fail
111- currentMetastoreAssignment , err := w .Metastores .Current (ctx )
112- if err != nil {
113- return err
114- }
115- _ , err = w .WorkspaceBindings .UpdateBindings (ctx , catalog.UpdateWorkspaceBindingsParameters {
116- SecurableName : ci .Name ,
117- SecurableType : "catalog" ,
118- Add : []catalog.WorkspaceBinding {
119- {
120- BindingType : catalog .WorkspaceBindingBindingTypeBindingTypeReadWrite ,
121- WorkspaceId : currentMetastoreAssignment .WorkspaceId ,
122- },
123- },
124- })
125- return err
101+ return bindings .AddCurrentWorkspaceBindings (ctx , d , w , ci .Name , "catalog" )
126102 },
127103 Read : func (ctx context.Context , d * schema.ResourceData , c * common.DatabricksClient ) error {
128104 w , err := c .WorkspaceClient ()
@@ -191,21 +167,7 @@ func ResourceCatalog() common.Resource {
191167 return nil
192168 }
193169 // Bind the current workspace if the catalog is isolated, otherwise the read will fail
194- currentMetastoreAssignment , err := w .Metastores .Current (ctx )
195- if err != nil {
196- return err
197- }
198- _ , err = w .WorkspaceBindings .UpdateBindings (ctx , catalog.UpdateWorkspaceBindingsParameters {
199- SecurableName : ci .Name ,
200- SecurableType : "catalog" ,
201- Add : []catalog.WorkspaceBinding {
202- {
203- BindingType : catalog .WorkspaceBindingBindingTypeBindingTypeReadWrite ,
204- WorkspaceId : currentMetastoreAssignment .WorkspaceId ,
205- },
206- },
207- })
208- return err
170+ return bindings .AddCurrentWorkspaceBindings (ctx , d , w , ci .Name , "catalog" )
209171 },
210172 Delete : func (ctx context.Context , d * schema.ResourceData , c * common.DatabricksClient ) error {
211173 w , err := c .WorkspaceClient ()
0 commit comments