Skip to content

Commit

Permalink
Add error predicates to all Terraform template sendRequest calls (#5221)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and emilymye committed Dec 18, 2019
1 parent 5cd3040 commit 07b5fe1
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions google/resource_app_engine_application_url_dispatch_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func resourceAppEngineApplicationUrlDispatchRulesRead(d *schema.ResourceData, me
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, isAppEngineRetryableError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("AppEngineApplicationUrlDispatchRules %q", d.Id()))
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func resourceAppEngineApplicationUrlDispatchRulesUpdate(d *schema.ResourceData,
}

log.Printf("[DEBUG] Updating ApplicationUrlDispatchRules %q: %#v", d.Id(), obj)
res, err := sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
res, err := sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate), isAppEngineRetryableError)

if err != nil {
return fmt.Errorf("Error updating ApplicationUrlDispatchRules %q: %s", d.Id(), err)
Expand Down Expand Up @@ -231,7 +231,7 @@ func resourceAppEngineApplicationUrlDispatchRulesDelete(d *schema.ResourceData,
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting ApplicationUrlDispatchRules %q", d.Id())

res, err := sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutDelete), isAppEngineRetryableError)
if err != nil {
return handleNotFoundError(err, d, "ApplicationUrlDispatchRules")
}
Expand Down
4 changes: 2 additions & 2 deletions google/resource_app_engine_standard_app_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func resourceAppEngineStandardAppVersionRead(d *schema.ResourceData, meta interf
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, isAppEngineRetryableError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("AppEngineStandardAppVersion %q", d.Id()))
}
Expand Down Expand Up @@ -546,7 +546,7 @@ func resourceAppEngineStandardAppVersionUpdate(d *schema.ResourceData, meta inte
}

log.Printf("[DEBUG] Updating StandardAppVersion %q: %#v", d.Id(), obj)
res, err := sendRequestWithTimeout(config, "POST", project, url, obj, d.Timeout(schema.TimeoutUpdate))
res, err := sendRequestWithTimeout(config, "POST", project, url, obj, d.Timeout(schema.TimeoutUpdate), isAppEngineRetryableError)

if err != nil {
return fmt.Errorf("Error updating StandardAppVersion %q: %s", d.Id(), err)
Expand Down
6 changes: 3 additions & 3 deletions google/resource_bigquery_data_transfer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func resourceBigqueryDataTransferConfigRead(d *schema.ResourceData, meta interfa
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, iamMemberMissing)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("BigqueryDataTransferConfig %q", d.Id()))
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter
if err != nil {
return err
}
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate), iamMemberMissing)

if err != nil {
return fmt.Errorf("Error updating Config %q: %s", d.Id(), err)
Expand All @@ -347,7 +347,7 @@ func resourceBigqueryDataTransferConfigDelete(d *schema.ResourceData, meta inter
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting Config %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete), iamMemberMissing)
if err != nil {
return handleNotFoundError(err, d, "Config")
}
Expand Down
6 changes: 3 additions & 3 deletions google/resource_monitoring_alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func resourceMonitoringAlertPolicyRead(d *schema.ResourceData, meta interface{})
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("MonitoringAlertPolicy %q", d.Id()))
}
Expand Down Expand Up @@ -961,7 +961,7 @@ func resourceMonitoringAlertPolicyUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate), isMonitoringRetryableError)

if err != nil {
return fmt.Errorf("Error updating AlertPolicy %q: %s", d.Id(), err)
Expand Down Expand Up @@ -993,7 +993,7 @@ func resourceMonitoringAlertPolicyDelete(d *schema.ResourceData, meta interface{
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting AlertPolicy %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete), isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, "AlertPolicy")
}
Expand Down
6 changes: 3 additions & 3 deletions google/resource_monitoring_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func resourceMonitoringGroupRead(d *schema.ResourceData, meta interface{}) error
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("MonitoringGroup %q", d.Id()))
}
Expand Down Expand Up @@ -242,7 +242,7 @@ func resourceMonitoringGroupUpdate(d *schema.ResourceData, meta interface{}) err
}

log.Printf("[DEBUG] Updating Group %q: %#v", d.Id(), obj)
_, err = sendRequestWithTimeout(config, "PUT", project, url, obj, d.Timeout(schema.TimeoutUpdate))
_, err = sendRequestWithTimeout(config, "PUT", project, url, obj, d.Timeout(schema.TimeoutUpdate), isMonitoringRetryableError)

if err != nil {
return fmt.Errorf("Error updating Group %q: %s", d.Id(), err)
Expand Down Expand Up @@ -274,7 +274,7 @@ func resourceMonitoringGroupDelete(d *schema.ResourceData, meta interface{}) err
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting Group %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete), isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, "Group")
}
Expand Down
2 changes: 1 addition & 1 deletion google/resource_monitoring_group_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func testAccCheckMonitoringGroupDestroy(s *terraform.State) error {
return err
}

_, err = sendRequest(config, "GET", "", url, nil)
_, err = sendRequest(config, "GET", "", url, nil, isMonitoringRetryableError)
if err == nil {
return fmt.Errorf("MonitoringGroup still exists at %s", url)
}
Expand Down
6 changes: 3 additions & 3 deletions google/resource_monitoring_notification_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func resourceMonitoringNotificationChannelRead(d *schema.ResourceData, meta inte
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("MonitoringNotificationChannel %q", d.Id()))
}
Expand Down Expand Up @@ -299,7 +299,7 @@ func resourceMonitoringNotificationChannelUpdate(d *schema.ResourceData, meta in
}

log.Printf("[DEBUG] Updating NotificationChannel %q: %#v", d.Id(), obj)
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate), isMonitoringRetryableError)

if err != nil {
return fmt.Errorf("Error updating NotificationChannel %q: %s", d.Id(), err)
Expand Down Expand Up @@ -331,7 +331,7 @@ func resourceMonitoringNotificationChannelDelete(d *schema.ResourceData, meta in
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting NotificationChannel %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete), isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, "NotificationChannel")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func testAccCheckMonitoringNotificationChannelDestroy(s *terraform.State) error
return err
}

_, err = sendRequest(config, "GET", "", url, nil)
_, err = sendRequest(config, "GET", "", url, nil, isMonitoringRetryableError)
if err == nil {
return fmt.Errorf("MonitoringNotificationChannel still exists at %s", url)
}
Expand Down
6 changes: 3 additions & 3 deletions google/resource_monitoring_uptime_check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func resourceMonitoringUptimeCheckConfigRead(d *schema.ResourceData, meta interf
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("MonitoringUptimeCheckConfig %q", d.Id()))
}
Expand Down Expand Up @@ -517,7 +517,7 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte
if err != nil {
return err
}
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate), isMonitoringRetryableError)

if err != nil {
return fmt.Errorf("Error updating UptimeCheckConfig %q: %s", d.Id(), err)
Expand All @@ -542,7 +542,7 @@ func resourceMonitoringUptimeCheckConfigDelete(d *schema.ResourceData, meta inte
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting UptimeCheckConfig %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete), isMonitoringRetryableError)
if err != nil {
return handleNotFoundError(err, d, "UptimeCheckConfig")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func testAccCheckMonitoringUptimeCheckConfigDestroy(s *terraform.State) error {
return err
}

_, err = sendRequest(config, "GET", "", url, nil)
_, err = sendRequest(config, "GET", "", url, nil, isMonitoringRetryableError)
if err == nil {
return fmt.Errorf("MonitoringUptimeCheckConfig still exists at %s", url)
}
Expand Down
6 changes: 3 additions & 3 deletions google/resource_pubsub_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func resourcePubsubTopicRead(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
res, err := sendRequest(config, "GET", project, url, nil)
res, err := sendRequest(config, "GET", project, url, nil, pubsubTopicProjectNotReady)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("PubsubTopic %q", d.Id()))
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func resourcePubsubTopicUpdate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate), pubsubTopicProjectNotReady)

if err != nil {
return fmt.Errorf("Error updating Topic %q: %s", d.Id(), err)
Expand All @@ -273,7 +273,7 @@ func resourcePubsubTopicDelete(d *schema.ResourceData, meta interface{}) error {
var obj map[string]interface{}
log.Printf("[DEBUG] Deleting Topic %q", d.Id())

res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete))
res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete), pubsubTopicProjectNotReady)
if err != nil {
return handleNotFoundError(err, d, "Topic")
}
Expand Down
2 changes: 1 addition & 1 deletion google/resource_pubsub_topic_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func testAccCheckPubsubTopicDestroy(s *terraform.State) error {
return err
}

_, err = sendRequest(config, "GET", "", url, nil)
_, err = sendRequest(config, "GET", "", url, nil, pubsubTopicProjectNotReady)
if err == nil {
return fmt.Errorf("PubsubTopic still exists at %s", url)
}
Expand Down
4 changes: 2 additions & 2 deletions google/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func isEmptyValue(v reflect.Value) bool {
return false
}

func sendRequest(config *Config, method, project, rawurl string, body map[string]interface{}) (map[string]interface{}, error) {
return sendRequestWithTimeout(config, method, project, rawurl, body, DefaultRequestTimeout)
func sendRequest(config *Config, method, project, rawurl string, body map[string]interface{}, errorRetryPredicates ...func(e error) (bool, string)) (map[string]interface{}, error) {
return sendRequestWithTimeout(config, method, project, rawurl, body, DefaultRequestTimeout, errorRetryPredicates...)
}

func sendRequestWithTimeout(config *Config, method, project, rawurl string, body map[string]interface{}, timeout time.Duration, errorRetryPredicates ...func(e error) (bool, string)) (map[string]interface{}, error) {
Expand Down

0 comments on commit 07b5fe1

Please sign in to comment.