-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Matejrisek/actions/on failure #37945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
3c2aaa5
8aa68aa
aa4edf1
c3f0dae
a426a07
054daae
c6efbc0
2a46bea
047af32
db41829
d04ce1b
3402c5f
42dee18
7068aa3
a780c9a
7fe146f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| kind: ENHANCEMENTS | ||
| body: 'actions: `action_trigger` block now supports `on_failure` attribute, which allows specifying terraform behavior on action failure.' | ||
| time: 2025-11-28T11:24:28.415647+01:00 | ||
| custom: | ||
| Issue: "37945" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ package terraform | |
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
|
|
||
| "github.com/hashicorp/hcl/v2" | ||
|
|
||
|
|
@@ -159,7 +160,7 @@ func (n *nodeActionTriggerApplyInstance) Execute(ctx EvalContext, wo walkOperati | |
| diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) { | ||
| return h.CompleteAction(hookIdentity, respDiags.Err()) | ||
| })) | ||
| return diags | ||
| return diagsIfNeeded(ai, diags) | ||
| } | ||
|
|
||
| if resp.Events != nil { // should only occur in misconfigured tests | ||
|
|
@@ -169,21 +170,12 @@ func (n *nodeActionTriggerApplyInstance) Execute(ctx EvalContext, wo walkOperati | |
| diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) { | ||
| return h.ProgressAction(hookIdentity, ev.Message) | ||
| })) | ||
| if diags.HasErrors() { | ||
| return diags | ||
| } | ||
| case providers.InvokeActionEvent_Completed: | ||
| // Enhance the diagnostics | ||
| diags = diags.Append(n.AddSubjectToDiagnostics(ev.Diagnostics)) | ||
| diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) { | ||
| return h.CompleteAction(hookIdentity, ev.Diagnostics.Err()) | ||
| })) | ||
| if ev.Diagnostics.HasErrors() { | ||
| return diags | ||
| } | ||
| if diags.HasErrors() { | ||
| return diags | ||
| } | ||
| default: | ||
| panic(fmt.Sprintf("unexpected action event type %T", ev)) | ||
| } | ||
|
|
@@ -197,7 +189,26 @@ func (n *nodeActionTriggerApplyInstance) Execute(ctx EvalContext, wo walkOperati | |
| }) | ||
| } | ||
|
|
||
| return diags | ||
| return diagsIfNeeded(ai, diags) | ||
| } | ||
|
|
||
| func diagsIfNeeded( | ||
| aii *plans.ActionInvocationInstance, | ||
| currentDiags tfdiags.Diagnostics, | ||
| ) tfdiags.Diagnostics { | ||
| switch aii.ActionTrigger.TriggerOnFailure() { | ||
| case configs.ActionTriggerOnFailureContinue: | ||
| if currentDiags.HasErrors() { | ||
|
||
| log.Printf("[WARN] Errors while running action %s, but"+ | ||
| " continuing as request in configuration.", aii.Addr) | ||
| } | ||
| return nil | ||
| default: | ||
| // Nothing to do for now - here to make it exhaustive and to denote the | ||
| // place to put potential new `on failure` cases. | ||
| } | ||
|
|
||
| return currentDiags | ||
| } | ||
|
|
||
| func (n *nodeActionTriggerApplyInstance) ProvidedBy() (addr addrs.ProviderConfig, exact bool) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,7 @@ type nodeActionTriggerPlanInstance struct { | |||||
| type lifecycleActionTriggerInstance struct { | ||||||
| resourceAddress addrs.AbsResourceInstance | ||||||
| events []configs.ActionTriggerEvent | ||||||
| onFailure configs.ActionTriggerOnFailure | ||||||
| actionTriggerBlockIndex int | ||||||
| actionListIndex int | ||||||
| invokingSubject *hcl.Range | ||||||
|
|
@@ -52,6 +53,7 @@ func (at *lifecycleActionTriggerInstance) ActionTrigger(triggeringEvent configs. | |||||
| ActionTriggerBlockIndex: at.actionTriggerBlockIndex, | ||||||
| ActionsListIndex: at.actionListIndex, | ||||||
| ActionTriggerEvent: triggeringEvent, | ||||||
| ActionTriggerOnFailure: at.onFailure, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now part of
Also I think we need to handle this in terraform/internal/plans/planfile/tfplan.go Line 1357 in a051ac6
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the test cases could be more extensive:
on_failure = continuecontinues with the other actions in theactionslist and in otheraction_triggerblocks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for this pointers.
They should have been address in this commit: 2a46bea.
Just for the clarification:
Do you mean we should assert action invocations or we do something else to verify changes?