Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions bundle/direct/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ func (d *DeploymentUnit) Create(ctx context.Context, db *dstate.DeploymentState,
}

func (d *DeploymentUnit) Recreate(ctx context.Context, db *dstate.DeploymentState, oldID string, newState any) error {
oldState, err := d.loadPersistedState(db)
if err != nil {
return err
}

// Note, unlike Delete(), we hard error on 403 here intentionally.
// MANAGED_BY_PARENT is still disregarded — the subsequent Create with
// replace_existing=true will reconfigure the parent-managed resource in
// place, matching the Terraform provider's recreate behaviour.
err := d.Adapter.DoDelete(ctx, oldID)
err = d.Adapter.DoDelete(ctx, oldID, oldState)
if err != nil && !isResourceGone(err) && !isManagedByParent(err) {
return fmt.Errorf("deleting old id=%s: %w", oldID, err)
}
Expand Down Expand Up @@ -170,7 +175,12 @@ func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *dstate.Deployment
}

func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, oldID string) error {
err := d.Adapter.DoDelete(ctx, oldID)
oldState, err := d.loadPersistedState(db)
if err != nil {
return err
}

err = d.Adapter.DoDelete(ctx, oldID, oldState)
if err != nil && !isResourceGone(err) && !isManagedByParent(err) {
// Rather than failing delete and requiring user to unbind, we perform unbind automatically there.
// Some services, e.g. jobs, return 403 for missing resources if caller did not have permissions to it when job existed.
Expand Down Expand Up @@ -215,6 +225,23 @@ func parseState(destType reflect.Type, raw json.RawMessage) (any, error) {
return reflect.ValueOf(destPtr).Elem().Interface(), nil
}

// loadPersistedState reads and parses the resource's last-persisted state for
// the DoDelete call. Returns a zero-value state pointer when nothing has been
// persisted yet (e.g. delete after a partial-create failure), so the call site
// always passes a typed value.
func (d *DeploymentUnit) loadPersistedState(db *dstate.DeploymentState) (any, error) {
stateType := d.Adapter.StateType()
dbentry, ok := db.GetResourceEntry(d.ResourceKey)
if !ok || len(dbentry.State) == 0 {
return reflect.New(stateType.Elem()).Interface(), nil
}
state, err := parseState(stateType, dbentry.State)
if err != nil {
return nil, fmt.Errorf("parsing persisted state: %w", err)
}
return state, nil
}

func (d *DeploymentUnit) refreshRemoteState(ctx context.Context, id string) error {
if d.RemoteState != nil {
return nil
Expand Down
18 changes: 9 additions & 9 deletions bundle/direct/dresources/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ type IResource interface {
// Example: func (r *ResourceJob) DoRead(ctx context.Context, id string) (*jobs.Job, error)
DoRead(ctx context.Context, id string) (remoteState any, e error)

// DoDelete deletes the resource.
// Example: func (r *ResourceJob) DoDelete(ctx context.Context, id string) error
DoDelete(ctx context.Context, id string) error
// DoDelete deletes the resource. The state argument is the last-persisted
// state for the resource; resources that don't need it should accept it as
// _ to satisfy the interface.
// Example: func (r *ResourceJob) DoDelete(ctx context.Context, id string, _ *jobs.JobSettings) error
DoDelete(ctx context.Context, id string, state any) error

// [Optional] OverrideChangeDesc can implement custom logic to update a given ChangeDesc; it is run last after built-in classifiers and field triggers.
OverrideChangeDesc(ctx context.Context, path *structpath.PathNode, changedesc *ChangeDesc, remoteState any) error
Expand Down Expand Up @@ -264,6 +266,7 @@ func (a *Adapter) validate() error {
validations := []any{
"PrepareState return", a.prepareState.OutTypes[0], stateType,
"DoCreate newState", a.doCreate.InTypes[1], stateType,
"DoDelete state", a.doDelete.InTypes[2], stateType,
}

// If RemapState is implemented, validate its signature.
Expand Down Expand Up @@ -399,12 +402,9 @@ func (a *Adapter) DoRead(ctx context.Context, id string) (any, error) {
return outs[0], nil
}

func (a *Adapter) DoDelete(ctx context.Context, id string) error {
_, err := a.doDelete.Call(ctx, id)
if err != nil {
return err
}
return nil
func (a *Adapter) DoDelete(ctx context.Context, id string, state any) error {
_, err := a.doDelete.Call(ctx, id, state)
return err
}

// normalizeNilPointer converts a nil pointer wrapped in an interface to a nil interface.
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *ResourceAlert) DoUpdate(ctx context.Context, id string, config *sql.Ale
}

// DoDelete deletes the alert by id.
func (r *ResourceAlert) DoDelete(ctx context.Context, id string) error {
func (r *ResourceAlert) DoDelete(ctx context.Context, id string, _ *sql.AlertV2) error {
return r.client.AlertsV2.TrashAlert(ctx, sql.TrashAlertV2Request{
Id: id,
Purge: true,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ func testCRUD(t *testing.T, group string, adapter *Adapter, client *databricks.W
assert.Equal(t, val, remoteValue, "path=%q\nnewState=%s\nremappedState=%s", path.String(), jsonDump(newState), jsonDump(remappedState))
}))

err = adapter.DoDelete(ctx, createdID)
err = adapter.DoDelete(ctx, createdID, newState)
require.NoError(t, err)

p, err := structpath.ParsePath("name")
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func deploymentToAppConfig(d *apps.AppDeployment) *resources.AppConfig {
return config
}

func (r *ResourceApp) DoDelete(ctx context.Context, id string) error {
func (r *ResourceApp) DoDelete(ctx context.Context, id string, _ *AppState) error {
_, err := r.client.Apps.DeleteByName(ctx, id)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *ResourceCatalog) DoUpdateWithID(ctx context.Context, id string, config
return newID, response, nil
}

func (r *ResourceCatalog) DoDelete(ctx context.Context, id string) error {
func (r *ResourceCatalog) DoDelete(ctx context.Context, id string, _ *catalog.CreateCatalog) error {
return r.client.Catalogs.Delete(ctx, catalog.DeleteCatalogRequest{
Name: id,
Force: true,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (r *ResourceCluster) DoResize(ctx context.Context, id string, config *compu
return err
}

func (r *ResourceCluster) DoDelete(ctx context.Context, id string) error {
func (r *ResourceCluster) DoDelete(ctx context.Context, id string, _ *compute.ClusterSpec) error {
return r.client.Clusters.PermanentDeleteByClusterId(ctx, id)
}

Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (r *ResourceDashboard) DoUpdate(ctx context.Context, id string, config *Das
return responseToState(updateResp, publishResp, dashboard.SerializedDashboard, config.Published), nil
}

func (r *ResourceDashboard) DoDelete(ctx context.Context, id string) error {
func (r *ResourceDashboard) DoDelete(ctx context.Context, id string, _ *DashboardState) error {
return r.client.Lakeview.Trash(ctx, dashboards.TrashDashboardRequest{
DashboardId: id,
})
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/database_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *ResourceDatabaseCatalog) DoUpdate(ctx context.Context, id string, confi
return nil, err
}

func (r *ResourceDatabaseCatalog) DoDelete(ctx context.Context, id string) error {
func (r *ResourceDatabaseCatalog) DoDelete(ctx context.Context, id string, _ *database.DatabaseCatalog) error {
return r.client.Database.DeleteDatabaseCatalog(ctx, database.DeleteDatabaseCatalogRequest{
Name: id,
})
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (d *ResourceDatabaseInstance) WaitAfterCreate(ctx context.Context, id strin
return nil, err
}

func (d *ResourceDatabaseInstance) DoDelete(ctx context.Context, name string) error {
func (d *ResourceDatabaseInstance) DoDelete(ctx context.Context, name string, _ *database.DatabaseInstance) error {
return d.client.Database.DeleteDatabaseInstance(ctx, database.DeleteDatabaseInstanceRequest{
Name: name,
Purge: true,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *ResourceExperiment) DoUpdate(ctx context.Context, id string, config *ml
return nil, r.client.Experiments.UpdateExperiment(ctx, updateReq)
}

func (r *ResourceExperiment) DoDelete(ctx context.Context, id string) error {
func (r *ResourceExperiment) DoDelete(ctx context.Context, id string, _ *ml.CreateExperiment) error {
return r.client.Experiments.DeleteExperiment(ctx, ml.DeleteExperiment{
ExperimentId: id,
})
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/external_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (r *ResourceExternalLocation) DoUpdateWithID(ctx context.Context, id string
return newID, response, nil
}

func (r *ResourceExternalLocation) DoDelete(ctx context.Context, id string) error {
func (r *ResourceExternalLocation) DoDelete(ctx context.Context, id string, _ *catalog.CreateExternalLocation) error {
return r.client.ExternalLocations.Delete(ctx, catalog.DeleteExternalLocationRequest{
Name: id,
Force: true,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (r *ResourceGrants) DoUpdate(ctx context.Context, _ string, state *GrantsSt
return nil, err
}

func (r *ResourceGrants) DoDelete(ctx context.Context, id string) error {
func (r *ResourceGrants) DoDelete(ctx context.Context, id string, _ *GrantsState) error {
// Similar to permissions, we do nothing there.
// We could delete all grants there, but it would be confusing to explain wrt permissions.
return nil
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *ResourceJob) DoUpdate(ctx context.Context, id string, config *jobs.JobS
return nil, r.client.Jobs.Reset(ctx, request)
}

func (r *ResourceJob) DoDelete(ctx context.Context, id string) error {
func (r *ResourceJob) DoDelete(ctx context.Context, id string, _ *jobs.JobSettings) error {
idInt, err := parseJobID(id)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (r *ResourceMlflowModel) DoUpdate(ctx context.Context, id string, config *m
}, nil
}

func (r *ResourceMlflowModel) DoDelete(ctx context.Context, id string) error {
func (r *ResourceMlflowModel) DoDelete(ctx context.Context, id string, _ *ml.CreateModelRequest) error {
return r.client.ModelRegistry.DeleteModel(ctx, ml.DeleteModelRequest{
Name: id,
})
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/model_serving_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,6 @@ func (r *ResourceModelServingEndpoint) DoUpdate(ctx context.Context, id string,
return nil, nil
}

func (r *ResourceModelServingEndpoint) DoDelete(ctx context.Context, id string) error {
func (r *ResourceModelServingEndpoint) DoDelete(ctx context.Context, id string, _ *serving.CreateServingEndpoint) error {
return r.client.ServingEndpoints.DeleteByName(ctx, id)
}
2 changes: 1 addition & 1 deletion bundle/direct/dresources/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (r *ResourcePermissions) DoUpdate(ctx context.Context, _ string, newState *
// it themselves. Trying to fix permissions back requires
// - making assumptions on what it should look like
// - storing current user somewhere or storing original permissions somewhere
func (r *ResourcePermissions) DoDelete(ctx context.Context, id string) error {
func (r *ResourcePermissions) DoDelete(ctx context.Context, id string, _ *PermissionsState) error {
// intentional noop
return nil
}
2 changes: 1 addition & 1 deletion bundle/direct/dresources/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (r *ResourcePipeline) DoUpdate(ctx context.Context, id string, config *pipe
return nil, r.client.Pipelines.Update(ctx, request)
}

func (r *ResourcePipeline) DoDelete(ctx context.Context, id string) error {
func (r *ResourcePipeline) DoDelete(ctx context.Context, id string, _ *pipelines.CreatePipeline) error {
return r.client.Pipelines.DeleteByPipelineId(ctx, id)
}

Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/postgres_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *ResourcePostgresBranch) DoUpdate(ctx context.Context, id string, config
return makePostgresBranchRemote(result), nil
}

func (r *ResourcePostgresBranch) DoDelete(ctx context.Context, id string) error {
func (r *ResourcePostgresBranch) DoDelete(ctx context.Context, id string, _ *PostgresBranchState) error {
waiter, err := r.client.Postgres.DeleteBranch(ctx, postgres.DeleteBranchRequest{
Name: id,
})
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/postgres_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (r *ResourcePostgresEndpoint) DoUpdate(ctx context.Context, id string, conf
return r.waitForReconciliation(ctx, id)
}

func (r *ResourcePostgresEndpoint) DoDelete(ctx context.Context, id string) error {
func (r *ResourcePostgresEndpoint) DoDelete(ctx context.Context, id string, _ *PostgresEndpointState) error {
// Retry loop to handle "Endpoint reconciliation still in progress" errors
deadline := time.Now().Add(endpointReconciliationTimeout)
for {
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/postgres_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (r *ResourcePostgresProject) DoUpdate(ctx context.Context, id string, confi
return makePostgresProjectRemote(result), nil
}

func (r *ResourcePostgresProject) DoDelete(ctx context.Context, id string) error {
func (r *ResourcePostgresProject) DoDelete(ctx context.Context, id string, _ *PostgresProjectState) error {
waiter, err := r.client.Postgres.DeleteProject(ctx, postgres.DeleteProjectRequest{
Name: id,
Purge: false,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/quality_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *ResourceQualityMonitor) DoUpdate(ctx context.Context, id string, config
return response, nil
}

func (r *ResourceQualityMonitor) DoDelete(ctx context.Context, id string) error {
func (r *ResourceQualityMonitor) DoDelete(ctx context.Context, id string, _ *QualityMonitorState) error {
//nolint:staticcheck // Direct quality_monitor resource still uses legacy monitor endpoints; v1 data-quality migration is separate work.
_, err := r.client.QualityMonitors.Delete(ctx, catalog.DeleteQualityMonitorRequest{
TableName: id,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/registered_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *ResourceRegisteredModel) DoUpdate(ctx context.Context, id string, confi
return response, nil
}

func (r *ResourceRegisteredModel) DoDelete(ctx context.Context, id string) error {
func (r *ResourceRegisteredModel) DoDelete(ctx context.Context, id string, _ *catalog.CreateRegisteredModelRequest) error {
return r.client.RegisteredModels.Delete(ctx, catalog.DeleteRegisteredModelRequest{
FullName: id,
})
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r *ResourceSchema) DoUpdate(ctx context.Context, id string, config *catalo
return response, nil
}

func (r *ResourceSchema) DoDelete(ctx context.Context, id string) error {
func (r *ResourceSchema) DoDelete(ctx context.Context, id string, _ *catalog.CreateSchema) error {
return r.client.Schemas.Delete(ctx, catalog.DeleteSchemaRequest{
FullName: id,
Force: true,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/secret_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func (r *ResourceSecretScope) DoCreate(ctx context.Context, state *SecretScopeCo
// DoUpdate is not intentionally implemented here because scopes do not support a update API. All fields are marked to
// return a recreate trigger.

func (r *ResourceSecretScope) DoDelete(ctx context.Context, id string) error {
func (r *ResourceSecretScope) DoDelete(ctx context.Context, id string, _ *SecretScopeConfig) error {
return r.client.Secrets.DeleteScopeByScope(ctx, id)
}
2 changes: 1 addition & 1 deletion bundle/direct/dresources/secret_scope_acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *ResourceSecretScopeAcls) DoUpdate(ctx context.Context, id string, state
}

// Removing ACLs is a no-op, to match the behavior for permissions and grants.
func (r *ResourceSecretScopeAcls) DoDelete(ctx context.Context, id string) error {
func (r *ResourceSecretScopeAcls) DoDelete(ctx context.Context, id string, _ *SecretScopeAclsState) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/sql_warehouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ func (r *ResourceSqlWarehouse) DoUpdate(ctx context.Context, id string, config *
return nil, nil
}

func (r *ResourceSqlWarehouse) DoDelete(ctx context.Context, oldID string) error {
func (r *ResourceSqlWarehouse) DoDelete(ctx context.Context, oldID string, _ *sql.CreateWarehouseRequest) error {
return r.client.Warehouses.DeleteById(ctx, oldID)
}
2 changes: 1 addition & 1 deletion bundle/direct/dresources/synced_database_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *ResourceSyncedDatabaseTable) DoUpdate(ctx context.Context, id string, c
return nil, err
}

func (r *ResourceSyncedDatabaseTable) DoDelete(ctx context.Context, id string) error {
func (r *ResourceSyncedDatabaseTable) DoDelete(ctx context.Context, id string, _ *database.SyncedDatabaseTable) error {
return r.client.Database.DeleteSyncedDatabaseTable(ctx, database.DeleteSyncedDatabaseTableRequest{
Name: id,
PurgeData: false,
Expand Down
2 changes: 1 addition & 1 deletion bundle/direct/dresources/vector_search_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ func (r *ResourceVectorSearchEndpoint) DoUpdate(ctx context.Context, id string,
return nil, nil
}

func (r *ResourceVectorSearchEndpoint) DoDelete(ctx context.Context, id string) error {
func (r *ResourceVectorSearchEndpoint) DoDelete(ctx context.Context, id string, _ *vectorsearch.CreateEndpoint) error {
return r.client.VectorSearchEndpoints.DeleteEndpointByEndpointName(ctx, id)
}
2 changes: 1 addition & 1 deletion bundle/direct/dresources/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *ResourceVolume) DoUpdateWithID(ctx context.Context, id string, config *
return response.FullName, response, nil
}

func (r *ResourceVolume) DoDelete(ctx context.Context, id string) error {
func (r *ResourceVolume) DoDelete(ctx context.Context, id string, _ *catalog.CreateVolumeRequestContent) error {
return r.client.Volumes.DeleteByName(ctx, id)
}

Expand Down
Loading