Skip to content

Commit

Permalink
Exporter: Make sure that name of databricks_repo is unique (#2842)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott authored Oct 26, 2023
1 parent bc05cff commit 88576b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,9 +1175,9 @@ var resourcesMap map[string]importable = map[string]importable{
Name: func(ic *importContext, d *schema.ResourceData) string {
name := d.Get("path").(string)
if name == "" {
return d.Id()
return "repo_" + d.Id()
}
return nameNormalizationRegex.ReplaceAllString(name[7:], "_")
return nameNormalizationRegex.ReplaceAllString(name[7:], "_") + "_" + d.Id()
},
Search: func(ic *importContext, r *resource) error {
reposAPI := repos.NewReposAPI(ic.Context, ic.Client)
Expand Down
18 changes: 11 additions & 7 deletions exporter/importables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ func TestClusterNameFromID(t *testing.T) {
assert.Equal(t, "c", resourcesMap["databricks_cluster"].Name(ic, d))
}

func TestRepoName(t *testing.T) {
ic := importContextForTest()
d := repos.ResourceRepo().TestResourceData()
d.SetId("12345")
// Repo without path
assert.Equal(t, "repo_12345", resourcesMap["databricks_repo"].Name(ic, d))
// Repo with path
d.Set("path", "/Repos/user/test")
assert.Equal(t, "user_test_12345", resourcesMap["databricks_repo"].Name(ic, d))
}

func TestJobName(t *testing.T) {
ic := importContextForTest()
d := jobs.ResourceJob().TestResourceData()
Expand Down Expand Up @@ -775,13 +786,6 @@ func TestGlobalInitScriptsBodyErrors(t *testing.T) {
})
}

func TestRepoIdForName(t *testing.T) {
d := repos.ResourceRepo().TestResourceData()
d.SetId("x")
ic := importContextForTest()
assert.Equal(t, "x", resourcesMap["databricks_repo"].Name(ic, d))
}

func TestRepoListFails(t *testing.T) {
qa.HTTPFixturesApply(t, []qa.HTTPFixture{
{
Expand Down

0 comments on commit 88576b5

Please sign in to comment.