diff --git a/pagerduty/provider.go b/pagerduty/provider.go index ab990153a..3da6629b4 100644 --- a/pagerduty/provider.go +++ b/pagerduty/provider.go @@ -92,6 +92,10 @@ func handleNotFoundError(err error, d *schema.ResourceData) error { return fmt.Errorf("Error reading: %s: %s", d.Id(), err) } +func handleError(err error, d *schema.ResourceData) error { + return fmt.Errorf("Error reading: %s: %s", d.Id(), err) +} + func providerConfigure(data *schema.ResourceData, terraformVersion string) (interface{}, error) { config := Config{ SkipCredsValidation: data.Get("skip_credentials_validation").(bool), diff --git a/pagerduty/resource_pagerduty_escalation_policy.go b/pagerduty/resource_pagerduty_escalation_policy.go index af56e9c23..e99d93b4e 100644 --- a/pagerduty/resource_pagerduty_escalation_policy.go +++ b/pagerduty/resource_pagerduty_escalation_policy.go @@ -118,14 +118,21 @@ func resourcePagerDutyEscalationPolicyCreate(d *schema.ResourceData, meta interf func resourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*pagerduty.Client) - log.Printf("[INFO] Reading PagerDuty escalation policy: %s", d.Id()) - o := &pagerduty.GetEscalationPolicyOptions{} + attempts := 0 return resource.Retry(2*time.Minute, func() *resource.RetryError { + attempts = attempts + 1 + + log.Printf("[INFO] Reading PagerDuty Escalation Policy %s. Attempt %s", d.Id(), attempts) escalationPolicy, _, err := client.EscalationPolicies.Get(d.Id(), o) if err != nil { - errResp := handleNotFoundError(err, d) + log.Printf("[WARN] Escalation Policy read error") + errResp := handleError(err, d) + if attempts > 6 { + errResp = handleNotFoundError(err, d) + } + if errResp != nil { time.Sleep(2 * time.Second) return resource.RetryableError(errResp) diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index b8dd71e7b..1ae1ea09d 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -296,13 +296,19 @@ func resourcePagerDutyServiceCreate(d *schema.ResourceData, meta interface{}) er func resourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*pagerduty.Client) - log.Printf("[INFO] Reading PagerDuty service %s", d.Id()) - + attempts := 0 return resource.Retry(2*time.Minute, func() *resource.RetryError { + attempts = attempts + 1 + + log.Printf("[INFO] Reading PagerDuty Service %s. Attempt %s", d.Id(), attempts) service, _, err := client.Services.Get(d.Id(), &pagerduty.GetServiceOptions{}) if err != nil { log.Printf("[WARN] Service read error") - errResp := handleNotFoundError(err, d) + errResp := handleError(err, d) + if attempts > 6 { + errResp = handleNotFoundError(err, d) + } + if errResp != nil { time.Sleep(2 * time.Second) return resource.RetryableError(errResp)