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

Correctly transform libraries in for_each_task block #1340

Merged
merged 1 commit into from
Apr 5, 2024
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
10 changes: 10 additions & 0 deletions bundle/deploy/terraform/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ func BundleToTerraform(config *config.Root) *schema.Root {
t.Library = append(t.Library, l)
}

// Convert for_each_task libraries
if v.ForEachTask != nil {
for _, v_ := range v.ForEachTask.Task.Libraries {
var l schema.ResourceJobTaskForEachTaskTaskLibrary
conv(v_, &l)
t.ForEachTask.Task.Library = append(t.ForEachTask.Task.Library, l)
}

}

dst.Task = append(dst.Task, t)
}

Expand Down
44 changes: 44 additions & 0 deletions bundle/deploy/terraform/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,50 @@ func TestBundleToTerraformJobTaskLibraries(t *testing.T) {
bundleToTerraformEquivalenceTest(t, &config)
}

func TestBundleToTerraformForEachTaskLibraries(t *testing.T) {
var src = resources.Job{
JobSettings: &jobs.JobSettings{
Name: "my job",
Tasks: []jobs.Task{
{
TaskKey: "key",
ForEachTask: &jobs.ForEachTask{
Inputs: "[1,2,3]",
Task: jobs.Task{
TaskKey: "iteration",
Libraries: []compute.Library{
{
Pypi: &compute.PythonPyPiLibrary{
Package: "mlflow",
},
},
},
},
},
},
},
},
}

var config = config.Root{
Resources: config.Resources{
Jobs: map[string]*resources.Job{
"my_job": &src,
},
},
}

out := BundleToTerraform(&config)
resource := out.Resource.Job["my_job"].(*schema.ResourceJob)

assert.Equal(t, "my job", resource.Name)
require.Len(t, resource.Task, 1)
require.Len(t, resource.Task[0].ForEachTask.Task.Library, 1)
assert.Equal(t, "mlflow", resource.Task[0].ForEachTask.Task.Library[0].Pypi.Package)

bundleToTerraformEquivalenceTest(t, &config)
}

func TestBundleToTerraformPipeline(t *testing.T) {
var src = resources.Pipeline{
PipelineSpec: &pipelines.PipelineSpec{
Expand Down
13 changes: 12 additions & 1 deletion bundle/deploy/terraform/tfdyn/convert_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ func convertJobResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {

// Modify keys in the "task" blocks
vout, err = dyn.Map(vout, "task", dyn.Foreach(func(_ dyn.Path, v dyn.Value) (dyn.Value, error) {
return renameKeys(v, map[string]string{
// Modify "library" blocks for for_each_task
vout, err = dyn.Map(v, "for_each_task.task", func(_ dyn.Path, v dyn.Value) (dyn.Value, error) {
return renameKeys(v, map[string]string{
"libraries": "library",
})
})

if err != nil {
return dyn.InvalidValue, err
}

return renameKeys(vout, map[string]string{
"libraries": "library",
})
}))
Expand Down
Loading