Skip to content
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

Avoid panic at null workflow in IW trigger, allowing it to refresh #955

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions pagerduty/resource_pagerduty_incident_workflow_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func resourcePagerDutyIncidentWorkflowTrigger() *schema.Resource {
"workflow": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"services": {
Type: schema.TypeList,
Expand Down Expand Up @@ -88,15 +89,27 @@ func resourcePagerDutyIncidentWorkflowTriggerCreate(ctx context.Context, d *sche

log.Printf("[INFO] Creating PagerDuty incident workflow trigger %s for %s.", iwt.Type, iwt.Workflow.ID)

createdWorkflowTrigger, _, err := client.IncidentWorkflowTriggers.CreateContext(ctx, iwt)
if err != nil {
return diag.FromErr(err)
}
err = retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
createdWorkflowTrigger, _, err := client.IncidentWorkflowTriggers.CreateContext(ctx, iwt)
if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return retry.NonRetryableError(err)
}

err = flattenIncidentWorkflowTrigger(d, createdWorkflowTrigger)
return retry.RetryableError(err)
}

err = flattenIncidentWorkflowTrigger(d, createdWorkflowTrigger)
if err != nil {
return retry.NonRetryableError(err)
}

return nil
})
if err != nil {
return diag.FromErr(err)
}

return nil
}

Expand All @@ -122,15 +135,26 @@ func resourcePagerDutyIncidentWorkflowTriggerUpdate(ctx context.Context, d *sche

log.Printf("[INFO] Updating PagerDuty incident workflow trigger %s", d.Id())

updatedWorkflowTrigger, _, err := client.IncidentWorkflowTriggers.UpdateContext(ctx, d.Id(), iwt)
if err != nil {
return diag.FromErr(err)
}
err = retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
updatedWorkflowTrigger, _, err := client.IncidentWorkflowTriggers.UpdateContext(ctx, d.Id(), iwt)
if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return retry.NonRetryableError(err)
}
return retry.RetryableError(err)
}

err = flattenIncidentWorkflowTrigger(d, updatedWorkflowTrigger)
err = flattenIncidentWorkflowTrigger(d, updatedWorkflowTrigger)
if err != nil {
return retry.NonRetryableError(err)
}

return nil
})
if err != nil {
return diag.FromErr(err)
}

return nil
}

Expand All @@ -142,6 +166,9 @@ func resourcePagerDutyIncidentWorkflowTriggerDelete(ctx context.Context, d *sche

_, err = client.IncidentWorkflowTriggers.DeleteContext(ctx, d.Id())
if err != nil {
if isErrCode(err, http.StatusNotFound) {
return diag.FromErr(handleNotFoundError(err, d))
}
return diag.FromErr(err)
}
return nil
Expand Down Expand Up @@ -209,7 +236,9 @@ func fetchIncidentWorkflowTrigger(ctx context.Context, d *schema.ResourceData, m
func flattenIncidentWorkflowTrigger(d *schema.ResourceData, t *pagerduty.IncidentWorkflowTrigger) error {
d.SetId(t.ID)
d.Set("type", t.TriggerType.String())
d.Set("workflow", t.Workflow.ID)
if t.Workflow != nil {
d.Set("workflow", t.Workflow.ID)
}
d.Set("services", flattenIncidentWorkflowEnabledServices(t.Services))
d.Set("subscribed_to_all_services", t.SubscribedToAllServices)
if t.Condition != nil {
Expand Down
Loading