diff --git a/exporter/context.go b/exporter/context.go index 6c1b3369a0..332a23fb5a 100644 --- a/exporter/context.go +++ b/exporter/context.go @@ -764,14 +764,15 @@ func (ic *importContext) ResourceName(r *resource) string { name = r.ID } name = ic.prefix + name + origCaseName := name name = strings.ToLower(name) name = ic.regexFix(name, ic.nameFixes) // this is either numeric id or all-non-ascii if regexp.MustCompile(`^\d`).MatchString(name) || name == "" { if name == "" { - name = r.ID + origCaseName = r.ID } - name = fmt.Sprintf("r%x", md5.Sum([]byte(name)))[0:12] + name = fmt.Sprintf("r%x", md5.Sum([]byte(origCaseName)))[0:12] } return name } diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index 83c05c4d55..566a41356c 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -1348,7 +1348,12 @@ func TestResourceName(t *testing.T) { norm = ic.ResourceName(&resource{ Name: "9721431b_bcd3_4526_b90f_f5de2befec8c|8737798193", }) - assert.Equal(t, "r7322b058678", norm) + assert.Equal(t, "r56cde0f5eda", norm) + + assert.NotEqual(t, ic.ResourceName(&resource{ + Name: "0A"}), ic.ResourceName(&resource{ + Name: "0a", + })) norm = ic.ResourceName(&resource{ Name: "General Policy - All Users", diff --git a/exporter/importables.go b/exporter/importables.go index bd9c22482d..ea978aaec6 100644 --- a/exporter/importables.go +++ b/exporter/importables.go @@ -261,7 +261,8 @@ var resourcesMap map[string]importable = map[string]importable{ {Path: "egg", Resource: "databricks_dbfs_file", Match: "dbfs_path"}, }, Name: func(ic *importContext, d *schema.ResourceData) string { - return d.Id() + id := d.Id() + return "lib_" + id + fmt.Sprintf("_%x", md5.Sum([]byte(id)))[:9] }, }, "databricks_cluster": { diff --git a/exporter/importables_test.go b/exporter/importables_test.go index 9284d8ac4a..6bfc2a4b90 100644 --- a/exporter/importables_test.go +++ b/exporter/importables_test.go @@ -226,7 +226,7 @@ func TestClusterLibrary(t *testing.T) { ic := importContextForTest() d := clusters.ResourceLibrary().TestResourceData() d.SetId("a-b-c") - assert.Equal(t, "a-b-c", resourcesMap["databricks_library"].Name(ic, d)) + assert.Equal(t, "lib_a-b-c_7b193b3d", resourcesMap["databricks_library"].Name(ic, d)) } func TestImportClusterLibraries(t *testing.T) { @@ -1123,3 +1123,4 @@ func TestIncrementalListDLT(t *testing.T) { assert.Equal(t, 1, len(ic.testEmits)) }) } +