Skip to content

Commit

Permalink
Custom suppress diff for storage in databricks_pipeline
Browse files Browse the repository at this point in the history
When the `storage` option isn't provided, DLT generates a temp one in the form of
`dbfs:/pipelines/<uuid>`.  But in the sequential apply the drift was detected, and
pipeline was recreated.  Marking it with `computed` or `suppress_diff` doesn't help
because it prevents the pipeline from the detection of change of `storage` from value
to null.
  • Loading branch information
alexott authored and nfx committed Aug 31, 2022
1 parent ad52ba0 commit 89c30b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pipelines/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"regexp"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -254,6 +255,17 @@ func (a PipelinesAPI) waitForState(id string, timeout time.Duration, desiredStat
})
}

func suppressStorageDiff(k, old, new string, d *schema.ResourceData) bool {
defaultStorageRegex := regexp.MustCompile(
`^dbfs:/pipelines/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
res := defaultStorageRegex.MatchString(old)
if new == "" && res {
log.Printf("[DEBUG] Suppressing diff for %v: platform=%#v config=%#v", k, old, new)
return true
}
return false
}

func adjustPipelineResourceSchema(m map[string]*schema.Schema) map[string]*schema.Schema {
cluster, _ := m["cluster"].Elem.(*schema.Resource)
clustersSchema := cluster.Schema
Expand Down Expand Up @@ -284,6 +296,8 @@ func adjustPipelineResourceSchema(m map[string]*schema.Schema) map[string]*schem
m["channel"].ValidateFunc = validation.StringInSlice([]string{"current", "preview"}, true)
m["edition"].ValidateFunc = validation.StringInSlice([]string{"pro", "core", "advanced"}, true)

m["storage"].DiffSuppressFunc = suppressStorageDiff

return m
}

Expand Down
8 changes: 8 additions & 0 deletions pipelines/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,11 @@ func TestListPipelinesWithFilter(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, len(data))
}

func TestStorageSuppressDiff(t *testing.T) {
k := "storage"
generated := "dbfs:/pipelines/c609bbb0-2e42-4bc8-bb4e-a1c26d6e9403"
require.True(t, suppressStorageDiff(k, generated, "", nil))
require.False(t, suppressStorageDiff(k, generated, "/tmp/abc", nil))
require.False(t, suppressStorageDiff(k, "/tmp/abc", "", nil))
}

0 comments on commit 89c30b7

Please sign in to comment.