databricks-cli/bundle/deploy/terraform/tfdyn/convert_volume.go

46 lines
1.1 KiB
Go
Raw Normal View History

2024-09-09 11:10:36 +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"
)
func convertVolumeResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
// Normalize the output value to the target schema.
2024-09-09 12:40:10 +00:00
vout, diags := convert.Normalize(schema.ResourceVolume{}, vin)
2024-09-09 11:10:36 +00:00
for _, diag := range diags {
log.Debugf(ctx, "volume normalization diagnostic: %s", diag.Summary)
}
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.
2024-09-10 10:52:31 +00:00
out.Volume[key] = vout.AsAny()
2024-09-09 11:10:36 +00:00
// Configure grants for this resource.
if grants := convertGrantsResource(ctx, vin); grants != nil {
2024-09-09 12:40:10 +00:00
grants.Volume = fmt.Sprintf("${databricks_volume.%s.id}", key)
out.Grants["volume_"+key] = grants
2024-09-09 11:10:36 +00:00
}
return nil
}
func init() {
registerConverter("volumes", volumeConverter{})
}