diff --git a/exporter/importables.go b/exporter/importables.go index aeb2650375..49f8e7537f 100644 --- a/exporter/importables.go +++ b/exporter/importables.go @@ -316,6 +316,7 @@ var resourcesMap map[string]importable = map[string]importable{ {Path: "library.egg", Resource: "databricks_workspace_file", Match: "workspace_path"}, {Path: "policy_id", Resource: "databricks_cluster_policy"}, {Path: "single_user_name", Resource: "databricks_service_principal", Match: "application_id"}, + {Path: "single_user_name", Resource: "databricks_group", Match: "display_name"}, {Path: "single_user_name", Resource: "databricks_user", Match: "user_name", MatchType: MatchCaseInsensitive}, {Path: "library.jar", Resource: "databricks_repo", Match: "workspace_path", MatchType: MatchPrefix, SearchValueTransformFunc: appendEndingSlashToDirName}, @@ -937,11 +938,14 @@ var resourcesMap map[string]importable = map[string]importable{ return nil }, Search: func(ic *importContext, r *resource) error { + if r.Attribute != "display_name" { + return fmt.Errorf("wrong search attribute '%s' for databricks_group", r.Attribute) + } if err := ic.cacheGroups(); err != nil { return err } for _, g := range ic.allGroups { - if g.DisplayName == r.Value && r.Attribute == "display_name" { + if g.DisplayName == r.Value { r.ID = g.ID return nil } diff --git a/exporter/importables_test.go b/exporter/importables_test.go index 6306f859b1..fe99d93f61 100644 --- a/exporter/importables_test.go +++ b/exporter/importables_test.go @@ -512,7 +512,7 @@ func TestClusterPolicyNoValues(t *testing.T) { assert.Equal(t, 1, len(ic.testEmits)) } -func TestGroupCacheError(t *testing.T) { +func TestGroupCacheAndSearchError(t *testing.T) { qa.HTTPFixturesApply(t, []qa.HTTPFixture{ { ReuseRequest: true, @@ -527,9 +527,14 @@ func TestGroupCacheError(t *testing.T) { assert.EqualError(t, err, "nope") err = resourcesMap["databricks_group"].Search(ic, &resource{ - ID: "nonsense", + Attribute: "display_name", }) assert.EqualError(t, err, "nope") + + err = resourcesMap["databricks_group"].Search(ic, &resource{ + Attribute: "nonsense", + }) + assert.EqualError(t, err, "wrong search attribute 'nonsense' for databricks_group") d := scim.ResourceGroup().ToResource().TestResourceData() d.Set("display_name", "nonsense") err = resourcesMap["databricks_group"].Import(ic, &resource{ diff --git a/exporter/util_compute.go b/exporter/util_compute.go index 4a42a0cf21..2c3f3222ea 100644 --- a/exporter/util_compute.go +++ b/exporter/util_compute.go @@ -65,6 +65,13 @@ func (ic *importContext) importCluster(c *compute.ClusterSpec) { ic.emitSecretsFromSecretsPathMap(c.SparkConf) ic.emitSecretsFromSecretsPathMap(c.SparkEnvVars) ic.emitUserOrServicePrincipal(c.SingleUserName) + if c.Kind.String() != "" && c.SingleUserName != "" { + ic.Emit(&resource{ + Resource: "databricks_group", + Attribute: "display_name", + Value: c.SingleUserName, + }) + } } func (ic *importContext) emitSecretsFromSecretPathString(v string) {