From 1a3b52679153deecc6e4f787c05f80a06448ce63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wilczyn=CC=81ski?= Date: Fri, 10 Apr 2020 12:48:48 +0200 Subject: [PATCH 1/4] Implement retry logic to all PagerDuty read calls --- ...data_source_pagerduty_escalation_policy.go | 38 +++++++------ .../data_source_pagerduty_extension_schema.go | 40 ++++++++------ pagerduty/data_source_pagerduty_schedule.go | 38 +++++++------ pagerduty/data_source_pagerduty_service.go | 41 ++++++++------ pagerduty/data_source_pagerduty_team.go | 40 ++++++++------ pagerduty/data_source_pagerduty_user.go | 40 ++++++++------ pagerduty/data_source_pagerduty_vendor.go | 55 ++++++++++--------- pagerduty/resource_pagerduty_addon.go | 21 ++++--- .../resource_pagerduty_escalation_policy.go | 36 +++++++----- pagerduty/resource_pagerduty_event_rule.go | 52 ++++++++++-------- pagerduty/resource_pagerduty_extension.go | 42 ++++++++------ .../resource_pagerduty_maintenance_window.go | 29 ++++++---- pagerduty/resource_pagerduty_ruleset.go | 29 ++++++---- pagerduty/resource_pagerduty_ruleset_rule.go | 12 +--- pagerduty/resource_pagerduty_schedule.go | 6 +- pagerduty/resource_pagerduty_team.go | 15 +---- .../resource_pagerduty_team_membership.go | 33 ++++++----- pagerduty/resource_pagerduty_user.go | 47 +++++++++------- .../resource_pagerduty_user_contact_method.go | 35 +++++++----- ...source_pagerduty_user_notification_rule.go | 29 ++++++---- 20 files changed, 381 insertions(+), 297 deletions(-) diff --git a/pagerduty/data_source_pagerduty_escalation_policy.go b/pagerduty/data_source_pagerduty_escalation_policy.go index 902c4d3ef..8751394c9 100644 --- a/pagerduty/data_source_pagerduty_escalation_policy.go +++ b/pagerduty/data_source_pagerduty_escalation_policy.go @@ -3,7 +3,9 @@ package pagerduty import ( "fmt" "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -32,26 +34,30 @@ func dataSourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interf Query: searchName, } - resp, _, err := client.EscalationPolicies.List(o) - if err != nil { - return err - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.EscalationPolicies.List(o) + if err != nil { + return resource.RetryableError(err) + } - var found *pagerduty.EscalationPolicy + var found *pagerduty.EscalationPolicy - for _, policy := range resp.EscalationPolicies { - if policy.Name == searchName { - found = policy - break + for _, policy := range resp.EscalationPolicies { + if policy.Name == searchName { + found = policy + break + } } - } - if found == nil { - return fmt.Errorf("Unable to locate any escalation policy with the name: %s", searchName) - } + if found == nil { + return resource.NonRetryableError( + fmt.Errorf("Unable to locate any escalation policy with the name: %s", searchName), + ) + } - d.SetId(found.ID) - d.Set("name", found.Name) + d.SetId(found.ID) + d.Set("name", found.Name) - return nil + return nil + }) } diff --git a/pagerduty/data_source_pagerduty_extension_schema.go b/pagerduty/data_source_pagerduty_extension_schema.go index 2cede5ac4..b49add451 100644 --- a/pagerduty/data_source_pagerduty_extension_schema.go +++ b/pagerduty/data_source_pagerduty_extension_schema.go @@ -4,7 +4,9 @@ import ( "fmt" "log" "strings" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -33,27 +35,31 @@ func dataSourcePagerDutyExtensionSchemaRead(d *schema.ResourceData, meta interfa searchName := d.Get("name").(string) - resp, _, err := client.ExtensionSchemas.List(&pagerduty.ListExtensionSchemasOptions{Query: searchName}) - if err != nil { - return err - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.ExtensionSchemas.List(&pagerduty.ListExtensionSchemasOptions{Query: searchName}) + if err != nil { + return resource.RetryableError(err) + } - var found *pagerduty.ExtensionSchema + var found *pagerduty.ExtensionSchema - for _, schema := range resp.ExtensionSchemas { - if strings.EqualFold(schema.Label, searchName) { - found = schema - break + for _, schema := range resp.ExtensionSchemas { + if strings.EqualFold(schema.Label, searchName) { + found = schema + break + } } - } - if found == nil { - return fmt.Errorf("Unable to locate any extension schema with the name: %s", searchName) - } + if found == nil { + return resource.NonRetryableError( + fmt.Errorf("Unable to locate any extension schema with the name: %s", searchName), + ) + } - d.SetId(found.ID) - d.Set("name", found.Label) - d.Set("type", found.Type) + d.SetId(found.ID) + d.Set("name", found.Label) + d.Set("type", found.Type) - return nil + return nil + }) } diff --git a/pagerduty/data_source_pagerduty_schedule.go b/pagerduty/data_source_pagerduty_schedule.go index 35249bc7a..aaddf4f32 100644 --- a/pagerduty/data_source_pagerduty_schedule.go +++ b/pagerduty/data_source_pagerduty_schedule.go @@ -3,7 +3,9 @@ package pagerduty import ( "fmt" "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -32,26 +34,30 @@ func dataSourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) e Query: searchName, } - resp, _, err := client.Schedules.List(o) - if err != nil { - return err - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Schedules.List(o) + if err != nil { + return resource.NonRetryableError(err) + } - var found *pagerduty.Schedule + var found *pagerduty.Schedule - for _, schedule := range resp.Schedules { - if schedule.Name == searchName { - found = schedule - break + for _, schedule := range resp.Schedules { + if schedule.Name == searchName { + found = schedule + break + } } - } - if found == nil { - return fmt.Errorf("Unable to locate any schedule with the name: %s", searchName) - } + if found == nil { + return resource.RetryableError( + fmt.Errorf("Unable to locate any schedule with the name: %s", searchName), + ) + } - d.SetId(found.ID) - d.Set("name", found.Name) + d.SetId(found.ID) + d.Set("name", found.Name) - return nil + return nil + }) } diff --git a/pagerduty/data_source_pagerduty_service.go b/pagerduty/data_source_pagerduty_service.go index d22c4c4c4..dcbb491e1 100644 --- a/pagerduty/data_source_pagerduty_service.go +++ b/pagerduty/data_source_pagerduty_service.go @@ -2,9 +2,12 @@ package pagerduty import ( "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" - "log" ) func dataSourcePagerDutyService() *schema.Resource { @@ -31,26 +34,30 @@ func dataSourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) er Query: searchName, } - resp, _, err := client.Services.List(o) - if err != nil { - return err - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Services.List(o) + if err != nil { + return resource.RetryableError(err) + } - var found *pagerduty.Service + var found *pagerduty.Service - for _, service := range resp.Services { - if service.Name == searchName { - found = service - break + for _, service := range resp.Services { + if service.Name == searchName { + found = service + break + } } - } - if found == nil { - return fmt.Errorf("Unable to locate any service with the name: %s", searchName) - } + if found == nil { + return resource.RetryableError( + fmt.Errorf("Unable to locate any service with the name: %s", searchName), + ) + } - d.SetId(found.ID) - d.Set("name", found.Name) + d.SetId(found.ID) + d.Set("name", found.Name) - return nil + return nil + }) } diff --git a/pagerduty/data_source_pagerduty_team.go b/pagerduty/data_source_pagerduty_team.go index 1ba553457..e5839aefa 100644 --- a/pagerduty/data_source_pagerduty_team.go +++ b/pagerduty/data_source_pagerduty_team.go @@ -3,7 +3,9 @@ package pagerduty import ( "fmt" "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -37,27 +39,31 @@ func dataSourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error Query: searchTeam, } - resp, _, err := client.Teams.List(o) - if err != nil { - return err - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Teams.List(o) + if err != nil { + return resource.RetryableError(err) + } - var found *pagerduty.Team + var found *pagerduty.Team - for _, team := range resp.Teams { - if team.Name == searchTeam { - found = team - break + for _, team := range resp.Teams { + if team.Name == searchTeam { + found = team + break + } } - } - if found == nil { - return fmt.Errorf("Unable to locate any team with name: %s", searchTeam) - } + if found == nil { + return resource.NonRetryableError( + fmt.Errorf("Unable to locate any team with name: %s", searchTeam), + ) + } - d.SetId(found.ID) - d.Set("name", found.Name) - d.Set("description", found.Description) + d.SetId(found.ID) + d.Set("name", found.Name) + d.Set("description", found.Description) - return nil + return nil + }) } diff --git a/pagerduty/data_source_pagerduty_user.go b/pagerduty/data_source_pagerduty_user.go index f0c8d99e8..9733a8995 100644 --- a/pagerduty/data_source_pagerduty_user.go +++ b/pagerduty/data_source_pagerduty_user.go @@ -3,7 +3,9 @@ package pagerduty import ( "fmt" "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -36,27 +38,31 @@ func dataSourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error Query: searchEmail, } - resp, _, err := client.Users.List(o) - if err != nil { - return err - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Users.List(o) + if err != nil { + return resource.RetryableError(err) + } - var found *pagerduty.User + var found *pagerduty.User - for _, user := range resp.Users { - if user.Email == searchEmail { - found = user - break + for _, user := range resp.Users { + if user.Email == searchEmail { + found = user + break + } } - } - if found == nil { - return fmt.Errorf("Unable to locate any user with the email: %s", searchEmail) - } + if found == nil { + return resource.NonRetryableError( + fmt.Errorf("Unable to locate any user with the email: %s", searchEmail), + ) + } - d.SetId(found.ID) - d.Set("name", found.Name) - d.Set("email", found.Email) + d.SetId(found.ID) + d.Set("name", found.Name) + d.Set("email", found.Email) - return nil + return nil + }) } diff --git a/pagerduty/data_source_pagerduty_vendor.go b/pagerduty/data_source_pagerduty_vendor.go index bc442af00..5bea6de48 100644 --- a/pagerduty/data_source_pagerduty_vendor.go +++ b/pagerduty/data_source_pagerduty_vendor.go @@ -5,7 +5,9 @@ import ( "log" "regexp" "strings" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -42,39 +44,42 @@ func dataSourcePagerDutyVendorRead(d *schema.ResourceData, meta interface{}) err o := &pagerduty.ListVendorsOptions{ Query: searchName, } - - resp, _, err := client.Vendors.List(o) - if err != nil { - return err - } - - var found *pagerduty.Vendor - - for _, vendor := range resp.Vendors { - if strings.EqualFold(vendor.Name, searchName) { - found = vendor - break + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Vendors.List(o) + if err != nil { + return resource.RetryableError(err) } - } - // We didn't find an exact match, so let's fallback to partial matching. - if found == nil { - pr := regexp.MustCompile("(?i)" + searchName) + var found *pagerduty.Vendor + for _, vendor := range resp.Vendors { - if pr.MatchString(vendor.Name) { + if strings.EqualFold(vendor.Name, searchName) { found = vendor break } } - } - if found == nil { - return fmt.Errorf("Unable to locate any vendor with the name: %s", searchName) - } + // We didn't find an exact match, so let's fallback to partial matching. + if found == nil { + pr := regexp.MustCompile("(?i)" + searchName) + for _, vendor := range resp.Vendors { + if pr.MatchString(vendor.Name) { + found = vendor + break + } + } + } + + if found == nil { + return resource.NonRetryableError( + fmt.Errorf("Unable to locate any vendor with the name: %s", searchName), + ) + } - d.SetId(found.ID) - d.Set("name", found.Name) - d.Set("type", found.GenericServiceType) + d.SetId(found.ID) + d.Set("name", found.Name) + d.Set("type", found.GenericServiceType) - return nil + return nil + }) } diff --git a/pagerduty/resource_pagerduty_addon.go b/pagerduty/resource_pagerduty_addon.go index ddbbbfb67..dd43dd0ab 100644 --- a/pagerduty/resource_pagerduty_addon.go +++ b/pagerduty/resource_pagerduty_addon.go @@ -2,7 +2,9 @@ package pagerduty import ( "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -61,15 +63,20 @@ func resourcePagerDutyAddonRead(d *schema.ResourceData, meta interface{}) error log.Printf("[INFO] Reading PagerDuty add-on %s", d.Id()) - addon, _, err := client.Addons.Get(d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + addon, _, err := client.Addons.Get(d.Id()) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } - d.Set("name", addon.Name) - d.Set("src", addon.Src) + d.Set("name", addon.Name) + d.Set("src", addon.Src) - return nil + return nil + }) } func resourcePagerDutyAddonUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_escalation_policy.go b/pagerduty/resource_pagerduty_escalation_policy.go index 0241fe86b..ef4402e35 100644 --- a/pagerduty/resource_pagerduty_escalation_policy.go +++ b/pagerduty/resource_pagerduty_escalation_policy.go @@ -3,7 +3,9 @@ package pagerduty import ( "fmt" "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -120,24 +122,30 @@ func resourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interfac o := &pagerduty.GetEscalationPolicyOptions{} - escalationPolicy, _, err := client.EscalationPolicies.Get(d.Id(), o) - if err != nil { - return handleNotFoundError(err, d) - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + escalationPolicy, _, err := client.EscalationPolicies.Get(d.Id(), o) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + log.Printf("[WARN] Returning retryable error") + return resource.RetryableError(errResp) + } + } - d.Set("name", escalationPolicy.Name) - d.Set("description", escalationPolicy.Description) - d.Set("num_loops", escalationPolicy.NumLoops) + d.Set("name", escalationPolicy.Name) + d.Set("description", escalationPolicy.Description) + d.Set("num_loops", escalationPolicy.NumLoops) - if err := d.Set("teams", flattenTeams(escalationPolicy.Teams)); err != nil { - return fmt.Errorf("error setting teams: %s", err) - } + if err := d.Set("teams", flattenTeams(escalationPolicy.Teams)); err != nil { + return resource.NonRetryableError(fmt.Errorf("error setting teams: %s", err)) + } - if err := d.Set("rule", flattenEscalationRules(escalationPolicy.EscalationRules)); err != nil { - return err - } + if err := d.Set("rule", flattenEscalationRules(escalationPolicy.EscalationRules)); err != nil { + return resource.NonRetryableError(err) + } - return nil + return nil + }) } func resourcePagerDutyEscalationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_event_rule.go b/pagerduty/resource_pagerduty_event_rule.go index dc4914e61..1391759c6 100644 --- a/pagerduty/resource_pagerduty_event_rule.go +++ b/pagerduty/resource_pagerduty_event_rule.go @@ -2,7 +2,9 @@ package pagerduty import ( "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -76,32 +78,34 @@ func resourcePagerDutyEventRuleRead(d *schema.ResourceData, meta interface{}) er log.Printf("[INFO] Reading PagerDuty event rule: %s", d.Id()) - resp, _, err := client.EventRules.List() - if err != nil { - return err - } - var foundRule *pagerduty.EventRule - - for _, rule := range resp.EventRules { - log.Printf("[DEBUG] Resp rule.ID: %s", rule.ID) - if rule.ID == d.Id() { - foundRule = rule - break + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.EventRules.List() + if err != nil { + return resource.RetryableError(err) } - } - // check if eventRule not found - if foundRule == nil { - d.SetId("") + var foundRule *pagerduty.EventRule + + for _, rule := range resp.EventRules { + log.Printf("[DEBUG] Resp rule.ID: %s", rule.ID) + if rule.ID == d.Id() { + foundRule = rule + break + } + } + // check if eventRule not found + if foundRule == nil { + d.SetId("") + return nil + } + // if event rule is found set to ResourceData + d.Set("action_json", flattenSlice(foundRule.Actions)) + d.Set("condition_json", flattenSlice(foundRule.Condition)) + if foundRule.AdvancedCondition != nil { + d.Set("advanced_condition_json", flattenSlice(foundRule.AdvancedCondition)) + } + d.Set("catch_all", foundRule.CatchAll) return nil - } - // if event rule is found set to ResourceData - d.Set("action_json", flattenSlice(foundRule.Actions)) - d.Set("condition_json", flattenSlice(foundRule.Condition)) - if foundRule.AdvancedCondition != nil { - d.Set("advanced_condition_json", flattenSlice(foundRule.AdvancedCondition)) - } - d.Set("catch_all", foundRule.CatchAll) - return nil + }) } func resourcePagerDutyEventRuleUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*pagerduty.Client) diff --git a/pagerduty/resource_pagerduty_extension.go b/pagerduty/resource_pagerduty_extension.go index 656370c8e..56472f6be 100644 --- a/pagerduty/resource_pagerduty_extension.go +++ b/pagerduty/resource_pagerduty_extension.go @@ -2,10 +2,11 @@ package pagerduty import ( "encoding/json" - "log" - "fmt" + "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -102,25 +103,30 @@ func resourcePagerDutyExtensionRead(d *schema.ResourceData, meta interface{}) er log.Printf("[INFO] Reading PagerDuty extension %s", d.Id()) - extension, _, err := client.Extensions.Get(d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + extension, _, err := client.Extensions.Get(d.Id()) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } - d.Set("summary", extension.Summary) - d.Set("name", extension.Name) - d.Set("endpoint_url", extension.EndpointURL) - d.Set("html_url", extension.HTMLURL) - if err := d.Set("extension_objects", flattenExtensionObjects(extension.ExtensionObjects)); err != nil { - log.Printf("[WARN] error setting extension_objects: %s", err) - } - d.Set("extension_schema", extension.ExtensionSchema) + d.Set("summary", extension.Summary) + d.Set("name", extension.Name) + d.Set("endpoint_url", extension.EndpointURL) + d.Set("html_url", extension.HTMLURL) + if err := d.Set("extension_objects", flattenExtensionObjects(extension.ExtensionObjects)); err != nil { + log.Printf("[WARN] error setting extension_objects: %s", err) + } + d.Set("extension_schema", extension.ExtensionSchema) - if err := d.Set("config", flattenExtensionConfig(extension.Config)); err != nil { - log.Printf("[WARN] error setting extension config: %s", err) - } + if err := d.Set("config", flattenExtensionConfig(extension.Config)); err != nil { + log.Printf("[WARN] error setting extension config: %s", err) + } - return nil + return nil + }) } func resourcePagerDutyExtensionUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_maintenance_window.go b/pagerduty/resource_pagerduty_maintenance_window.go index 9d13d3586..8070702c6 100644 --- a/pagerduty/resource_pagerduty_maintenance_window.go +++ b/pagerduty/resource_pagerduty_maintenance_window.go @@ -2,7 +2,9 @@ package pagerduty import ( "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -82,20 +84,25 @@ func resourcePagerDutyMaintenanceWindowRead(d *schema.ResourceData, meta interfa log.Printf("[INFO] Reading PagerDuty maintenance window %s", d.Id()) - window, _, err := client.MaintenanceWindows.Get(d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + window, _, err := client.MaintenanceWindows.Get(d.Id()) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } - d.Set("description", window.Description) - d.Set("start_time", window.StartTime) - d.Set("end_time", window.EndTime) + d.Set("description", window.Description) + d.Set("start_time", window.StartTime) + d.Set("end_time", window.EndTime) - if err := d.Set("services", flattenServices(window.Services)); err != nil { - return err - } + if err := d.Set("services", flattenServices(window.Services)); err != nil { + return resource.NonRetryableError(err) + } - return nil + return nil + }) } func resourcePagerDutyMaintenanceWindowUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_ruleset.go b/pagerduty/resource_pagerduty_ruleset.go index 155c789c6..c36f6a6e2 100644 --- a/pagerduty/resource_pagerduty_ruleset.go +++ b/pagerduty/resource_pagerduty_ruleset.go @@ -131,20 +131,25 @@ func resourcePagerDutyRulesetRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[INFO] Reading PagerDuty ruleset: %s", d.Id()) - ruleset, _, err := client.Rulesets.Get(d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } - d.Set("name", ruleset.Name) - d.Set("type", ruleset.Type) + return resource.Retry(2*time.Minute, func() *resource.RetryError { + ruleset, _, err := client.Rulesets.Get(d.Id()) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } + d.Set("name", ruleset.Name) + d.Set("type", ruleset.Type) - // if ruleset is found set to ResourceData - if ruleset.Team != nil { - d.Set("team", flattenTeam(ruleset.Team)) - } - d.Set("routing_keys", ruleset.RoutingKeys) + // if ruleset is found set to ResourceData + if ruleset.Team != nil { + d.Set("team", flattenTeam(ruleset.Team)) + } + d.Set("routing_keys", ruleset.RoutingKeys) - return nil + return nil + }) } func resourcePagerDutyRulesetUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*pagerduty.Client) diff --git a/pagerduty/resource_pagerduty_ruleset_rule.go b/pagerduty/resource_pagerduty_ruleset_rule.go index 89d47229e..ed2159786 100644 --- a/pagerduty/resource_pagerduty_ruleset_rule.go +++ b/pagerduty/resource_pagerduty_ruleset_rule.go @@ -616,12 +616,9 @@ func resourcePagerDutyRulesetRuleRead(d *schema.ResourceData, meta interface{}) log.Printf("[INFO] Reading PagerDuty ruleset rule: %s", d.Id()) rulesetID := d.Get("ruleset").(string) - retryErr := resource.Retry(30*time.Second, func() *resource.RetryError { + return resource.Retry(30*time.Second, func() *resource.RetryError { if rule, _, err := client.Rulesets.GetRule(rulesetID, d.Id()); err != nil { - if isErrCode(err, 500) || isErrCode(err, 429) { - return resource.RetryableError(err) - } - return resource.NonRetryableError(err) + return resource.RetryableError(err) } else if rule != nil { d.Set("conditions", flattenConditions(rule.Conditions)) @@ -637,11 +634,6 @@ func resourcePagerDutyRulesetRuleRead(d *schema.ResourceData, meta interface{}) } return nil }) - if retryErr != nil { - time.Sleep(2 * time.Second) - return retryErr - } - return nil } func resourcePagerDutyRulesetRuleUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_schedule.go b/pagerduty/resource_pagerduty_schedule.go index c3cff238d..96f44e04f 100644 --- a/pagerduty/resource_pagerduty_schedule.go +++ b/pagerduty/resource_pagerduty_schedule.go @@ -171,11 +171,7 @@ func resourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) err retryErr := resource.Retry(30*time.Second, func() *resource.RetryError { if schedule, _, err := client.Schedules.Get(d.Id(), &pagerduty.GetScheduleOptions{}); err != nil { - if isErrCode(err, 500) || isErrCode(err, 503) || isErrCode(err, 429) { - return resource.RetryableError(err) - } - - return resource.NonRetryableError(err) + return resource.RetryableError(err) } else if schedule != nil { d.Set("name", schedule.Name) d.Set("time_zone", schedule.TimeZone) diff --git a/pagerduty/resource_pagerduty_team.go b/pagerduty/resource_pagerduty_team.go index dbef54e4c..73093ef48 100644 --- a/pagerduty/resource_pagerduty_team.go +++ b/pagerduty/resource_pagerduty_team.go @@ -71,13 +71,9 @@ func resourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] Reading PagerDuty team %s", d.Id()) - retryErr := resource.Retry(30*time.Second, func() *resource.RetryError { + return resource.Retry(30*time.Second, func() *resource.RetryError { if team, _, err := client.Teams.Get(d.Id()); err != nil { - if isErrCode(err, 500) || isErrCode(err, 403) { - return resource.RetryableError(err) - } - - return resource.NonRetryableError(err) + return resource.RetryableError(err) } else if team != nil { d.Set("name", team.Name) d.Set("description", team.Description) @@ -85,13 +81,6 @@ func resourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error { } return nil }) - - if retryErr != nil { - time.Sleep(2 * time.Second) - return retryErr - } - - return nil } func resourcePagerDutyTeamUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_team_membership.go b/pagerduty/resource_pagerduty_team_membership.go index bf0b90a2b..db8c10bfa 100644 --- a/pagerduty/resource_pagerduty_team_membership.go +++ b/pagerduty/resource_pagerduty_team_membership.go @@ -80,25 +80,30 @@ func resourcePagerDutyTeamMembershipRead(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Reading user: %s from team: %s", userID, teamID) - resp, _, err := client.Teams.GetMembers(teamID, &pagerduty.GetMembersOptions{}) - if err != nil { - return handleNotFoundError(err, d) - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Teams.GetMembers(teamID, &pagerduty.GetMembersOptions{}) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } - for _, member := range resp.Members { - if member.User.ID == userID { - d.Set("user_id", userID) - d.Set("team_id", teamID) - d.Set("role", member.Role) + for _, member := range resp.Members { + if member.User.ID == userID { + d.Set("user_id", userID) + d.Set("team_id", teamID) + d.Set("role", member.Role) - return nil + return nil + } } - } - log.Printf("[WARN] Removing %s since the user: %s is not a member of: %s", d.Id(), userID, teamID) - d.SetId("") + log.Printf("[WARN] Removing %s since the user: %s is not a member of: %s", d.Id(), userID, teamID) + d.SetId("") - return nil + return nil + }) } func resourcePagerDutyTeamMembershipUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_user.go b/pagerduty/resource_pagerduty_user.go index 4b3430ada..6e32e1c69 100644 --- a/pagerduty/resource_pagerduty_user.go +++ b/pagerduty/resource_pagerduty_user.go @@ -3,7 +3,9 @@ package pagerduty import ( "fmt" "log" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -137,28 +139,35 @@ func resourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] Reading PagerDuty user %s", d.Id()) - user, _, err := client.Users.Get(d.Id(), &pagerduty.GetUserOptions{}) - if err != nil { - return handleNotFoundError(err, d) - } + return resource.Retry(2*time.Minute, func() *resource.RetryError { + user, _, err := client.Users.Get(d.Id(), &pagerduty.GetUserOptions{}) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } - d.Set("name", user.Name) - d.Set("email", user.Email) - d.Set("time_zone", user.TimeZone) - d.Set("html_url", user.HTMLURL) - d.Set("color", user.Color) - d.Set("role", user.Role) - d.Set("avatar_url", user.AvatarURL) - d.Set("description", user.Description) - d.Set("job_title", user.JobTitle) - - if err := d.Set("teams", flattenTeams(user.Teams)); err != nil { - return fmt.Errorf("error setting teams: %s", err) - } + d.Set("name", user.Name) + d.Set("email", user.Email) + d.Set("time_zone", user.TimeZone) + d.Set("html_url", user.HTMLURL) + d.Set("color", user.Color) + d.Set("role", user.Role) + d.Set("avatar_url", user.AvatarURL) + d.Set("description", user.Description) + d.Set("job_title", user.JobTitle) + + if err := d.Set("teams", flattenTeams(user.Teams)); err != nil { + return resource.NonRetryableError( + fmt.Errorf("error setting teams: %s", err), + ) + } - d.Set("invitation_sent", user.InvitationSent) + d.Set("invitation_sent", user.InvitationSent) - return nil + return nil + }) } func resourcePagerDutyUserUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_user_contact_method.go b/pagerduty/resource_pagerduty_user_contact_method.go index e644d0ec6..a0bd4aa22 100644 --- a/pagerduty/resource_pagerduty_user_contact_method.go +++ b/pagerduty/resource_pagerduty_user_contact_method.go @@ -4,7 +4,9 @@ import ( "fmt" "log" "strings" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -112,20 +114,25 @@ func resourcePagerDutyUserContactMethodRead(d *schema.ResourceData, meta interfa userID := d.Get("user_id").(string) - resp, _, err := client.Users.GetContactMethod(userID, d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } - - d.Set("address", resp.Address) - d.Set("blacklisted", resp.BlackListed) - d.Set("country_code", resp.CountryCode) - d.Set("enabled", resp.Enabled) - d.Set("label", resp.Label) - d.Set("send_short_email", resp.SendShortEmail) - d.Set("type", resp.Type) - - return nil + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Users.GetContactMethod(userID, d.Id()) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } + + d.Set("address", resp.Address) + d.Set("blacklisted", resp.BlackListed) + d.Set("country_code", resp.CountryCode) + d.Set("enabled", resp.Enabled) + d.Set("label", resp.Label) + d.Set("send_short_email", resp.SendShortEmail) + d.Set("type", resp.Type) + + return nil + }) } func resourcePagerDutyUserContactMethodUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/pagerduty/resource_pagerduty_user_notification_rule.go b/pagerduty/resource_pagerduty_user_notification_rule.go index 6b1ab99e7..8d0bbab9d 100644 --- a/pagerduty/resource_pagerduty_user_notification_rule.go +++ b/pagerduty/resource_pagerduty_user_notification_rule.go @@ -4,7 +4,9 @@ import ( "fmt" "log" "strings" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" ) @@ -96,17 +98,22 @@ func resourcePagerDutyUserNotificationRuleRead(d *schema.ResourceData, meta inte userID := d.Get("user_id").(string) - resp, _, err := client.Users.GetNotificationRule(userID, d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } - - d.Set("type", resp.Type) - d.Set("urgency", resp.Urgency) - d.Set("start_delay_in_minutes", resp.StartDelayInMinutes) - d.Set("contact_method", flattenContactMethod(resp.ContactMethod)) - - return nil + return resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, _, err := client.Users.GetNotificationRule(userID, d.Id()) + if err != nil { + errResp := handleNotFoundError(err, d) + if errResp != nil { + return resource.RetryableError(errResp) + } + } + + d.Set("type", resp.Type) + d.Set("urgency", resp.Urgency) + d.Set("start_delay_in_minutes", resp.StartDelayInMinutes) + d.Set("contact_method", flattenContactMethod(resp.ContactMethod)) + + return nil + }) } func resourcePagerDutyUserNotificationRuleUpdate(d *schema.ResourceData, meta interface{}) error { From 9ef39040cb190b7bc00c087bbfb74dc3a1554853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wilczyn=CC=81ski?= Date: Thu, 16 Apr 2020 12:26:52 +0200 Subject: [PATCH 2/4] Fix error type in schedule data source --- pagerduty/data_source_pagerduty_schedule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pagerduty/data_source_pagerduty_schedule.go b/pagerduty/data_source_pagerduty_schedule.go index aaddf4f32..6613bd4e7 100644 --- a/pagerduty/data_source_pagerduty_schedule.go +++ b/pagerduty/data_source_pagerduty_schedule.go @@ -37,7 +37,7 @@ func dataSourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) e return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.Schedules.List(o) if err != nil { - return resource.NonRetryableError(err) + return resource.RetryableError(err) } var found *pagerduty.Schedule From 1d8dd323b9669f774df2cdf581017512afae06b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wilczyn=CC=81ski?= Date: Wed, 22 Apr 2020 10:31:11 +0200 Subject: [PATCH 3/4] Add early return in case of errors --- pagerduty/data_source_pagerduty_schedule.go | 2 +- pagerduty/data_source_pagerduty_service.go | 2 +- pagerduty/resource_pagerduty_addon.go | 2 ++ pagerduty/resource_pagerduty_escalation_policy.go | 2 ++ pagerduty/resource_pagerduty_extension.go | 2 ++ pagerduty/resource_pagerduty_maintenance_window.go | 2 ++ pagerduty/resource_pagerduty_ruleset.go | 2 ++ pagerduty/resource_pagerduty_service.go | 2 ++ pagerduty/resource_pagerduty_service_integration.go | 2 ++ pagerduty/resource_pagerduty_team_membership.go | 2 ++ pagerduty/resource_pagerduty_user.go | 2 ++ pagerduty/resource_pagerduty_user_contact_method.go | 2 ++ pagerduty/resource_pagerduty_user_notification_rule.go | 2 ++ 13 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pagerduty/data_source_pagerduty_schedule.go b/pagerduty/data_source_pagerduty_schedule.go index 6613bd4e7..6825b11d1 100644 --- a/pagerduty/data_source_pagerduty_schedule.go +++ b/pagerduty/data_source_pagerduty_schedule.go @@ -50,7 +50,7 @@ func dataSourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) e } if found == nil { - return resource.RetryableError( + return resource.NonRetryableError( fmt.Errorf("Unable to locate any schedule with the name: %s", searchName), ) } diff --git a/pagerduty/data_source_pagerduty_service.go b/pagerduty/data_source_pagerduty_service.go index dcbb491e1..1e5845a62 100644 --- a/pagerduty/data_source_pagerduty_service.go +++ b/pagerduty/data_source_pagerduty_service.go @@ -50,7 +50,7 @@ func dataSourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) er } if found == nil { - return resource.RetryableError( + return resource.NonRetryableError( fmt.Errorf("Unable to locate any service with the name: %s", searchName), ) } diff --git a/pagerduty/resource_pagerduty_addon.go b/pagerduty/resource_pagerduty_addon.go index dd43dd0ab..a2df10a6e 100644 --- a/pagerduty/resource_pagerduty_addon.go +++ b/pagerduty/resource_pagerduty_addon.go @@ -70,6 +70,8 @@ func resourcePagerDutyAddonRead(d *schema.ResourceData, meta interface{}) error if errResp != nil { return resource.RetryableError(errResp) } + + return nil } d.Set("name", addon.Name) diff --git a/pagerduty/resource_pagerduty_escalation_policy.go b/pagerduty/resource_pagerduty_escalation_policy.go index ef4402e35..9459e0443 100644 --- a/pagerduty/resource_pagerduty_escalation_policy.go +++ b/pagerduty/resource_pagerduty_escalation_policy.go @@ -130,6 +130,8 @@ func resourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interfac log.Printf("[WARN] Returning retryable error") return resource.RetryableError(errResp) } + + return nil } d.Set("name", escalationPolicy.Name) diff --git a/pagerduty/resource_pagerduty_extension.go b/pagerduty/resource_pagerduty_extension.go index 56472f6be..4ae346a03 100644 --- a/pagerduty/resource_pagerduty_extension.go +++ b/pagerduty/resource_pagerduty_extension.go @@ -110,6 +110,8 @@ func resourcePagerDutyExtensionRead(d *schema.ResourceData, meta interface{}) er if errResp != nil { return resource.RetryableError(errResp) } + + return nil } d.Set("summary", extension.Summary) diff --git a/pagerduty/resource_pagerduty_maintenance_window.go b/pagerduty/resource_pagerduty_maintenance_window.go index 8070702c6..fbbac5495 100644 --- a/pagerduty/resource_pagerduty_maintenance_window.go +++ b/pagerduty/resource_pagerduty_maintenance_window.go @@ -91,6 +91,8 @@ func resourcePagerDutyMaintenanceWindowRead(d *schema.ResourceData, meta interfa if errResp != nil { return resource.RetryableError(errResp) } + + return nil } d.Set("description", window.Description) diff --git a/pagerduty/resource_pagerduty_ruleset.go b/pagerduty/resource_pagerduty_ruleset.go index c36f6a6e2..16363d52d 100644 --- a/pagerduty/resource_pagerduty_ruleset.go +++ b/pagerduty/resource_pagerduty_ruleset.go @@ -138,6 +138,8 @@ func resourcePagerDutyRulesetRead(d *schema.ResourceData, meta interface{}) erro if errResp != nil { return resource.RetryableError(errResp) } + + return nil } d.Set("name", ruleset.Name) d.Set("type", ruleset.Type) diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index c02a8a884..05906c280 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -306,6 +306,8 @@ func resourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[WARN] Returning retryable error") return resource.RetryableError(errResp) } + + return nil } d.Set("name", service.Name) diff --git a/pagerduty/resource_pagerduty_service_integration.go b/pagerduty/resource_pagerduty_service_integration.go index 84c8cb480..7aeb09f1e 100644 --- a/pagerduty/resource_pagerduty_service_integration.go +++ b/pagerduty/resource_pagerduty_service_integration.go @@ -142,6 +142,8 @@ func resourcePagerDutyServiceIntegrationRead(d *schema.ResourceData, meta interf log.Printf("[WARN] Returning retryable error") return resource.RetryableError(errResp) } + + return nil } d.Set("name", serviceIntegration.Name) diff --git a/pagerduty/resource_pagerduty_team_membership.go b/pagerduty/resource_pagerduty_team_membership.go index db8c10bfa..b365acb3f 100644 --- a/pagerduty/resource_pagerduty_team_membership.go +++ b/pagerduty/resource_pagerduty_team_membership.go @@ -87,6 +87,8 @@ func resourcePagerDutyTeamMembershipRead(d *schema.ResourceData, meta interface{ if errResp != nil { return resource.RetryableError(errResp) } + + return nil } for _, member := range resp.Members { diff --git a/pagerduty/resource_pagerduty_user.go b/pagerduty/resource_pagerduty_user.go index 6e32e1c69..f19234281 100644 --- a/pagerduty/resource_pagerduty_user.go +++ b/pagerduty/resource_pagerduty_user.go @@ -146,6 +146,8 @@ func resourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error { if errResp != nil { return resource.RetryableError(errResp) } + + return nil } d.Set("name", user.Name) diff --git a/pagerduty/resource_pagerduty_user_contact_method.go b/pagerduty/resource_pagerduty_user_contact_method.go index a0bd4aa22..71f7da199 100644 --- a/pagerduty/resource_pagerduty_user_contact_method.go +++ b/pagerduty/resource_pagerduty_user_contact_method.go @@ -121,6 +121,8 @@ func resourcePagerDutyUserContactMethodRead(d *schema.ResourceData, meta interfa if errResp != nil { return resource.RetryableError(errResp) } + + return nil } d.Set("address", resp.Address) diff --git a/pagerduty/resource_pagerduty_user_notification_rule.go b/pagerduty/resource_pagerduty_user_notification_rule.go index 8d0bbab9d..d06e9ecd5 100644 --- a/pagerduty/resource_pagerduty_user_notification_rule.go +++ b/pagerduty/resource_pagerduty_user_notification_rule.go @@ -105,6 +105,8 @@ func resourcePagerDutyUserNotificationRuleRead(d *schema.ResourceData, meta inte if errResp != nil { return resource.RetryableError(errResp) } + + return nil } d.Set("type", resp.Type) From a60119189b77fcd0e45b0b42375508ca3a7891ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wilczyn=CC=81ski?= Date: Wed, 27 May 2020 11:08:31 +0200 Subject: [PATCH 4/4] Add delays before returning retryable errors --- pagerduty/data_source_pagerduty_escalation_policy.go | 1 + pagerduty/data_source_pagerduty_extension_schema.go | 1 + pagerduty/data_source_pagerduty_schedule.go | 1 + pagerduty/data_source_pagerduty_service.go | 1 + pagerduty/data_source_pagerduty_team.go | 1 + pagerduty/data_source_pagerduty_user.go | 1 + pagerduty/data_source_pagerduty_vendor.go | 1 + pagerduty/resource_pagerduty_addon.go | 1 + pagerduty/resource_pagerduty_escalation_policy.go | 2 +- pagerduty/resource_pagerduty_event_rule.go | 1 + pagerduty/resource_pagerduty_extension.go | 1 + pagerduty/resource_pagerduty_maintenance_window.go | 1 + pagerduty/resource_pagerduty_ruleset.go | 1 + pagerduty/resource_pagerduty_ruleset_rule.go | 1 + pagerduty/resource_pagerduty_schedule.go | 1 + pagerduty/resource_pagerduty_service.go | 2 +- pagerduty/resource_pagerduty_service_integration.go | 2 +- pagerduty/resource_pagerduty_team.go | 1 + pagerduty/resource_pagerduty_team_membership.go | 1 + pagerduty/resource_pagerduty_user.go | 1 + pagerduty/resource_pagerduty_user_contact_method.go | 1 + pagerduty/resource_pagerduty_user_notification_rule.go | 1 + 22 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pagerduty/data_source_pagerduty_escalation_policy.go b/pagerduty/data_source_pagerduty_escalation_policy.go index 8751394c9..86d78da8f 100644 --- a/pagerduty/data_source_pagerduty_escalation_policy.go +++ b/pagerduty/data_source_pagerduty_escalation_policy.go @@ -37,6 +37,7 @@ func dataSourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interf return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.EscalationPolicies.List(o) if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } diff --git a/pagerduty/data_source_pagerduty_extension_schema.go b/pagerduty/data_source_pagerduty_extension_schema.go index b49add451..58e70a2ec 100644 --- a/pagerduty/data_source_pagerduty_extension_schema.go +++ b/pagerduty/data_source_pagerduty_extension_schema.go @@ -38,6 +38,7 @@ func dataSourcePagerDutyExtensionSchemaRead(d *schema.ResourceData, meta interfa return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.ExtensionSchemas.List(&pagerduty.ListExtensionSchemasOptions{Query: searchName}) if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } diff --git a/pagerduty/data_source_pagerduty_schedule.go b/pagerduty/data_source_pagerduty_schedule.go index 6825b11d1..223d794dd 100644 --- a/pagerduty/data_source_pagerduty_schedule.go +++ b/pagerduty/data_source_pagerduty_schedule.go @@ -37,6 +37,7 @@ func dataSourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) e return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.Schedules.List(o) if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } diff --git a/pagerduty/data_source_pagerduty_service.go b/pagerduty/data_source_pagerduty_service.go index 1e5845a62..f7ec1f3ad 100644 --- a/pagerduty/data_source_pagerduty_service.go +++ b/pagerduty/data_source_pagerduty_service.go @@ -37,6 +37,7 @@ func dataSourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) er return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.Services.List(o) if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } diff --git a/pagerduty/data_source_pagerduty_team.go b/pagerduty/data_source_pagerduty_team.go index e5839aefa..3da9480b1 100644 --- a/pagerduty/data_source_pagerduty_team.go +++ b/pagerduty/data_source_pagerduty_team.go @@ -42,6 +42,7 @@ func dataSourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.Teams.List(o) if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } diff --git a/pagerduty/data_source_pagerduty_user.go b/pagerduty/data_source_pagerduty_user.go index 9733a8995..c1edb4a69 100644 --- a/pagerduty/data_source_pagerduty_user.go +++ b/pagerduty/data_source_pagerduty_user.go @@ -41,6 +41,7 @@ func dataSourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.Users.List(o) if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } diff --git a/pagerduty/data_source_pagerduty_vendor.go b/pagerduty/data_source_pagerduty_vendor.go index 5bea6de48..bb3316634 100644 --- a/pagerduty/data_source_pagerduty_vendor.go +++ b/pagerduty/data_source_pagerduty_vendor.go @@ -47,6 +47,7 @@ func dataSourcePagerDutyVendorRead(d *schema.ResourceData, meta interface{}) err return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.Vendors.List(o) if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } diff --git a/pagerduty/resource_pagerduty_addon.go b/pagerduty/resource_pagerduty_addon.go index a2df10a6e..fce4cbdab 100644 --- a/pagerduty/resource_pagerduty_addon.go +++ b/pagerduty/resource_pagerduty_addon.go @@ -68,6 +68,7 @@ func resourcePagerDutyAddonRead(d *schema.ResourceData, meta interface{}) error if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_escalation_policy.go b/pagerduty/resource_pagerduty_escalation_policy.go index 9459e0443..82b947016 100644 --- a/pagerduty/resource_pagerduty_escalation_policy.go +++ b/pagerduty/resource_pagerduty_escalation_policy.go @@ -127,7 +127,7 @@ func resourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interfac if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { - log.Printf("[WARN] Returning retryable error") + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_event_rule.go b/pagerduty/resource_pagerduty_event_rule.go index 1391759c6..520c15cac 100644 --- a/pagerduty/resource_pagerduty_event_rule.go +++ b/pagerduty/resource_pagerduty_event_rule.go @@ -81,6 +81,7 @@ func resourcePagerDutyEventRuleRead(d *schema.ResourceData, meta interface{}) er return resource.Retry(2*time.Minute, func() *resource.RetryError { resp, _, err := client.EventRules.List() if err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } var foundRule *pagerduty.EventRule diff --git a/pagerduty/resource_pagerduty_extension.go b/pagerduty/resource_pagerduty_extension.go index 4ae346a03..f4fd9df73 100644 --- a/pagerduty/resource_pagerduty_extension.go +++ b/pagerduty/resource_pagerduty_extension.go @@ -108,6 +108,7 @@ func resourcePagerDutyExtensionRead(d *schema.ResourceData, meta interface{}) er if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_maintenance_window.go b/pagerduty/resource_pagerduty_maintenance_window.go index fbbac5495..375a07a35 100644 --- a/pagerduty/resource_pagerduty_maintenance_window.go +++ b/pagerduty/resource_pagerduty_maintenance_window.go @@ -89,6 +89,7 @@ func resourcePagerDutyMaintenanceWindowRead(d *schema.ResourceData, meta interfa if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_ruleset.go b/pagerduty/resource_pagerduty_ruleset.go index 16363d52d..871784322 100644 --- a/pagerduty/resource_pagerduty_ruleset.go +++ b/pagerduty/resource_pagerduty_ruleset.go @@ -136,6 +136,7 @@ func resourcePagerDutyRulesetRead(d *schema.ResourceData, meta interface{}) erro if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_ruleset_rule.go b/pagerduty/resource_pagerduty_ruleset_rule.go index 4b9bad637..6736b8c67 100644 --- a/pagerduty/resource_pagerduty_ruleset_rule.go +++ b/pagerduty/resource_pagerduty_ruleset_rule.go @@ -623,6 +623,7 @@ func resourcePagerDutyRulesetRuleRead(d *schema.ResourceData, meta interface{}) return resource.Retry(30*time.Second, func() *resource.RetryError { if rule, _, err := client.Rulesets.GetRule(rulesetID, d.Id()); err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } else if rule != nil { if rule.Conditions != nil { diff --git a/pagerduty/resource_pagerduty_schedule.go b/pagerduty/resource_pagerduty_schedule.go index 96f44e04f..6014331c1 100644 --- a/pagerduty/resource_pagerduty_schedule.go +++ b/pagerduty/resource_pagerduty_schedule.go @@ -171,6 +171,7 @@ func resourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) err retryErr := resource.Retry(30*time.Second, func() *resource.RetryError { if schedule, _, err := client.Schedules.Get(d.Id(), &pagerduty.GetScheduleOptions{}); err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } else if schedule != nil { d.Set("name", schedule.Name) diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index 05906c280..add738b18 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -303,7 +303,7 @@ func resourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[WARN] Service read error") errResp := handleNotFoundError(err, d) if errResp != nil { - log.Printf("[WARN] Returning retryable error") + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_service_integration.go b/pagerduty/resource_pagerduty_service_integration.go index 06b0a83ab..27117a5ac 100644 --- a/pagerduty/resource_pagerduty_service_integration.go +++ b/pagerduty/resource_pagerduty_service_integration.go @@ -140,7 +140,7 @@ func resourcePagerDutyServiceIntegrationRead(d *schema.ResourceData, meta interf log.Printf("[WARN] Service integration read error") errResp := handleNotFoundError(err, d) if errResp != nil { - log.Printf("[WARN] Returning retryable error") + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_team.go b/pagerduty/resource_pagerduty_team.go index 73093ef48..53e4f6f53 100644 --- a/pagerduty/resource_pagerduty_team.go +++ b/pagerduty/resource_pagerduty_team.go @@ -73,6 +73,7 @@ func resourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error { return resource.Retry(30*time.Second, func() *resource.RetryError { if team, _, err := client.Teams.Get(d.Id()); err != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(err) } else if team != nil { d.Set("name", team.Name) diff --git a/pagerduty/resource_pagerduty_team_membership.go b/pagerduty/resource_pagerduty_team_membership.go index b365acb3f..193210e1b 100644 --- a/pagerduty/resource_pagerduty_team_membership.go +++ b/pagerduty/resource_pagerduty_team_membership.go @@ -85,6 +85,7 @@ func resourcePagerDutyTeamMembershipRead(d *schema.ResourceData, meta interface{ if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_user.go b/pagerduty/resource_pagerduty_user.go index f19234281..b28aea2e1 100644 --- a/pagerduty/resource_pagerduty_user.go +++ b/pagerduty/resource_pagerduty_user.go @@ -144,6 +144,7 @@ func resourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error { if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_user_contact_method.go b/pagerduty/resource_pagerduty_user_contact_method.go index 71f7da199..4263833ed 100644 --- a/pagerduty/resource_pagerduty_user_contact_method.go +++ b/pagerduty/resource_pagerduty_user_contact_method.go @@ -119,6 +119,7 @@ func resourcePagerDutyUserContactMethodRead(d *schema.ResourceData, meta interfa if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) } diff --git a/pagerduty/resource_pagerduty_user_notification_rule.go b/pagerduty/resource_pagerduty_user_notification_rule.go index d06e9ecd5..af6dd3866 100644 --- a/pagerduty/resource_pagerduty_user_notification_rule.go +++ b/pagerduty/resource_pagerduty_user_notification_rule.go @@ -103,6 +103,7 @@ func resourcePagerDutyUserNotificationRuleRead(d *schema.ResourceData, meta inte if err != nil { errResp := handleNotFoundError(err, d) if errResp != nil { + time.Sleep(10 * time.Second) return resource.RetryableError(errResp) }