@@ -35,11 +35,11 @@ type Loader struct {
35
35
// Constructs a new [Loader], with an initial empty plan.
36
36
func NewLoader () * Loader {
37
37
ret := & Plan {
38
+ Root : newStackInstance (stackaddrs .RootStackInstance ),
38
39
RootInputValues : make (map [stackaddrs.InputVariable ]cty.Value ),
39
40
ApplyTimeInputVariables : collections .NewSetCmp [stackaddrs.InputVariable ](),
40
41
DeletedInputVariables : collections .NewSet [stackaddrs.InputVariable ](),
41
42
DeletedOutputValues : collections .NewSet [stackaddrs.OutputValue ](),
42
- Components : collections .NewMap [stackaddrs.AbsComponentInstance , * Component ](),
43
43
DeletedComponents : collections .NewSet [stackaddrs.AbsComponentInstance ](),
44
44
PrevRunStateRaw : make (map [string ]* anypb.Any ),
45
45
}
@@ -220,27 +220,24 @@ func (l *Loader) AddRaw(rawMsg *anypb.Any) error {
220
220
})
221
221
}
222
222
223
- if ! l .ret .Components .HasKey (addr ) {
224
- l .ret .Components .Put (addr , & Component {
225
- PlannedAction : plannedAction ,
226
- Mode : mode ,
227
- PlanApplyable : msg .PlanApplyable ,
228
- PlanComplete : msg .PlanComplete ,
229
- Dependencies : dependencies ,
230
- Dependents : collections .NewSet [stackaddrs.AbsComponent ](),
231
- PlannedInputValues : inputVals ,
232
- PlannedInputValueMarks : inputValMarks ,
233
- PlannedOutputValues : outputVals ,
234
- PlannedChecks : checkResults ,
235
- PlannedFunctionResults : functionResults ,
236
-
237
- ResourceInstancePlanned : addrs .MakeMap [addrs.AbsResourceInstanceObject , * plans.ResourceInstanceChangeSrc ](),
238
- ResourceInstancePriorState : addrs .MakeMap [addrs.AbsResourceInstanceObject , * states.ResourceInstanceObjectSrc ](),
239
- ResourceInstanceProviderConfig : addrs .MakeMap [addrs.AbsResourceInstanceObject , addrs.AbsProviderConfig ](),
240
- DeferredResourceInstanceChanges : addrs .MakeMap [addrs.AbsResourceInstanceObject , * plans.DeferredResourceInstanceChangeSrc ](),
241
- })
242
- }
243
- c := l .ret .Components .Get (addr )
223
+ c := l .ret .GetOrCreate (addr , & Component {
224
+ PlannedAction : plannedAction ,
225
+ Mode : mode ,
226
+ PlanApplyable : msg .PlanApplyable ,
227
+ PlanComplete : msg .PlanComplete ,
228
+ Dependencies : dependencies ,
229
+ Dependents : collections .NewSet [stackaddrs.AbsComponent ](),
230
+ PlannedInputValues : inputVals ,
231
+ PlannedInputValueMarks : inputValMarks ,
232
+ PlannedOutputValues : outputVals ,
233
+ PlannedChecks : checkResults ,
234
+ PlannedFunctionResults : functionResults ,
235
+
236
+ ResourceInstancePlanned : addrs .MakeMap [addrs.AbsResourceInstanceObject , * plans.ResourceInstanceChangeSrc ](),
237
+ ResourceInstancePriorState : addrs .MakeMap [addrs.AbsResourceInstanceObject , * states.ResourceInstanceObjectSrc ](),
238
+ ResourceInstanceProviderConfig : addrs .MakeMap [addrs.AbsResourceInstanceObject , addrs.AbsProviderConfig ](),
239
+ DeferredResourceInstanceChanges : addrs .MakeMap [addrs.AbsResourceInstanceObject , * plans.DeferredResourceInstanceChangeSrc ](),
240
+ })
244
241
err = c .PlanTimestamp .UnmarshalText ([]byte (msg .PlanTimestamp ))
245
242
if err != nil {
246
243
return fmt .Errorf ("invalid plan timestamp %q for %s" , msg .PlanTimestamp , addr )
@@ -329,26 +326,15 @@ func (l *Loader) Plan() (*Plan, error) {
329
326
330
327
// Before we return we'll calculate the reverse dependency information
331
328
// based on the forward dependency information we loaded above.
332
- for dependentInstAddr , dependencyInst := range l .ret .Components . All () {
329
+ for dependentInstAddr , dependencyInst := range l .ret .AllComponents () {
333
330
dependentAddr := stackaddrs.AbsComponent {
334
331
Stack : dependentInstAddr .Stack ,
335
332
Item : dependentInstAddr .Item .Component ,
336
333
}
337
334
338
335
for dependencyAddr := range dependencyInst .Dependencies .All () {
339
- // FIXME: This is very inefficient because the current data structure doesn't
340
- // allow looking up all of the component instances that have a particular
341
- // component. This'll be okay as long as the number of components is
342
- // small, but we'll need to improve this if we ever want to support stacks
343
- // with a large number of components.
344
- for maybeDependencyInstAddr , dependencyInst := range l .ret .Components .All () {
345
- maybeDependencyAddr := stackaddrs.AbsComponent {
346
- Stack : maybeDependencyInstAddr .Stack ,
347
- Item : maybeDependencyInstAddr .Item .Component ,
348
- }
349
- if dependencyAddr .UniqueKey () == maybeDependencyAddr .UniqueKey () {
350
- dependencyInst .Dependents .Add (dependentAddr )
351
- }
336
+ for _ , dependencyInst := range l .ret .ComponentInstances (dependencyAddr ) {
337
+ dependencyInst .Dependents .Add (dependentAddr )
352
338
}
353
339
}
354
340
}
@@ -439,7 +425,7 @@ func LoadComponentForResourceInstance(plan *Plan, change *tfstackdata1.PlanResou
439
425
DeposedKey : deposedKey ,
440
426
}
441
427
442
- c , ok := plan .Components .GetOk (cAddr )
428
+ c , ok := plan .Root .GetOk (cAddr )
443
429
if ! ok {
444
430
return nil , addrs.AbsResourceInstanceObject {}, addrs.AbsProviderConfig {}, fmt .Errorf ("resource instance change for unannounced component instance %s" , cAddr )
445
431
}
@@ -476,7 +462,7 @@ func LoadComponentForPartialResourceInstance(plan *Plan, change *tfstackdata1.Pl
476
462
DeposedKey : deposedKey ,
477
463
}
478
464
479
- c , ok := plan .Components .GetOk (cAddr )
465
+ c , ok := plan .Root .GetOk (cAddr )
480
466
if ! ok {
481
467
return nil , addrs.AbsResourceInstanceObject {}, addrs.AbsProviderConfig {}, fmt .Errorf ("resource instance change for unannounced component instance %s" , cAddr )
482
468
}
0 commit comments