Skip to content

Commit 9a5e960

Browse files
alexottfjakobs
andauthored
Add suppress diff for URL change that only change / (remove or add) in UC resources (#2336)
This fixes #2335 Co-authored-by: Fabian Jakobs <[email protected]>
1 parent fd509fb commit 9a5e960

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

catalog/resource_catalog.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ package catalog
33
import (
44
"context"
55
"fmt"
6+
"log"
67

78
"github.com/databricks/terraform-provider-databricks/common"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
)
1011

12+
func ucDirectoryPathSuppressDiff(k, old, new string, d *schema.ResourceData) bool {
13+
if (new == (old + "/")) || (old == (new + "/")) {
14+
log.Printf("[DEBUG] Ignoring configuration drift from %s to %s", old, new)
15+
return true
16+
}
17+
return false
18+
}
19+
1120
type CatalogsAPI struct {
1221
client *common.DatabricksClient
1322
context context.Context
@@ -68,6 +77,7 @@ func ResourceCatalog() *schema.Resource {
6877
Optional: true,
6978
Default: false,
7079
}
80+
m["storage_root"].DiffSuppressFunc = ucDirectoryPathSuppressDiff
7181
return m
7282
})
7383
update := updateFunctionFactory("/unity-catalog/catalogs", []string{"owner", "comment", "properties"})

catalog/resource_catalog_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,12 @@ func TestCatalogCreateDeltaSharing(t *testing.T) {
303303
`,
304304
}.ApplyNoError(t)
305305
}
306+
307+
func TestUcDirectoryPathSuppressDiff(t *testing.T) {
308+
assert.True(t, ucDirectoryPathSuppressDiff("", "abfss://[email protected]/TF_DIR_WITH_SLASH",
309+
"abfss://[email protected]/TF_DIR_WITH_SLASH/", nil))
310+
assert.True(t, ucDirectoryPathSuppressDiff("", "abfss://[email protected]/TF_DIR_WITH_SLASH/",
311+
"abfss://[email protected]/TF_DIR_WITH_SLASH", nil))
312+
assert.False(t, ucDirectoryPathSuppressDiff("", "abfss://[email protected]/new_dir",
313+
"abfss://[email protected]/TF_DIR_WITH_SLASH/", nil))
314+
}

catalog/resource_external_location.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func ResourceExternalLocation() *schema.Resource {
4646
m["skip_validation"].DiffSuppressFunc = func(k, old, new string, d *schema.ResourceData) bool {
4747
return old == "false" && new == "true"
4848
}
49+
m["url"].DiffSuppressFunc = ucDirectoryPathSuppressDiff
4950
return m
5051
})
5152
update := updateFunctionFactory("/unity-catalog/external-locations", []string{"owner", "comment", "url", "credential_name"})

catalog/resource_schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func ResourceSchema() *schema.Resource {
7373
Optional: true,
7474
Default: false,
7575
}
76+
m["storage_root"].DiffSuppressFunc = ucDirectoryPathSuppressDiff
7677
return m
7778
})
7879
update := updateFunctionFactory("/unity-catalog/schemas", []string{"owner", "comment", "properties"})

0 commit comments

Comments
 (0)