@@ -102,7 +102,7 @@ func (b *DeploymentBundle) InitForApply(ctx context.Context, client *databricks.
102102 return fmt .Errorf ("loading plan entry %s: %w" , resourceKey , err )
103103 }
104104
105- b .StructVarCache .Store (resourceKey , sv )
105+ b .StateCache .Store (resourceKey , sv )
106106 }
107107
108108 b .Plan = plan
@@ -218,9 +218,9 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks
218218 // for integers: compare 0 with actual object ID. As long as real object IDs are never 0 we're good.
219219 // Once we add non-id fields or add per-field details to "bundle plan", we must read dynamic data and deal with references as first class citizen.
220220 // This means distinguishing between 0 that are actually object ids and 0 that are there because typed struct integer cannot contain ${...} string.
221- sv , ok := b .StructVarCache .Load (resourceKey )
221+ sv , ok := b .StateCache .Load (resourceKey )
222222 if ! ok {
223- logdiag .LogError (ctx , fmt .Errorf ("%s: internal error: no state found for %q" , errorPrefix , resourceKey ))
223+ logdiag .LogError (ctx , fmt .Errorf ("%s: internal error: no state cache entry found for %q" , errorPrefix , resourceKey ))
224224 return false
225225 }
226226 localDiff , err := structdiff .GetStructDiff (savedState , sv .Value , adapter .KeyedSlices ())
@@ -558,10 +558,9 @@ func (b *DeploymentBundle) LookupReferencePreDeploy(ctx context.Context, path *s
558558 return nil , fmt .Errorf ("internal error: %s: action is %q missing new_state" , targetResourceKey , targetEntry .Action )
559559 }
560560
561- // Get StructVar from cache
562- sv , ok := b .StructVarCache .Load (targetResourceKey )
561+ sv , ok := b .StateCache .Load (targetResourceKey )
563562 if ! ok {
564- return nil , fmt .Errorf ("internal error: %s: missing cached StructVar " , targetResourceKey )
563+ return nil , fmt .Errorf ("internal error: %s: missing state cache entry " , targetResourceKey )
565564 }
566565
567566 _ , isUnresolved := sv .Refs [fieldPathS ]
@@ -604,6 +603,8 @@ func (b *DeploymentBundle) LookupReferencePreDeploy(ctx context.Context, path *s
604603 remoteState , ok := b .RemoteStateCache .Load (targetResourceKey )
605604 if ok {
606605 return structaccess .Get (remoteState , fieldPath )
606+ } else {
607+ return nil , fmt .Errorf ("internal error: no entry in remote state cache for %q (remote-only)" , targetResourceKey )
607608 }
608609 }
609610 return nil , errDelayed
@@ -621,27 +622,19 @@ func (b *DeploymentBundle) LookupReferencePreDeploy(ctx context.Context, path *s
621622 remoteState , ok := b .RemoteStateCache .Load (targetResourceKey )
622623 if ok {
623624 return structaccess .Get (remoteState , fieldPath )
625+ } else {
626+ return nil , fmt .Errorf ("internal error: no entry in remote state cache for %q" , targetResourceKey )
624627 }
625628 }
626629
627630 return nil , errDelayed
628631}
629632
630- // getStructVar returns the cached StructVar for the given resource key.
631- // The StructVar must have been eagerly loaded during plan creation or InitForApply.
632- func (b * DeploymentBundle ) getStructVar (resourceKey string ) (* structvar.StructVar , error ) {
633- sv , ok := b .StructVarCache .Load (resourceKey )
634- if ! ok {
635- return nil , fmt .Errorf ("internal error: StructVar not found in cache for %s" , resourceKey )
636- }
637- return sv , nil
638- }
639-
640633// resolveReferences processes all references in entry.NewState.Refs.
641- func (b * DeploymentBundle ) resolveReferences (ctx context.Context , resourceKey string , entry * deployplan.PlanEntry , errorPrefix string , isLocal bool ) bool {
642- sv , err := b .getStructVar (resourceKey )
643- if err != nil {
644- logdiag .LogError (ctx , fmt .Errorf ("%s: %w " , errorPrefix , err ))
634+ func (b * DeploymentBundle ) resolveReferences (ctx context.Context , resourceKey string , entry * deployplan.PlanEntry , errorPrefix string , isPreDeploy bool ) bool {
635+ sv , ok := b .StateCache . Load (resourceKey )
636+ if ! ok {
637+ logdiag .LogError (ctx , fmt .Errorf ("%s: internal error: no cache entry found for %q " , errorPrefix , resourceKey ))
645638 return false
646639 }
647640
@@ -662,7 +655,7 @@ func (b *DeploymentBundle) resolveReferences(ctx context.Context, resourceKey st
662655 }
663656
664657 var value any
665- if isLocal {
658+ if isPreDeploy {
666659 value , err = b .LookupReferencePreDeploy (ctx , targetPath )
667660 if err != nil {
668661 if errors .Is (err , errDelayed ) {
@@ -853,7 +846,7 @@ func (b *DeploymentBundle) makePlan(ctx context.Context, configRoot *config.Root
853846 }
854847
855848 // Store in cache for use during planning phase
856- b .StructVarCache .Store (node , newState )
849+ b .StateCache .Store (node , newState )
857850
858851 // Convert to JSON for serialization in plan
859852 newStateJSON , err := newState .ToJSON ()
0 commit comments