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

Add retry predicate for 400 pubsub error #4352

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
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
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