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
3 changes: 3 additions & 0 deletions bundle/config/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ import (
type Resources struct {
Jobs map[string]*resources.Job `json:"jobs,omitempty"`
Pipelines map[string]*resources.Pipeline `json:"pipelines,omitempty"`

Models map[string]*resources.MlflowModel `json:"models,omitempty"`
Experiments map[string]*resources.MlflowExperiment `json:"experiments,omitempty"`
}
7 changes: 7 additions & 0 deletions bundle/config/resources/mlflow_experiment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package resources

import "github.com/databricks/databricks-sdk-go/service/mlflow"

type MlflowExperiment struct {
*mlflow.Experiment
}
7 changes: 7 additions & 0 deletions bundle/config/resources/mlflow_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package resources

import "github.com/databricks/databricks-sdk-go/service/mlflow"

type MlflowModel struct {
*mlflow.RegisteredModel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question - any reason this uses Model and not CreateModelRequest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall...

I thought it had to do with tags, but now I see the struct for create also includes tags, so that can't be it.

}
24 changes: 24 additions & 0 deletions bundle/deploy/terraform/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ func BundleToTerraform(config *config.Root) *schema.Root {
tfroot.Resource.Pipeline[k] = &dst
}

for k, src := range config.Resources.Models {
var dst schema.ResourceMlflowModel
conv(src, &dst)
tfroot.Resource.MlflowModel[k] = &dst
}

for k, src := range config.Resources.Experiments {
var dst schema.ResourceMlflowExperiment
conv(src, &dst)
tfroot.Resource.MlflowExperiment[k] = &dst
}

return tfroot
}

Expand Down Expand Up @@ -112,6 +124,18 @@ func TerraformToBundle(state *tfjson.State, config *config.Root) error {
cur := config.Resources.Pipelines[resource.Name]
conv(tmp, &cur)
config.Resources.Pipelines[resource.Name] = cur
case "databricks_mlflow_model":
var tmp schema.ResourceMlflowModel
conv(resource.AttributeValues, &tmp)
cur := config.Resources.Models[resource.Name]
conv(tmp, &cur)
config.Resources.Models[resource.Name] = cur
case "databricks_mlflow_experiment":
var tmp schema.ResourceMlflowExperiment
conv(resource.AttributeValues, &tmp)
cur := config.Resources.Experiments[resource.Name]
conv(tmp, &cur)
config.Resources.Experiments[resource.Name] = cur
default:
return fmt.Errorf("missing mapping for %s", resource.Type)
}
Expand Down
58 changes: 58 additions & 0 deletions bundle/deploy/terraform/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/databricks/databricks-sdk-go/service/clusters"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/libraries"
"github.com/databricks/databricks-sdk-go/service/mlflow"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -79,3 +80,60 @@ func TestConvertJobTaskLibraries(t *testing.T) {
require.Len(t, out.Resource.Job["my_job"].Task[0].Library, 1)
assert.Equal(t, "mlflow", out.Resource.Job["my_job"].Task[0].Library[0].Pypi.Package)
}

func TestConvertModel(t *testing.T) {
var src = resources.MlflowModel{
RegisteredModel: &mlflow.RegisteredModel{
Name: "name",
Description: "description",
Tags: []mlflow.RegisteredModelTag{
{
Key: "k1",
Value: "v1",
},
{
Key: "k2",
Value: "v2",
},
},
},
}

var config = config.Root{
Resources: config.Resources{
Models: map[string]*resources.MlflowModel{
"my_model": &src,
},
},
}

out := BundleToTerraform(&config)
assert.Equal(t, "name", out.Resource.MlflowModel["my_model"].Name)
assert.Equal(t, "description", out.Resource.MlflowModel["my_model"].Description)
assert.Len(t, out.Resource.MlflowModel["my_model"].Tags, 2)
assert.Equal(t, "k1", out.Resource.MlflowModel["my_model"].Tags[0].Key)
assert.Equal(t, "v1", out.Resource.MlflowModel["my_model"].Tags[0].Value)
assert.Equal(t, "k2", out.Resource.MlflowModel["my_model"].Tags[1].Key)
assert.Equal(t, "v2", out.Resource.MlflowModel["my_model"].Tags[1].Value)
assert.Nil(t, out.Data)
}

func TestConvertExperiment(t *testing.T) {
var src = resources.MlflowExperiment{
Experiment: &mlflow.Experiment{
Name: "name",
},
}

var config = config.Root{
Resources: config.Resources{
Experiments: map[string]*resources.MlflowExperiment{
"my_experiment": &src,
},
},
}

out := BundleToTerraform(&config)
assert.Equal(t, "name", out.Resource.MlflowExperiment["my_experiment"].Name)
assert.Nil(t, out.Data)
}
6 changes: 6 additions & 0 deletions bundle/deploy/terraform/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func interpolateTerraformResourceIdentifiers(path string, lookup map[string]stri
case "jobs":
path = strings.Join(append([]string{"databricks_job"}, parts[2:]...), interpolation.Delimiter)
return fmt.Sprintf("${%s}", path), nil
case "models":
path = strings.Join(append([]string{"databricks_mlflow_model"}, parts[2:]...), interpolation.Delimiter)
return fmt.Sprintf("${%s}", path), nil
case "experiments":
path = strings.Join(append([]string{"databricks_mlflow_experiment"}, parts[2:]...), interpolation.Delimiter)
return fmt.Sprintf("${%s}", path), nil
default:
panic("TODO: " + parts[1])
}
Expand Down