Skip to content

Commit

Permalink
[Exporter] Support for group assigned clusters
Browse files Browse the repository at this point in the history
Also optimized group search a bit
  • Loading branch information
alexott committed Dec 29, 2024
1 parent 1e5443d commit 93fbd48
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions exporter/importables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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{
Expand Down
7 changes: 7 additions & 0 deletions exporter/util_compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 93fbd48

Please sign in to comment.