@@ -2,6 +2,7 @@ package direct
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "os"
78 "strings"
@@ -63,13 +64,16 @@ type BindResult struct {
6364func (b * DeploymentBundle ) Bind (ctx context.Context , client * databricks.WorkspaceClient , configRoot * config.Root , statePath , resourceKey , resourceID string ) (* BindResult , error ) {
6465 // Check if the resource is already managed (bound to a different ID)
6566 var checkStateDB dstate.DeploymentState
66- if err := checkStateDB .Open (ctx , statePath , dstate .ReadingFile , dstate . WithRecovery (true ), dstate. OpenDmsArgs {} ); err != nil {
67+ if err := checkStateDB .Open (ctx , statePath , dstate .WithRecovery (true )); err != nil {
6768 // State that cannot be read is not the same as state without a binding:
6869 // the resource may well be managed already, and binding on top of it
6970 // would take over a resource whose ownership was never checked. A state
7071 // file that does not exist yet opens successfully as an empty one.
7172 return nil , fmt .Errorf ("cannot check whether %s is already bound: %w" , resourceKey , err )
7273 }
74+ if checkStateDB .IsDeploymentMetadataService () {
75+ return nil , errors .New ("bind is not supported for a bundle target that records deployment history" )
76+ }
7377 existingID := checkStateDB .GetResourceID (resourceKey )
7478 if _ , err := checkStateDB .Finalize (ctx ); err != nil {
7579 log .Warnf (ctx , "failed to finalize state: %v" , err )
@@ -92,7 +96,7 @@ func (b *DeploymentBundle) Bind(ctx context.Context, client *databricks.Workspac
9296 }
9397
9498 // Open temp state
95- err := b .StateDB .Open (ctx , tmpStatePath , dstate .ReadingFile , dstate . WithRecovery (false ), dstate. OpenDmsArgs {} )
99+ err := b .StateDB .Open (ctx , tmpStatePath , dstate .WithRecovery (false ))
96100 if err != nil {
97101 os .Remove (tmpStatePath )
98102 return nil , err
@@ -119,7 +123,7 @@ func (b *DeploymentBundle) Bind(ctx context.Context, client *databricks.Workspac
119123 log .Infof (ctx , "Bound %s to id=%s (in temp state)" , resourceKey , resourceID )
120124
121125 // First plan + update: populate state with resolved config
122- err = b .StateDB .Open (ctx , tmpStatePath , dstate .ReadingFile , dstate . WithRecovery (true ), dstate. OpenDmsArgs {} )
126+ err = b .StateDB .Open (ctx , tmpStatePath , dstate .WithRecovery (true ))
123127 if err != nil {
124128 os .Remove (tmpStatePath )
125129 return nil , err
@@ -168,7 +172,7 @@ func (b *DeploymentBundle) Bind(ctx context.Context, client *databricks.Workspac
168172 return nil , fmt .Errorf ("compacting state: %w" , err )
169173 }
170174
171- err = b .StateDB .Open (ctx , tmpStatePath , dstate .ReadingFile , dstate . WithRecovery (true ), dstate. OpenDmsArgs {} )
175+ err = b .StateDB .Open (ctx , tmpStatePath , dstate .WithRecovery (true ))
172176 if err != nil {
173177 os .Remove (tmpStatePath )
174178 return nil , err
@@ -192,7 +196,7 @@ func (b *DeploymentBundle) Bind(ctx context.Context, client *databricks.Workspac
192196 }
193197
194198 // Second plan: this is the plan to present to the user (change between remote resource and config)
195- err = b .StateDB .Open (ctx , tmpStatePath , dstate .ReadingFile , dstate . WithRecovery (true ), dstate. OpenDmsArgs {} )
199+ err = b .StateDB .Open (ctx , tmpStatePath , dstate .WithRecovery (true ))
196200 if err != nil {
197201 os .Remove (tmpStatePath )
198202 return nil , err
@@ -242,9 +246,12 @@ func (result *BindResult) Cancel() {
242246// Unbind removes a resource from direct engine state without deleting
243247// the workspace resource. Also removes associated permissions/grants entries.
244248func (b * DeploymentBundle ) Unbind (ctx context.Context , statePath , resourceKey string ) error {
245- if err := b .StateDB .Open (ctx , statePath , dstate .ReadingFile , dstate . WithRecovery (true ), dstate. OpenDmsArgs {} ); err != nil {
249+ if err := b .StateDB .Open (ctx , statePath , dstate .WithRecovery (true )); err != nil {
246250 return err
247251 }
252+ if b .StateDB .IsDeploymentMetadataService () {
253+ return errors .New ("unbind is not supported for a bundle target that records deployment history" )
254+ }
248255 if err := b .StateDB .UpgradeToWrite (); err != nil {
249256 return err
250257 }
0 commit comments