Skip to content

Commit f375ae0

Browse files
committed
Populate Deferred Action Invocations
1 parent 200e97c commit f375ae0

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

internal/stacks/stackplan/from_plan.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,38 @@ func FromPlan(ctx context.Context, config *configs.Config, plan *plans.Plan, ref
207207
})
208208
}
209209

210+
// And the Deferred Action Invocations
211+
for _, deferredAction := range plan.DeferredActionInvocations {
212+
action := deferredAction.ActionInvocationInstanceSrc
213+
214+
schema, err := producer.ActionSchema(ctx,
215+
action.ProviderAddr.Provider, action.Addr.Action.Action.Type)
216+
if err != nil {
217+
diags = diags.Append(tfdiags.Sourceless(
218+
tfdiags.Error,
219+
"Can't fetch provider schema to save plan",
220+
fmt.Sprintf(
221+
"Failed to retrieve schema for %s from provider %s: %s. This is a bug in Terraform.",
222+
action.Addr, action.ProviderAddr.Provider, err)))
223+
continue
224+
}
225+
226+
plannedActionInvocation := PlannedChangeActionInvocationInstancePlanned{
227+
ActionInvocationAddr: stackaddrs.AbsActionInvocationInstance{
228+
Component: producer.Addr(),
229+
Item: action.Addr,
230+
},
231+
Invocation: deferredAction.ActionInvocationInstanceSrc,
232+
ProviderConfigAddr: action.ProviderAddr,
233+
Schema: schema,
234+
}
235+
236+
changes = append(changes, &PlannedChangeDeferredActionInvocationPlanned{
237+
DeferredReason: deferredAction.DeferredReason,
238+
ActionInvocationPlanned: plannedActionInvocation,
239+
})
240+
}
241+
210242
// We also need to catch any objects that exist in the "prior state"
211243
// but don't have any actions planned, since we still need to capture
212244
// the prior state part in case it was updated by refreshing during

internal/stacks/stackplan/planned_change.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,3 +1000,61 @@ func (pc *PlannedChangeActionInvocationInstancePlanned) PlannedChangeProto() (*s
10001000
Descriptions: descs,
10011001
}, nil
10021002
}
1003+
1004+
// PlannedChangeDeferredActionInvocationPlanned announces that an invocation that Terraform
1005+
// is proposing to take if this plan is applied is being deferred.
1006+
type PlannedChangeDeferredActionInvocationPlanned struct {
1007+
// ActionInvocationPlanned is the planned invocation that is being deferred.
1008+
ActionInvocationPlanned PlannedChangeActionInvocationInstancePlanned
1009+
1010+
// DeferredReason is the reason why the change is being deferred.
1011+
DeferredReason providers.DeferredReason
1012+
}
1013+
1014+
var _ PlannedChange = (*PlannedChangeDeferredActionInvocationPlanned)(nil)
1015+
1016+
// PlannedChangeProto implements PlannedChange.
1017+
func (dai *PlannedChangeDeferredActionInvocationPlanned) PlannedChangeProto() (*stacks.PlannedChange, error) {
1018+
invocation, err := dai.ActionInvocationPlanned.PlanActionInvocationProto()
1019+
if err != nil {
1020+
return nil, err
1021+
}
1022+
1023+
// We'll ignore the error here. We certainly should not have got this far
1024+
// if we have a deferred reason that the Terraform Core runtime doesn't
1025+
// recognise. There will be diagnostics elsewhere to reflect this, as we
1026+
// can just use INVALID to capture this. This also makes us forwards and
1027+
// backwards compatible, as we'll return INVALID for any new deferred
1028+
// reasons that are added in the future without erroring.
1029+
deferredReason, _ := planfile.DeferredReasonToProto(dai.DeferredReason)
1030+
1031+
var raw anypb.Any
1032+
err = anypb.MarshalFrom(&raw, &tfstackdata1.PlanDeferredActionInvocation{
1033+
Invocation: invocation,
1034+
Deferred: &planproto.Deferred{
1035+
Reason: deferredReason,
1036+
},
1037+
}, proto.MarshalOptions{})
1038+
if err != nil {
1039+
return nil, err
1040+
}
1041+
desc, err := dai.ActionInvocationPlanned.ChangeDescription()
1042+
if err != nil {
1043+
return nil, err
1044+
}
1045+
1046+
var descs []*stacks.PlannedChange_ChangeDescription
1047+
descs = append(descs, &stacks.PlannedChange_ChangeDescription{
1048+
Description: &stacks.PlannedChange_ChangeDescription_ActionInvocationDeferred{
1049+
ActionInvocationDeferred: &stacks.PlannedChange_ActionInvocationDeferred{
1050+
ActionInvocation: desc.GetActionInvocationPlanned(),
1051+
Deferred: EncodeDeferred(dai.DeferredReason),
1052+
},
1053+
},
1054+
})
1055+
1056+
return &stacks.PlannedChange{
1057+
Raw: []*anypb.Any{&raw},
1058+
Descriptions: descs,
1059+
}, nil
1060+
}

0 commit comments

Comments
 (0)