mirror of https://github.com/databricks/cli.git
first comment
This commit is contained in:
parent
02e83877f4
commit
f772ce4259
|
@ -19,6 +19,7 @@ type Resources struct {
|
||||||
RegisteredModels map[string]*resources.RegisteredModel `json:"registered_models,omitempty"`
|
RegisteredModels map[string]*resources.RegisteredModel `json:"registered_models,omitempty"`
|
||||||
QualityMonitors map[string]*resources.QualityMonitor `json:"quality_monitors,omitempty"`
|
QualityMonitors map[string]*resources.QualityMonitor `json:"quality_monitors,omitempty"`
|
||||||
Schemas map[string]*resources.Schema `json:"schemas,omitempty"`
|
Schemas map[string]*resources.Schema `json:"schemas,omitempty"`
|
||||||
|
Volumes map[string]*resources.Volume `json:"volumes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigResource interface {
|
type ConfigResource interface {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package resources
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/databricks/databricks-sdk-go/marshal"
|
||||||
|
"github.com/databricks/databricks-sdk-go/service/catalog"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Volume struct {
|
||||||
|
// List of grants to apply on this schema.
|
||||||
|
Grants []Grant `json:"grants,omitempty"`
|
||||||
|
|
||||||
|
// Full name of the schema (catalog_name.schema_name.volume_name). This value is read from
|
||||||
|
// the terraform state after deployment succeeds.
|
||||||
|
ID string `json:"id,omitempty" bundle:"readonly"`
|
||||||
|
|
||||||
|
*catalog.CreateVolumeRequestContent
|
||||||
|
|
||||||
|
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Volume) UnmarshalJSON(b []byte) error {
|
||||||
|
return marshal.Unmarshal(b, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Volume) MarshalJSON() ([]byte, error) {
|
||||||
|
return marshal.Marshal(v)
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
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 convertVolumeResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
|
||||||
|
// Normalize the output value to the target schema.
|
||||||
|
v, diags := convert.Normalize(schema.ResourceVolume{}, vin)
|
||||||
|
for _, diag := range diags {
|
||||||
|
log.Debugf(ctx, "volume normalization diagnostic: %s", diag.Summary)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: What happens if I try to delete a UC volume that has data in it?
|
||||||
|
// Do I need force destroy functionality here.
|
||||||
|
|
||||||
|
// We always set force destroy as it allows DABs to manage the lifecycle
|
||||||
|
// of the schema. It's the responsibility of the CLI to ensure the user
|
||||||
|
// is adequately warned when they try to delete a UC Volume.
|
||||||
|
vout, err := dyn.SetByPath(v, dyn.MustPathFromString("force_destroy"), dyn.V(true))
|
||||||
|
if err != nil {
|
||||||
|
return dyn.InvalidValue, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return vout, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type volumeConverter struct{}
|
||||||
|
|
||||||
|
func (volumeConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error {
|
||||||
|
vout, err := convertVolumeResource(ctx, vin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the converted resource to the output.
|
||||||
|
out.Schema[key] = vout.AsAny()
|
||||||
|
|
||||||
|
// Configure grants for this resource.
|
||||||
|
if grants := convertGrantsResource(ctx, vin); grants != nil {
|
||||||
|
grants.Schema = fmt.Sprintf("${databricks_schema.%s.id}", key)
|
||||||
|
out.Grants["schema_"+key] = grants
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerConverter("volumes", volumeConverter{})
|
||||||
|
}
|
Loading…
Reference in New Issue