2024-09-23 10:42:34 +00:00
|
|
|
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"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
|
|
|
)
|
|
|
|
|
|
|
|
func convertClusterResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
|
|
|
|
// Normalize the output value to the target schema.
|
|
|
|
vout, diags := convert.Normalize(compute.ClusterSpec{}, vin)
|
|
|
|
for _, diag := range diags {
|
|
|
|
log.Debugf(ctx, "cluster normalization diagnostic: %s", diag.Summary)
|
|
|
|
}
|
|
|
|
|
|
|
|
return vout, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type clusterConverter struct{}
|
|
|
|
|
|
|
|
func (clusterConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error {
|
|
|
|
vout, err := convertClusterResource(ctx, vin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always set no_wait as it allows DABs not to wait for cluster to be started.
|
|
|
|
vout, err = dyn.Set(vout, "no_wait", dyn.V(true))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the converted resource to the output.
|
|
|
|
out.Cluster[key] = vout.AsAny()
|
|
|
|
|
|
|
|
// Configure permissions for this resource.
|
|
|
|
if permissions := convertPermissionsResource(ctx, vin); permissions != nil {
|
2024-10-10 14:10:16 +00:00
|
|
|
permissions.ClusterId = fmt.Sprintf("${databricks_cluster.%s.id}", key)
|
2024-09-23 10:42:34 +00:00
|
|
|
out.Permissions["cluster_"+key] = permissions
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registerConverter("clusters", clusterConverter{})
|
|
|
|
}
|