Skip to content

Commit c1c5067

Browse files
nkvuongalexottrauchy
authored
[Fix] Suppressing diff for databricks_catalog attributes (#4976)
## Changes - Suppressing diff for `databricks_catalog` attributes - Switch to Go SDK - Resolves #4971 ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] covered with integration tests in `internal/acceptance` - [x] using Go SDK - [x] has entry in `NEXT_CHANGELOG.md` file --------- Co-authored-by: Alex Ott <[email protected]> Co-authored-by: Alex Ott <[email protected]> Co-authored-by: Omer Lachish <[email protected]>
1 parent 461ec8a commit c1c5067

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
### Bug Fixes
1313

14+
* Suppress diff for `databricks_catalog` attributes ([#4975](https://github.com/databricks/terraform-provider-databricks/pull/4975))
1415
* Correct which file event fields should be reset in `databricks_external_location` ([#4945](https://github.com/databricks/terraform-provider-databricks/pull/4945))
1516
* Fix `ExactlyOneOf` in `databricks_app` ([#4946](https://github.com/databricks/terraform-provider-databricks/pull/4946))
1617
* Enable update of `databricks_mws_ncc_private_endpoint_rule` resource ([#4957](https://github.com/databricks/terraform-provider-databricks/pull/4957))

catalog/resource_catalog.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,36 @@ func ucDirectoryPathSlashAndEmptySuppressDiff(k, old, new string, d *schema.Reso
2828
return false
2929
}
3030

31-
type CatalogInfo struct {
32-
Name string `json:"name"`
33-
Comment string `json:"comment,omitempty"`
34-
StorageRoot string `json:"storage_root,omitempty" tf:"force_new"`
35-
ProviderName string `json:"provider_name,omitempty" tf:"force_new,conflicts:storage_root"`
36-
ShareName string `json:"share_name,omitempty" tf:"force_new,conflicts:storage_root"`
37-
ConnectionName string `json:"connection_name,omitempty" tf:"force_new,conflicts:storage_root"`
38-
EnablePredictiveOptimization string `json:"enable_predictive_optimization,omitempty" tf:"computed"`
39-
Options map[string]string `json:"options,omitempty"`
40-
Properties map[string]string `json:"properties,omitempty"`
41-
Owner string `json:"owner,omitempty" tf:"computed"`
42-
IsolationMode string `json:"isolation_mode,omitempty" tf:"computed"`
43-
MetastoreID string `json:"metastore_id,omitempty" tf:"computed"`
44-
}
45-
4631
func ResourceCatalog() common.Resource {
47-
catalogSchema := common.StructToSchema(CatalogInfo{},
32+
catalogSchema := common.StructToSchema(catalog.CatalogInfo{},
4833
func(s map[string]*schema.Schema) map[string]*schema.Schema {
4934
s["force_destroy"] = &schema.Schema{
5035
Type: schema.TypeBool,
5136
Optional: true,
5237
Default: false,
5338
}
54-
common.CustomizeSchemaPath(s, "storage_root").SetCustomSuppressDiff(ucDirectoryPathSlashOnlySuppressDiff)
55-
common.CustomizeSchemaPath(s, "name").SetCustomSuppressDiff(common.EqualFoldDiffSuppress)
39+
// mark all computed values
40+
for _, v := range []string{"owner", "isolation_mode", "metastore_id", "enable_predictive_optimization"} {
41+
common.CustomizeSchemaPath(s, v).SetOptional().SetComputed()
42+
}
43+
// case sensitive suppress diff
44+
for _, v := range []string{"name", "connection_name", "share_name", "provider_name"} {
45+
common.CustomizeSchemaPath(s, v).SetCustomSuppressDiff(common.EqualFoldDiffSuppress)
46+
}
47+
// can only have one of provider_name + share_name, connection_name or storage_root
48+
common.CustomizeSchemaPath(s, "connection_name").SetConflictsWith([]string{"storage_root", "provider_name", "share_name"}).SetForceNew()
49+
for _, v := range []string{"provider_name", "share_name"} {
50+
common.CustomizeSchemaPath(s, v).SetConflictsWith([]string{"connection_name", "storage_root"}).SetForceNew()
51+
}
52+
common.CustomizeSchemaPath(s, "storage_root").SetCustomSuppressDiff(ucDirectoryPathSlashOnlySuppressDiff).SetForceNew()
5653
common.CustomizeSchemaPath(s, "enable_predictive_optimization").SetValidateFunc(
5754
validation.StringInSlice([]string{"DISABLE", "ENABLE", "INHERIT"}, false),
5855
)
56+
for _, v := range []string{"catalog_type", "created_at", "created_by",
57+
"updated_at", "updated_by", "securable_type", "full_name"} {
58+
common.CustomizeSchemaPath(s, v).SetReadOnly()
59+
}
60+
common.CustomizeSchemaPath(s, "effective_predictive_optimization_flag").SetComputed().SetSuppressDiff()
5961
return s
6062
})
6163
return common.Resource{

catalog/resource_catalog_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,14 @@ func TestCatalogSuppressCaseSensitivity(t *testing.T) {
773773
"isolation_mode": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
774774
"owner": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
775775
"enable_predictive_optimization": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
776+
"updated_by": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
777+
"updated_at": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
778+
"created_by": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
779+
"created_at": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
780+
"securable_type": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
781+
"catalog_type": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
782+
"effective_predictive_optimization_flag.#": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
783+
"full_name": {Old: "", New: "", NewComputed: true, NewRemoved: false, RequiresNew: false, Sensitive: false},
776784
},
777785
HCL: `
778786
name = "A"

exporter/impl_uc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func listUcCatalogs(ic *importContext) error {
4545
}
4646

4747
func importUcCatalog(ic *importContext, r *resource) error {
48-
var cat tf_uc.CatalogInfo
48+
var cat catalog.CatalogInfo
4949
s := ic.Resources["databricks_catalog"].Schema
5050
common.DataToStructPointer(r.Data, s, &cat)
5151

@@ -59,7 +59,7 @@ func importUcCatalog(ic *importContext, r *resource) error {
5959
if cat.ConnectionName != "" {
6060
ic.Emit(&resource{
6161
Resource: "databricks_connection",
62-
ID: cat.MetastoreID + "|" + cat.ConnectionName,
62+
ID: cat.MetastoreId + "|" + cat.ConnectionName,
6363
})
6464
} else if cat.ShareName == "" {
6565
// TODO: We need to be careful here if we add more catalog types... Really we need to have CatalogType in resource

0 commit comments

Comments
 (0)