adding some code to simplify switching over to the instance expander for actions

mildwonkey/action-prep
Kristin Laemmert 7 days ago
parent f463e420b2
commit 3bcbdda0b0

@ -100,13 +100,12 @@ func TestContextPlan_actions(t *testing.T) {
}
for topic, tcs := range map[string]map[string]struct {
toBeImplemented bool
module map[string]string
buildState func(*states.SyncState)
planActionFn func(*testing.T, providers.PlanActionRequest) providers.PlanActionResponse
planResourceFn func(*testing.T, providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
readResourceFn func(*testing.T, providers.ReadResourceRequest) providers.ReadResourceResponse
planOpts *PlanOpts
module map[string]string
buildState func(*states.SyncState)
planActionFn func(*testing.T, providers.PlanActionRequest) providers.PlanActionResponse
planResourceFn func(*testing.T, providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
readResourceFn func(*testing.T, providers.ReadResourceRequest) providers.ReadResourceResponse
planOpts *PlanOpts
expectPlanActionCalled bool

@ -25,13 +25,13 @@ import (
//
// This is the partial-expanded equivalent of NodeActionTriggerInstance.
type NodeActionTriggerPartialExpanded struct {
addr addrs.PartialExpandedAction
config *configs.Action
resolvedProvider addrs.AbsProviderConfig
lifecycleActionTrigger *lifecycleActionTriggerPartialExpanded
addr addrs.PartialExpandedAction
config *configs.Action
resolvedProvider addrs.AbsProviderConfig
resourceActionTrigger *resourceActionTriggerPartialExpanded
}
type lifecycleActionTriggerPartialExpanded struct {
type resourceActionTriggerPartialExpanded struct {
resourceAddress addrs.PartialExpandedResource
events []configs.ActionTriggerEvent
actionTriggerBlockIndex int
@ -39,7 +39,7 @@ type lifecycleActionTriggerPartialExpanded struct {
invokingSubject *hcl.Range
}
func (at *lifecycleActionTriggerPartialExpanded) Name() string {
func (at *resourceActionTriggerPartialExpanded) Name() string {
return fmt.Sprintf("%s.lifecycle.action_trigger[%d].actions[%d]", at.resourceAddress.String(), at.actionTriggerBlockIndex, at.actionListIndex)
}
@ -74,12 +74,12 @@ func (n *NodeActionTriggerPartialExpanded) ActionAddr() addrs.ConfigAction {
func (n *NodeActionTriggerPartialExpanded) Execute(ctx EvalContext, op walkOperation) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
// We know that if the action is partially expanded, the triggering resource must also be partially expanded.
partialResourceChange := ctx.Deferrals().GetDeferredPartialExpandedResource(n.lifecycleActionTrigger.resourceAddress)
partialResourceChange := ctx.Deferrals().GetDeferredPartialExpandedResource(n.resourceActionTrigger.resourceAddress)
if partialResourceChange == nil {
panic("partialResource is nil")
}
triggeringEvents := actionIsTriggeredByEvent(n.lifecycleActionTrigger.events, partialResourceChange.Change.Action)
triggeringEvents := actionIsTriggeredByEvent(n.resourceActionTrigger.events, partialResourceChange.Change.Action)
if len(triggeringEvents) == 0 {
return nil
}
@ -95,7 +95,7 @@ func (n *NodeActionTriggerPartialExpanded) Execute(ctx EvalContext, op walkOpera
Severity: hcl.DiagError,
Summary: "Failed to get provider",
Detail: fmt.Sprintf("Failed to get provider: %s", err),
Subject: n.lifecycleActionTrigger.invokingSubject,
Subject: n.resourceActionTrigger.invokingSubject,
})
return diags
@ -120,10 +120,10 @@ func (n *NodeActionTriggerPartialExpanded) Execute(ctx EvalContext, op walkOpera
Addr: n.addr.UnknownActionInstance(),
ProviderAddr: n.resolvedProvider,
ActionTrigger: &plans.ResourceActionTrigger{
TriggeringResourceAddr: n.lifecycleActionTrigger.resourceAddress.UnknownResourceInstance(),
TriggeringResourceAddr: n.resourceActionTrigger.resourceAddress.UnknownResourceInstance(),
ActionTriggerEvent: triggeringEvent,
ActionTriggerBlockIndex: n.lifecycleActionTrigger.actionTriggerBlockIndex,
ActionsListIndex: n.lifecycleActionTrigger.actionListIndex,
ActionTriggerBlockIndex: n.resourceActionTrigger.actionTriggerBlockIndex,
ActionsListIndex: n.resourceActionTrigger.actionListIndex,
},
ConfigValue: actionInstance.ConfigValue,
}, providers.DeferredReasonInstanceCountUnknown)

@ -58,7 +58,7 @@ func (n *nodeActionTriggerPlanExpand) DynamicExpand(ctx EvalContext) (*Graph, tf
addr: actionAddr,
config: n.Config,
resolvedProvider: n.resolvedProvider,
lifecycleActionTrigger: &lifecycleActionTriggerPartialExpanded{
resourceActionTrigger: &resourceActionTriggerPartialExpanded{
resourceAddress: resourceAddr,
events: n.triggerConfig.events,
actionTriggerBlockIndex: n.triggerConfig.actionTriggerBlockIndex,

Loading…
Cancel
Save