@@ -11,26 +11,64 @@ import (
1111func resourceEventHookVerification () * schema.Resource {
1212 return & schema.Resource {
1313 CreateContext : resourceEventHookVerificationCreate ,
14- ReadContext : utils .ResourceFuncNoOp ,
14+ ReadContext : resourceEventHookVerificationRead ,
15+ UpdateContext : resourceEventHookVerificationUpdate ,
1516 DeleteContext : utils .ResourceFuncNoOp ,
1617 Importer : nil ,
1718 Description : "Verifies the Event Hook. The resource won't be created unless the URI provided in the event hook returns a valid JSON object with verification. See [Event Hooks](https://developer.okta.com/docs/concepts/event-hooks/#one-time-verification-request) documentation for details." ,
19+ CustomizeDiff : func (ctx context.Context , d * schema.ResourceDiff , meta interface {}) error {
20+ // When the API reports the hook as UNVERIFIED, force a planned diff so that
21+ // UpdateContext is invoked on the next apply to re-trigger verification.
22+ if d .Id () != "" && d .Get ("verification_status" ).(string ) == "UNVERIFIED" {
23+ return d .SetNew ("verification_status" , "VERIFIED" )
24+ }
25+ return nil
26+ },
1827 Schema : map [string ]* schema.Schema {
1928 "event_hook_id" : {
2029 Type : schema .TypeString ,
2130 Required : true ,
22- ForceNew : true ,
2331 Description : "Event hook ID" ,
2432 },
33+ "verification_status" : {
34+ Type : schema .TypeString ,
35+ Computed : true ,
36+ Description : "Verification status of the Event hook" ,
37+ },
2538 },
2639 }
2740}
2841
2942func resourceEventHookVerificationCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
30- _ , _ , err := getOktaClientFromMetadata (meta ).EventHook .VerifyEventHook (ctx , d .Get ("event_hook_id" ).(string ))
43+ hook , _ , err := getOktaV6ClientFromMetadata (meta ).EventHookAPI .VerifyEventHook (ctx , d .Get ("event_hook_id" ).(string )).Execute ()
44+ if err != nil {
45+ return diag .Errorf ("failed to verify event hook sender: %v" , err )
46+ }
47+ d .SetId (d .Get ("event_hook_id" ).(string ))
48+ _ = d .Set ("verification_status" , hook .VerificationStatus )
49+ return nil
50+ }
51+
52+ func resourceEventHookVerificationRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
53+ hook , resp , err := getOktaV6ClientFromMetadata (meta ).EventHookAPI .GetEventHook (ctx , d .Id ()).Execute ()
54+ if err := utils .SuppressErrorOn404_V6 (resp , err ); err != nil {
55+ return diag .Errorf ("failed to get event hook: %v" , err )
56+ }
57+ if hook == nil {
58+ d .SetId ("" )
59+ return nil
60+ }
61+ d .SetId (d .Get ("event_hook_id" ).(string ))
62+ _ = d .Set ("verification_status" , hook .VerificationStatus )
63+ return nil
64+ }
65+
66+ func resourceEventHookVerificationUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
67+ hook , _ , err := getOktaV6ClientFromMetadata (meta ).EventHookAPI .VerifyEventHook (ctx , d .Get ("event_hook_id" ).(string )).Execute ()
3168 if err != nil {
3269 return diag .Errorf ("failed to verify event hook sender: %v" , err )
3370 }
3471 d .SetId (d .Get ("event_hook_id" ).(string ))
72+ _ = d .Set ("verification_status" , hook .VerificationStatus )
3573 return nil
3674}
0 commit comments