Skip to content

Commit 1908a92

Browse files
authored
[Exporter] Ignore databricks_artifact_allowlist with zero artifact_matcher blocks (#4019)
## Changes <!-- Summary of your changes that are easy to understand --> Don't generate `databricks_artifact_allowlist` when no `artifact_matcher` blocks are defined ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [ ] using Go SDK
1 parent d22064e commit 1908a92

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

exporter/importables.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,14 @@ var resourcesMap map[string]importable = map[string]importable{
25182518
}
25192519
return nil
25202520
},
2521+
Ignore: func(ic *importContext, r *resource) bool {
2522+
numBlocks := r.Data.Get("artifact_matcher.#").(int)
2523+
if numBlocks == 0 {
2524+
log.Printf("[WARN] Ignoring artifcat allowlist with ID %s", r.ID)
2525+
ic.addIgnoredResource(fmt.Sprintf("databricks_artifact_allowlist. id=%s", r.ID))
2526+
}
2527+
return numBlocks == 0
2528+
},
25212529
Depends: []reference{
25222530
{Path: "artifact_matcher.artifact", Resource: "databricks_volume", Match: "volume_path",
25232531
IsValidApproximation: isMatchingAllowListArtifact},

exporter/importables_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,34 @@ func TestListUcAllowListSuccess(t *testing.T) {
14741474
err := resourcesMap["databricks_artifact_allowlist"].List(ic)
14751475
assert.NoError(t, err)
14761476
assert.Equal(t, len(ic.testEmits), 3)
1477+
// Test ignore function
1478+
d := tfcatalog.ResourceArtifactAllowlist().ToResource().TestResourceData()
1479+
d.MarkNewResource()
1480+
d.Set("id", "abc")
1481+
res := ic.Importables["databricks_artifact_allowlist"].Ignore(ic, &resource{
1482+
ID: "abc",
1483+
Data: d,
1484+
})
1485+
assert.True(t, res)
1486+
assert.Contains(t, ic.ignoredResources, "databricks_artifact_allowlist. id=abc")
1487+
// Test ignore function, with blocks
1488+
err = common.StructToData(
1489+
tfcatalog.ArtifactAllowlistInfo{
1490+
ArtifactType: "INIT_SCRIPT",
1491+
ArtifactMatchers: []catalog.ArtifactMatcher{
1492+
{
1493+
Artifact: "/Volumes/inits",
1494+
MatchType: "PREFIX_MATCH",
1495+
},
1496+
},
1497+
},
1498+
tfcatalog.ResourceArtifactAllowlist().Schema, d)
1499+
assert.NoError(t, err)
1500+
res = ic.Importables["databricks_artifact_allowlist"].Ignore(ic, &resource{
1501+
ID: "abc",
1502+
Data: d,
1503+
})
1504+
assert.False(t, res)
14771505
}
14781506

14791507
func TestEmitSqlParent(t *testing.T) {

0 commit comments

Comments
 (0)