Skip to content

Commit 9a4f3ee

Browse files
committed
Populate ActionTrigger
1 parent 5ac6b63 commit 9a4f3ee

File tree

3 files changed

+60
-23
lines changed

3 files changed

+60
-23
lines changed

internal/rpcapi/terraform1/stacks/stacks.pb.go

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/rpcapi/terraform1/stacks/stacks.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ message PlannedChange {
599599
// LifecycleActionTrigger contains details on the conditions that led to the
600600
// triggering of an action.
601601
message LifecycleActionTrigger {
602-
ResourceInstanceObjectInStackAddr triggering_resource_address = 1;
602+
ResourceInstanceInStackAddr triggering_resource_address = 1;
603603
ActionTriggerEvent trigger_event = 2;
604604
int64 action_trigger_block_index = 3;
605605
int64 actions_list_index = 4;

internal/stacks/stackplan/planned_change.go

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/hashicorp/terraform/internal/addrs"
1717
"github.com/hashicorp/terraform/internal/collections"
18+
"github.com/hashicorp/terraform/internal/configs"
1819
"github.com/hashicorp/terraform/internal/lang"
1920
"github.com/hashicorp/terraform/internal/lang/marks"
2021
"github.com/hashicorp/terraform/internal/plans"
@@ -909,19 +910,55 @@ func (pc *PlannedChangeActionInvocationInstancePlanned) ChangeDescription() (*st
909910
return nil, nil
910911
}
911912

912-
return &stacks.PlannedChange_ChangeDescription{
913-
Description: &stacks.PlannedChange_ChangeDescription_ActionInvocationPlanned{
914-
ActionInvocationPlanned: &stacks.PlannedChange_ActionInvocationInstance{
915-
Addr: stacks.NewActionInvocationInStackAddr(addr),
916-
ProviderAddr: pc.Invocation.ProviderAddr.Provider.String(),
917-
918-
ConfigValue: stacks.NewDynamicValue(
919-
pc.Invocation.ConfigValue,
920-
pc.Invocation.SensitiveConfigPaths,
921-
),
913+
invoke := stacks.PlannedChange_ActionInvocationInstance{
914+
Addr: stacks.NewActionInvocationInStackAddr(addr),
915+
ProviderAddr: pc.Invocation.ProviderAddr.Provider.String(),
916+
917+
ConfigValue: stacks.NewDynamicValue(
918+
pc.Invocation.ConfigValue,
919+
pc.Invocation.SensitiveConfigPaths,
920+
),
921+
}
922+
923+
switch at := pc.Invocation.ActionTrigger.(type) {
924+
case *plans.LifecycleActionTrigger:
925+
triggerEvent := stacks.PlannedChange_INVALID_EVENT
926+
switch at.ActionTriggerEvent {
927+
case configs.BeforeCreate:
928+
triggerEvent = stacks.PlannedChange_BEFORE_CREATE
929+
case configs.AfterCreate:
930+
triggerEvent = stacks.PlannedChange_AFTER_CREATE
931+
case configs.BeforeUpdate:
932+
triggerEvent = stacks.PlannedChange_BEFORE_UPDATE
933+
case configs.AfterUpdate:
934+
triggerEvent = stacks.PlannedChange_AFTER_UPDATE
935+
case configs.BeforeDestroy:
936+
triggerEvent = stacks.PlannedChange_BEFORE_DESTROY
937+
case configs.AfterDestroy:
938+
triggerEvent = stacks.PlannedChange_AFTER_DESTROY
939+
}
922940

923-
ActionTrigger: nil,
941+
invoke.ActionTrigger = &stacks.PlannedChange_ActionInvocationInstance_LifecycleActionTrigger{
942+
LifecycleActionTrigger: &stacks.PlannedChange_LifecycleActionTrigger{
943+
TriggerEvent: triggerEvent,
944+
TriggeringResourceAddress: stacks.NewResourceInstanceInStackAddr(stackaddrs.AbsResourceInstance{
945+
Component: addr.Component,
946+
Item: at.TriggeringResourceAddr,
947+
}),
948+
ActionTriggerBlockIndex: int64(at.ActionTriggerBlockIndex),
949+
ActionsListIndex: int64(at.ActionsListIndex),
924950
},
951+
}
952+
case *plans.InvokeActionTrigger:
953+
invoke.ActionTrigger = new(stacks.PlannedChange_ActionInvocationInstance_InvokeActionTrigger)
954+
default:
955+
// This should be exhaustive
956+
return nil, fmt.Errorf("unsupported action trigger type: %T", at)
957+
}
958+
959+
return &stacks.PlannedChange_ChangeDescription{
960+
Description: &stacks.PlannedChange_ChangeDescription_ActionInvocationPlanned{
961+
ActionInvocationPlanned: &invoke,
925962
},
926963
}, nil
927964
}

0 commit comments

Comments
 (0)