Skip to content
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
12 changes: 6 additions & 6 deletions .codegen/lookup.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ package variable
"warehouses"
}}

{{ $customField :=
dict
"service-principals" "ApplicationId"
}}

import (
"context"
"fmt"
Expand Down Expand Up @@ -116,15 +121,10 @@ func allResolvers() *resolvers {
return "", err
}

return fmt.Sprint(entity{{ template "field-path" .List.NamedIdMap.IdPath }}), nil
return fmt.Sprint(entity.{{ getOrDefault $customField .KebabName ((index .List.NamedIdMap.IdPath 0).PascalName) }}), nil
}
{{end -}}
{{- end}}

return r
}


{{- define "field-path" -}}
{{- range .}}.{{.PascalName}}{{end}}
{{- end -}}
28 changes: 28 additions & 0 deletions bundle/config/mutator/resolve_resource_references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/databricks/databricks-sdk-go/experimental/mocks"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/databricks-sdk-go/service/iam"
)

func TestResolveClusterReference(t *testing.T) {
Expand Down Expand Up @@ -105,3 +106,30 @@ func TestNoLookupIfVariableIsSet(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "random value", *b.Config.Variables["my-cluster-id"].Value)
}

func TestResolveServicePrincipal(t *testing.T) {
spName := "Some SP name"
b := &bundle.Bundle{
Config: config.Root{
Variables: map[string]*variable.Variable{
"my-sp": {
Lookup: &variable.Lookup{
ServicePrincipal: spName,
},
},
},
},
}

m := mocks.NewMockWorkspaceClient(t)
b.SetWorkpaceClient(m.WorkspaceClient)
spApi := m.GetMockServicePrincipalsAPI()
spApi.EXPECT().GetByDisplayName(mock.Anything, spName).Return(&iam.ServicePrincipal{
Id: "1234",
ApplicationId: "app-1234",
}, nil)

err := bundle.Apply(context.Background(), b, ResolveResourceReferences())
require.NoError(t, err)
require.Equal(t, "app-1234", *b.Config.Variables["my-sp"].Value)
}
2 changes: 1 addition & 1 deletion bundle/config/variable/lookup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.