2024-09-09 11:10:36 +00:00
|
|
|
package resources
|
|
|
|
|
|
|
|
import (
|
2024-11-18 16:52:17 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/databricks/databricks-sdk-go"
|
2024-09-09 11:10:36 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/marshal"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/catalog"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Volume struct {
|
2024-10-14 13:05:33 +00:00
|
|
|
// List of grants to apply on this volume.
|
2024-09-09 11:10:36 +00:00
|
|
|
Grants []Grant `json:"grants,omitempty"`
|
|
|
|
|
2024-10-14 13:05:33 +00:00
|
|
|
// Full name of the volume (catalog_name.schema_name.volume_name). This value is read from
|
2024-09-09 11:10:36 +00:00
|
|
|
// the terraform state after deployment succeeds.
|
|
|
|
ID string `json:"id,omitempty" bundle:"readonly"`
|
|
|
|
|
|
|
|
*catalog.CreateVolumeRequestContent
|
|
|
|
|
|
|
|
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
|
2024-11-18 16:52:17 +00:00
|
|
|
URL string `json:"url,omitempty" bundle:"internal"`
|
2024-09-09 11:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Volume) UnmarshalJSON(b []byte) error {
|
|
|
|
return marshal.Unmarshal(b, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Volume) MarshalJSON() ([]byte, error) {
|
|
|
|
return marshal.Marshal(v)
|
|
|
|
}
|
2024-11-18 16:52:17 +00:00
|
|
|
|
|
|
|
func (v *Volume) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
|
|
|
|
return false, fmt.Errorf("volume.Exists() is not supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Volume) TerraformResourceName() string {
|
|
|
|
return "databricks_volume"
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Test unit and manually. Maybe just manually.
|
|
|
|
func (v *Volume) InitializeURL(baseURL url.URL) {
|
|
|
|
if v.ID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
baseURL.Path = fmt.Sprintf("explore/data/volumes/%s", v.ID)
|
|
|
|
v.URL = baseURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Volume) GetURL() string {
|
|
|
|
return v.URL
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Volume) GetName() string {
|
|
|
|
return v.Name
|
|
|
|
}
|