mirror of https://github.com/databricks/cli.git
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package tfdyn
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
"github.com/databricks/databricks-sdk-go/service/apps"
|
|
)
|
|
|
|
func convertAppResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
|
|
// Normalize the output value to the target schema.
|
|
vout, diags := convert.Normalize(apps.App{}, vin)
|
|
for _, diag := range diags {
|
|
log.Debugf(ctx, "app normalization diagnostic: %s", diag.Summary)
|
|
}
|
|
|
|
return vout, nil
|
|
}
|
|
|
|
type appConverter struct{}
|
|
|
|
func (appConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error {
|
|
vout, err := convertAppResource(ctx, vin)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Modify top-level keys.
|
|
vout, err = renameKeys(vout, map[string]string{
|
|
"resources": "resource",
|
|
})
|
|
|
|
// Add the converted resource to the output.
|
|
out.App[key] = vout.AsAny()
|
|
|
|
// Configure permissions for this resource.
|
|
if permissions := convertPermissionsResource(ctx, vin); permissions != nil {
|
|
// TODO: add when permissions are supported in TF
|
|
/*
|
|
permissions.AppId = fmt.Sprintf("${databricks_app.%s.id}", key)
|
|
out.Permissions["app_"+key] = permissions
|
|
*/
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
registerConverter("apps", appConverter{})
|
|
}
|