Skip to content

Commit 3b12eb0

Browse files
actions: serialize trigger event in hooks
1 parent 47994b5 commit 3b12eb0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

internal/command/views/hook_json_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ func TestJSONHook_actions(t *testing.T) {
657657
"resource_name": "boop",
658658
"resource_type": "test_instance",
659659
},
660+
"trigger_event": "AfterCreate",
660661
"trigger_index": float64(0),
661662
},
662663
},
@@ -686,6 +687,7 @@ func TestJSONHook_actions(t *testing.T) {
686687
"resource_name": "boop",
687688
"resource_type": "test_instance",
688689
},
690+
"trigger_event": "AfterCreate",
689691
"trigger_index": float64(0),
690692
},
691693
},
@@ -714,6 +716,7 @@ func TestJSONHook_actions(t *testing.T) {
714716
"resource_name": "boop",
715717
"resource_type": "test_instance",
716718
},
719+
"trigger_event": "AfterCreate",
717720
"trigger_index": float64(2),
718721
},
719722
},
@@ -743,6 +746,7 @@ func TestJSONHook_actions(t *testing.T) {
743746
"resource_name": "boop",
744747
"resource_type": "test_instance",
745748
},
749+
"trigger_event": "AfterCreate",
746750
"trigger_index": float64(2),
747751
},
748752
},
@@ -771,6 +775,7 @@ func TestJSONHook_actions(t *testing.T) {
771775
"resource_name": "boop",
772776
"resource_type": "test_instance",
773777
},
778+
"trigger_event": "AfterCreate",
774779
"trigger_index": float64(2),
775780
},
776781
},
@@ -800,6 +805,7 @@ func TestJSONHook_actions(t *testing.T) {
800805
"resource_name": "boop",
801806
"resource_type": "test_instance",
802807
},
808+
"trigger_event": "AfterCreate",
803809
"trigger_index": float64(0),
804810
},
805811
},

internal/command/views/json/hook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ type actionStart struct {
359359
TriggeringResource ResourceAddr `json:"resource"`
360360
TriggerIndex int `json:"trigger_index"`
361361
ActionsIndex int `json:"actions_index"`
362+
TriggerEvent string `json:"trigger_event"`
362363
Action ActionAddr `json:"action"`
363364
}
364365

@@ -382,6 +383,7 @@ func NewActionStart(id terraform.HookActionIdentity) Hook {
382383
TriggeringResource: newResourceAddr(at.TriggeringResourceAddr),
383384
TriggerIndex: at.ActionTriggerBlockIndex,
384385
ActionsIndex: at.ActionsListIndex,
386+
TriggerEvent: at.ActionTriggerEvent.String(),
385387
Action: newActionAddr(id.Addr),
386388
}
387389
}
@@ -390,6 +392,7 @@ type actionProgress struct {
390392
TriggeringResource ResourceAddr `json:"resource"`
391393
TriggerIndex int `json:"trigger_index"`
392394
ActionsIndex int `json:"actions_index"`
395+
TriggerEvent string `json:"trigger_event"`
393396
Action ActionAddr `json:"action"`
394397
Message string `json:"message"`
395398
}
@@ -413,6 +416,7 @@ func NewActionProgress(id terraform.HookActionIdentity, message string) Hook {
413416
TriggeringResource: newResourceAddr(at.TriggeringResourceAddr),
414417
TriggerIndex: at.ActionTriggerBlockIndex,
415418
ActionsIndex: at.ActionsListIndex,
419+
TriggerEvent: at.ActionTriggerEvent.String(),
416420
Action: newActionAddr(id.Addr),
417421
Message: message,
418422
}
@@ -422,6 +426,7 @@ type actionComplete struct {
422426
TriggeringResource ResourceAddr `json:"resource"`
423427
TriggerIndex int `json:"trigger_index"`
424428
ActionsIndex int `json:"actions_index"`
429+
TriggerEvent string `json:"trigger_event"`
425430
Action ActionAddr `json:"action"`
426431
}
427432

@@ -444,6 +449,7 @@ func NewActionComplete(id terraform.HookActionIdentity) Hook {
444449
TriggeringResource: newResourceAddr(at.TriggeringResourceAddr),
445450
TriggerIndex: at.ActionTriggerBlockIndex,
446451
ActionsIndex: at.ActionsListIndex,
452+
TriggerEvent: at.ActionTriggerEvent.String(),
447453
Action: newActionAddr(id.Addr),
448454
}
449455
}
@@ -452,6 +458,7 @@ type actionErrored struct {
452458
TriggeringResource ResourceAddr `json:"resource"`
453459
TriggerIndex int `json:"trigger_index"`
454460
ActionsIndex int `json:"actions_index"`
461+
TriggerEvent string `json:"trigger_event"`
455462
Action ActionAddr `json:"action"`
456463
Error string `json:"error"`
457464
}
@@ -475,6 +482,7 @@ func NewActionErrored(id terraform.HookActionIdentity, err error) Hook {
475482
TriggeringResource: newResourceAddr(at.TriggeringResourceAddr),
476483
TriggerIndex: at.ActionTriggerBlockIndex,
477484
ActionsIndex: at.ActionsListIndex,
485+
TriggerEvent: at.ActionTriggerEvent.String(),
478486
Action: newActionAddr(id.Addr),
479487
Error: err.Error(),
480488
}

0 commit comments

Comments
 (0)