Skip to content

Commit e30b8e0

Browse files
authored
Add suppress diff for path argument of databricks_directory resource when it ends with / (#2204)
Right now if we have directory declared as follows: ```hcl resource "databricks_directory" "test" { path = "/Users/user@domain/TF_DIR_WITH_SLASH/" } ``` on update it's trying to recreate resource because REST API returns normalized path, without ending `/`, and this leads to following: ``` # databricks_directory.test must be replaced -/+ resource "databricks_directory" "test" { ~ id = "/Users/user@domain/TF_DIR_WITH_SLASH/" -> (known after apply) ~ object_id = 696671922817959 -> (known after apply) ~ path = "/Users/user@domain/TF_DIR_WITH_SLASH" -> "/Users/user@domain/TF_DIR_WITH_SLASH/" # forces replacement # (1 unchanged attribute hidden) } ``` this patch fixes this behavior
1 parent 949c108 commit e30b8e0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

workspace/resource_directory.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010
)
1111

12+
func directoryPathSuppressDiff(k, old, new string, d *schema.ResourceData) bool {
13+
return new == (old + "/")
14+
}
15+
1216
// ResourceDirectory manages directories
1317
func ResourceDirectory() *schema.Resource {
1418
s := map[string]*schema.Schema{
1519
"path": {
16-
Type: schema.TypeString,
17-
Required: true,
18-
ForceNew: true,
20+
Type: schema.TypeString,
21+
Required: true,
22+
ForceNew: true,
23+
DiffSuppressFunc: directoryPathSuppressDiff,
1924
},
2025
"object_id": {
2126
Type: schema.TypeInt,

workspace/resource_directory_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,8 @@ func TestResourceDirectoryReadNotDirectory(t *testing.T) {
258258
qa.AssertErrorStartsWith(t, err, "different object type")
259259
assert.Equal(t, "", d.Id(), "Id should be empty for different object type read")
260260
}
261+
262+
func TestDirectoryPathSuppressDiff(t *testing.T) {
263+
assert.True(t, directoryPathSuppressDiff("", "/TF_DIR_WITH_SLASH", "/TF_DIR_WITH_SLASH/", nil))
264+
assert.False(t, directoryPathSuppressDiff("", "/new_dir", "/TF_DIR_WITH_SLASH/", nil))
265+
}

0 commit comments

Comments
 (0)