Skip to content

Commit 88576b5

Browse files
authored
Exporter: Make sure that name of databricks_repo is unique (#2842)
1 parent bc05cff commit 88576b5

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

exporter/importables.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,9 @@ var resourcesMap map[string]importable = map[string]importable{
11751175
Name: func(ic *importContext, d *schema.ResourceData) string {
11761176
name := d.Get("path").(string)
11771177
if name == "" {
1178-
return d.Id()
1178+
return "repo_" + d.Id()
11791179
}
1180-
return nameNormalizationRegex.ReplaceAllString(name[7:], "_")
1180+
return nameNormalizationRegex.ReplaceAllString(name[7:], "_") + "_" + d.Id()
11811181
},
11821182
Search: func(ic *importContext, r *resource) error {
11831183
reposAPI := repos.NewReposAPI(ic.Context, ic.Client)

exporter/importables_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ func TestClusterNameFromID(t *testing.T) {
222222
assert.Equal(t, "c", resourcesMap["databricks_cluster"].Name(ic, d))
223223
}
224224

225+
func TestRepoName(t *testing.T) {
226+
ic := importContextForTest()
227+
d := repos.ResourceRepo().TestResourceData()
228+
d.SetId("12345")
229+
// Repo without path
230+
assert.Equal(t, "repo_12345", resourcesMap["databricks_repo"].Name(ic, d))
231+
// Repo with path
232+
d.Set("path", "/Repos/user/test")
233+
assert.Equal(t, "user_test_12345", resourcesMap["databricks_repo"].Name(ic, d))
234+
}
235+
225236
func TestJobName(t *testing.T) {
226237
ic := importContextForTest()
227238
d := jobs.ResourceJob().TestResourceData()
@@ -775,13 +786,6 @@ func TestGlobalInitScriptsBodyErrors(t *testing.T) {
775786
})
776787
}
777788

778-
func TestRepoIdForName(t *testing.T) {
779-
d := repos.ResourceRepo().TestResourceData()
780-
d.SetId("x")
781-
ic := importContextForTest()
782-
assert.Equal(t, "x", resourcesMap["databricks_repo"].Name(ic, d))
783-
}
784-
785789
func TestRepoListFails(t *testing.T) {
786790
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
787791
{

0 commit comments

Comments
 (0)