mirror of https://github.com/databricks/cli.git
This commit is contained in:
parent
4ce2b75928
commit
a448c7f238
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle/config"
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/bundle/config/resources"
|
"github.com/databricks/cli/bundle/config/resources"
|
||||||
|
@ -82,6 +83,10 @@ func BundleToTerraform(config *config.Root) *schema.Root {
|
||||||
conv(src, &dst)
|
conv(src, &dst)
|
||||||
|
|
||||||
if src.JobSettings != nil {
|
if src.JobSettings != nil {
|
||||||
|
sort.Slice(src.JobSettings.Tasks, func(i, j int) bool {
|
||||||
|
return src.JobSettings.Tasks[i].TaskKey < src.JobSettings.Tasks[j].TaskKey
|
||||||
|
})
|
||||||
|
|
||||||
for _, v := range src.Tasks {
|
for _, v := range src.Tasks {
|
||||||
var t schema.ResourceJobTask
|
var t schema.ResourceJobTask
|
||||||
conv(v, &t)
|
conv(v, &t)
|
||||||
|
|
|
@ -25,15 +25,28 @@ func convertJobResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
|
||||||
// recreates. For more details see the NOTE at
|
// recreates. For more details see the NOTE at
|
||||||
// https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/job#example-usage
|
// https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/job#example-usage
|
||||||
// and https://github.com/databricks/terraform-provider-databricks/issues/4011
|
// and https://github.com/databricks/terraform-provider-databricks/issues/4011
|
||||||
tasks := vin.Get("tasks").MustSequence()
|
// TODO: Is this safe for nil values of task key? Empty strings?
|
||||||
sort.Slice(tasks, func(i, j int) bool {
|
vout := vin
|
||||||
return tasks[i].Get("task_key").MustString() < tasks[j].Get("task_key").MustString()
|
var err error
|
||||||
})
|
tasks, ok := vin.Get("tasks").AsSequence()
|
||||||
vout, err := dyn.Map(vin, "tasks", func(_ dyn.Path, _ dyn.Value) (dyn.Value, error) {
|
if ok {
|
||||||
return dyn.V(tasks), nil
|
sort.Slice(tasks, func(i, j int) bool {
|
||||||
})
|
tk1, ok := tasks[i].Get("task_key").AsString()
|
||||||
if err != nil {
|
if !ok {
|
||||||
return dyn.InvalidValue, err
|
return true
|
||||||
|
}
|
||||||
|
tk2, ok := tasks[j].Get("task_key").AsString()
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return tk1 < tk2
|
||||||
|
})
|
||||||
|
vout, err = dyn.Map(vin, "tasks", func(_ dyn.Path, _ dyn.Value) (dyn.Value, error) {
|
||||||
|
return dyn.V(tasks), nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return dyn.InvalidValue, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify top-level keys.
|
// Modify top-level keys.
|
||||||
|
|
|
@ -63,6 +63,9 @@ func TestConvertJob(t *testing.T) {
|
||||||
TaskKey: "task_key_c",
|
TaskKey: "task_key_c",
|
||||||
JobClusterKey: "job_cluster_key_c",
|
JobClusterKey: "job_cluster_key_c",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Description: "missing task key 😱",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Permissions: []resources.Permission{
|
Permissions: []resources.Permission{
|
||||||
|
@ -107,6 +110,9 @@ func TestConvertJob(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"task": []any{
|
"task": []any{
|
||||||
|
map[string]any{
|
||||||
|
"description": "missing task key 😱",
|
||||||
|
},
|
||||||
map[string]any{
|
map[string]any{
|
||||||
"task_key": "task_key_a",
|
"task_key": "task_key_a",
|
||||||
"job_cluster_key": "job_cluster_key_a",
|
"job_cluster_key": "job_cluster_key_a",
|
||||||
|
|
Loading…
Reference in New Issue