@@ -26,6 +26,7 @@ func TestContextPlan_actions(t *testing.T) {
2626 module map [string ]string
2727 buildState func (* states.SyncState )
2828 planActionResponse * providers.PlanActionResponse
29+ planOpts * PlanOpts
2930
3031 expectPlanActionCalled bool
3132 expectValidateDiagnostics func (m * configs.Config ) tfdiags.Diagnostics
@@ -616,6 +617,63 @@ output "my_output2" {
616617 return tfdiags.Diagnostics {tfdiags .Sourceless (tfdiags .Error , "Can not access actions" , "Actions can not be accessed, they have no state and can only be referenced with a resources lifecycle action_trigger events list. Tried to access action.test_unlinked.my_action." ), tfdiags .Sourceless (tfdiags .Error , "Can not access actions" , "Actions can not be accessed, they have no state and can only be referenced with a resources lifecycle action_trigger events list. Tried to access action.test_unlinked.my_action." )}
617618 },
618619 },
620+
621+ "destroy run" : {
622+ module : map [string ]string {
623+ "main.tf" : `
624+ terraform { experiments = [actions] }
625+ action "test_unlinked" "hello" {}
626+ resource "test_object" "a" {
627+ lifecycle {
628+ action_trigger {
629+ events = [before_create, after_update]
630+ actions = [action.test_unlinked.hello]
631+ }
632+ }
633+ }
634+ ` ,
635+ },
636+ expectPlanActionCalled : false ,
637+ planOpts : SimplePlanOpts (plans .DestroyMode , InputValues {}),
638+ },
639+
640+ // Since if we just destroy a node there is no reference to an action in config, we try
641+ // to provoke an error by just removing a resource instance.
642+ "destroying expanded node" : {
643+ module : map [string ]string {
644+ "main.tf" : `
645+ terraform { experiments = [actions] }
646+ action "test_unlinked" "hello" {}
647+ resource "test_object" "a" {
648+ count = 2
649+ lifecycle {
650+ action_trigger {
651+ events = [before_create, after_update]
652+ actions = [action.test_unlinked.hello]
653+ }
654+ }
655+ }
656+ ` ,
657+ },
658+ expectPlanActionCalled : false ,
659+
660+ buildState : func (s * states.SyncState ) {
661+ s .SetResourceInstanceCurrent (mustResourceInstanceAddr ("test_object.a[0]" ), & states.ResourceInstanceObjectSrc {
662+ AttrsJSON : []byte (`{}` ),
663+ Status : states .ObjectReady ,
664+ }, mustProviderConfig (`provider["registry.terraform.io/hashicorp/test"]` ))
665+
666+ s .SetResourceInstanceCurrent (mustResourceInstanceAddr ("test_object.a[1]" ), & states.ResourceInstanceObjectSrc {
667+ AttrsJSON : []byte (`{}` ),
668+ Status : states .ObjectReady ,
669+ }, mustProviderConfig (`provider["registry.terraform.io/hashicorp/test"]` ))
670+
671+ s .SetResourceInstanceCurrent (mustResourceInstanceAddr ("test_object.a[2]" ), & states.ResourceInstanceObjectSrc {
672+ AttrsJSON : []byte (`{}` ),
673+ Status : states .ObjectReady ,
674+ }, mustProviderConfig (`provider["registry.terraform.io/hashicorp/test"]` ))
675+ },
676+ },
619677 } {
620678 t .Run (name , func (t * testing.T ) {
621679 if tc .toBeImplemented {
@@ -683,7 +741,12 @@ output "my_output2" {
683741 prevRunState = states .BuildState (tc .buildState )
684742 }
685743
686- _ , diags = ctx .Plan (m , prevRunState , SimplePlanOpts (plans .NormalMode , InputValues {}))
744+ opts := SimplePlanOpts (plans .NormalMode , InputValues {})
745+ if tc .planOpts != nil {
746+ opts = tc .planOpts
747+ }
748+
749+ _ , diags = ctx .Plan (m , prevRunState , opts )
687750
688751 if tc .expectPlanDiagnostics != nil {
689752 tfdiags .AssertDiagnosticsMatch (t , diags , tc .expectPlanDiagnostics (m ))
0 commit comments