Skip to content

Commit

Permalink
Add retry predicate for 400 pubsub error (#4352)
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 Aug 28, 2019
1 parent 1dc8e3b commit 86a49ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions google/error_retry_predicates.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package google

import (
"strings"

"google.golang.org/api/googleapi"
"log"
"strings"
)

// If a permission necessary to provision a resource is created in the same config
Expand All @@ -17,3 +17,16 @@ func iamMemberMissing(err error) (bool, string) {
}
return false, ""
}

// Cloud PubSub returns a 400 error if a topic's parent project was recently created and an
// organization policy has not propagated.
// See https://github.com/terraform-providers/terraform-provider-google/issues/4349
func pubsubTopicProjectNotReady(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok {
if gerr.Code == 400 && strings.Contains(gerr.Body, "retry this operation") {
log.Printf("[DEBUG] Dismissed error as a retryable operation: %s", err)
return true, "Waiting for Pubsub topic's project to properly initialize with organiation policy"
}
}
return false, ""
}
2 changes: 1 addition & 1 deletion google/resource_pubsub_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func resourcePubsubTopicCreate(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
res, err := sendRequestWithTimeout(config, "PUT", project, url, obj, d.Timeout(schema.TimeoutCreate))
res, err := sendRequestWithTimeout(config, "PUT", project, url, obj, d.Timeout(schema.TimeoutCreate), pubsubTopicProjectNotReady)
if err != nil {
return fmt.Errorf("Error creating Topic: %s", err)
}
Expand Down

0 comments on commit 86a49ee

Please sign in to comment.