Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exporter] Support for group assigned clusters #4361

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading