@@ -14,7 +14,6 @@ import (
1414 "github.com/databricks/cli/libs/diag"
1515 "github.com/databricks/cli/libs/log"
1616 "github.com/databricks/cli/libs/logdiag"
17- "github.com/databricks/cli/libs/utils"
1817 "github.com/databricks/databricks-sdk-go"
1918)
2019
@@ -37,32 +36,32 @@ func (m *terranovaApplyMutator) Apply(ctx context.Context, b *bundle.Bundle) dia
3736 return nil
3837 }
3938
39+ g , isReferenced , err := makeResourceGraph (ctx , b )
40+ if err != nil {
41+ logdiag .LogError (ctx , fmt .Errorf ("error while reading config: %w" , err ))
42+ }
43+
4044 // Maps node key to originally planned action
4145 plannedActionsMap := map [nodeKey ]deployplan.ActionType {}
4246
4347 for _ , action := range b .Plan .Actions {
48+ node := nodeKey {action .Group , action .Name }
4449 plannedActionsMap [nodeKey {action .Group , action .Name }] = action .ActionType
45- }
46-
47- state := b .ResourceDatabase .ExportState (ctx )
48- g , isReferenced , err := makeResourceGraph (ctx , b , state )
49- if err != nil {
50- logdiag .LogError (ctx , fmt .Errorf ("error while reading config: %w" , err ))
51- }
52-
53- // Remained in state are resources that no longer present in the config
54- for _ , group := range utils .SortedKeys (state ) {
55- groupData := state [group ]
56- for _ , name := range utils .SortedKeys (groupData ) {
57- n := nodeKey {group , name }
58- g .AddNode (n )
59- if plannedActionsMap [n ] != deployplan .ActionTypeDelete {
60- logdiag .LogError (ctx , fmt .Errorf ("internal error, resources %s.%s is missing from state but action is not delete but %v" , group , name , plannedActionsMap [n ]))
61- return nil
50+ if ! g .HasNode (node ) {
51+ if action .ActionType == deployplan .ActionTypeDelete {
52+ // it is expected that this node is not seen by makeResourceGraph
53+ g .AddNode (node )
54+ } else {
55+ // it's internal error today because plan cannot be outdated. In the future when we load serialized plan, this will become user error
56+ logdiag .LogError (ctx , fmt .Errorf ("cannot %s %s.%s: internal error, plan is outdated" , action .ActionType , action .Group , action .Name ))
6257 }
6358 }
6459 }
6560
61+ if logdiag .HasError (ctx ) {
62+ return nil
63+ }
64+
6665 err = g .DetectCycle ()
6766 if err != nil {
6867 return diag .FromErr (err )
0 commit comments