From d713521d635f5e708962c6d85ee184759d097566 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 12 Dec 2022 16:36:59 +0100 Subject: [PATCH] Convert job task libraries to TF JSON (#132) --- bundle/deploy/terraform/convert.go | 7 +++++ bundle/deploy/terraform/convert_test.go | 36 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/bundle/deploy/terraform/convert.go b/bundle/deploy/terraform/convert.go index 7a6d4234..571a7da4 100644 --- a/bundle/deploy/terraform/convert.go +++ b/bundle/deploy/terraform/convert.go @@ -30,6 +30,13 @@ func BundleToTerraform(config *config.Root) *schema.Root { for _, v := range src.Tasks { var t schema.ResourceJobTask conv(v, &t) + + for _, v_ := range v.Libraries { + var l schema.ResourceJobTaskLibrary + conv(v_, &l) + t.Library = append(t.Library, l) + } + dst.Task = append(dst.Task, t) } diff --git a/bundle/deploy/terraform/convert_test.go b/bundle/deploy/terraform/convert_test.go index 6caeb9ea..f7a691ab 100644 --- a/bundle/deploy/terraform/convert_test.go +++ b/bundle/deploy/terraform/convert_test.go @@ -7,7 +7,9 @@ import ( "github.com/databricks/bricks/bundle/config/resources" "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/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestConvertJob(t *testing.T) { @@ -43,3 +45,37 @@ func TestConvertJob(t *testing.T) { assert.Equal(t, "https://github.com/foo/bar", out.Resource.Job["my_job"].GitSource.Url) assert.Nil(t, out.Data) } + +func TestConvertJobTaskLibraries(t *testing.T) { + var src = resources.Job{ + JobSettings: &jobs.JobSettings{ + Name: "my job", + Tasks: []jobs.JobTaskSettings{ + { + TaskKey: "key", + Libraries: []libraries.Library{ + { + Pypi: &libraries.PythonPyPiLibrary{ + Package: "mlflow", + }, + }, + }, + }, + }, + }, + } + + var config = config.Root{ + Resources: config.Resources{ + Jobs: map[string]resources.Job{ + "my_job": src, + }, + }, + } + + out := BundleToTerraform(&config) + assert.Equal(t, "my job", out.Resource.Job["my_job"].Name) + require.Len(t, out.Resource.Job["my_job"].Task, 1) + 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) +}