-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathconvert_pipeline.go
More file actions
60 lines (48 loc) · 1.5 KB
/
convert_pipeline.go
File metadata and controls
60 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package tfdyn
import (
"context"
"fmt"
"github.com/databricks/cli/bundle/internal/tf/schema"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/dyn/convert"
"github.com/databricks/cli/libs/log"
)
func convertPipelineResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
// Modify top-level keys.
vout, err := renameKeys(vin, map[string]string{
"libraries": "library",
"clusters": "cluster",
"notifications": "notification",
})
if err != nil {
return dyn.InvalidValue, err
}
vout, err = dyn.DropKeys(vout, []string{"dry_run"})
if err != nil {
return dyn.InvalidValue, err
}
// Normalize the output value to the target schema.
vout, diags := convert.Normalize(schema.ResourcePipeline{}, vout)
for _, diag := range diags {
log.Debugf(ctx, "pipeline normalization diagnostic: %s", diag.Summary)
}
return vout, err
}
type pipelineConverter struct{}
func (pipelineConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error {
vout, err := convertPipelineResource(ctx, vin)
if err != nil {
return err
}
// Add the converted resource to the output.
out.Pipeline[key] = vout.AsAny()
// Configure permissions for this resource.
if permissions := convertPermissionsResource(ctx, vin); permissions != nil {
permissions.PipelineId = fmt.Sprintf("${databricks_pipeline.%s.id}", key)
out.Permissions["pipeline_"+key] = permissions
}
return nil
}
func init() {
registerConverter("pipelines", pipelineConverter{})
}