Skip to content

Commit 57d4553

Browse files
authored
Suppress diff for edition attribute in databricks_pipeline (#2219)
Added suppress diff for `edition` attribute for case when change is just case sensitivity, i.e., `CORE` -> `core`, etc.
1 parent 65564f1 commit 57d4553

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

common/resource.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,11 @@ func WorkspaceData[T any](read func(context.Context, *T, *databricks.WorkspaceCl
299299
},
300300
}
301301
}
302+
303+
func EqualFoldDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
304+
if strings.EqualFold(old, new) {
305+
log.Printf("[INFO] Suppressing diff on %s", k)
306+
return true
307+
}
308+
return false
309+
}

common/resource_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,8 @@ func TestCustomizeDiffRobustness(t *testing.T) {
178178
err = r.CustomizeDiff(ctx, nil, nil)
179179
assert.EqualError(t, err, "cannot customize diff for sample: panic: oops")
180180
}
181+
182+
func TestEqualFoldDiffSuppress(t *testing.T) {
183+
assert.True(t, EqualFoldDiffSuppress("k", "A", "a", nil))
184+
assert.False(t, EqualFoldDiffSuppress("k", "A", "A2", nil))
185+
}

pipelines/resource_pipeline.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"log"
77
"regexp"
8-
"strings"
98
"time"
109

1110
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -284,21 +283,13 @@ func suppressStorageDiff(k, old, new string, d *schema.ResourceData) bool {
284283
return false
285284
}
286285

287-
func AutoscaleModeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
288-
if strings.EqualFold(old, new) {
289-
log.Printf("[INFO] Suppressing diff on autoscale mode")
290-
return true
291-
}
292-
return false
293-
}
294-
295286
func adjustPipelineResourceSchema(m map[string]*schema.Schema) map[string]*schema.Schema {
296287
cluster, _ := m["cluster"].Elem.(*schema.Resource)
297288
clustersSchema := cluster.Schema
298289
clustersSchema["spark_conf"].DiffSuppressFunc = clusters.SparkConfDiffSuppressFunc
299290
common.MustSchemaPath(clustersSchema,
300291
"aws_attributes", "zone_id").DiffSuppressFunc = clusters.ZoneDiffSuppress
301-
common.MustSchemaPath(clustersSchema, "autoscale", "mode").DiffSuppressFunc = AutoscaleModeDiffSuppress
292+
common.MustSchemaPath(clustersSchema, "autoscale", "mode").DiffSuppressFunc = common.EqualFoldDiffSuppress
302293

303294
gcpAttributes, _ := clustersSchema["gcp_attributes"].Elem.(*schema.Resource)
304295
gcpAttributesSchema := gcpAttributes.Schema
@@ -312,6 +303,7 @@ func adjustPipelineResourceSchema(m map[string]*schema.Schema) map[string]*schem
312303
}
313304
m["channel"].ValidateFunc = validation.StringInSlice([]string{"current", "preview"}, true)
314305
m["edition"].ValidateFunc = validation.StringInSlice([]string{"pro", "core", "advanced"}, true)
306+
m["edition"].DiffSuppressFunc = common.EqualFoldDiffSuppress
315307

316308
m["storage"].DiffSuppressFunc = suppressStorageDiff
317309
m["storage"].ConflictsWith = []string{"catalog"}

repos/resource_repo.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ func validatePath(i interface{}, k string) (_ []string, errors []error) {
170170
func ResourceRepo() *schema.Resource {
171171
s := common.StructToSchema(ReposInformation{}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
172172
s["url"].ValidateFunc = validation.IsURLWithScheme([]string{"https", "http"})
173-
s["git_provider"].DiffSuppressFunc = func(k, old, new string, d *schema.ResourceData) bool {
174-
return strings.EqualFold(old, new)
175-
}
173+
s["git_provider"].DiffSuppressFunc = common.EqualFoldDiffSuppress
176174
s["branch"].ConflictsWith = []string{"tag"}
177175
s["branch"].ValidateFunc = validation.StringIsNotWhiteSpace
178176
s["path"].ValidateFunc = validatePath

0 commit comments

Comments
 (0)