diff --git a/builtin/providers/heroku/resource_heroku_drain.go b/builtin/providers/heroku/resource_heroku_drain.go index 9c1c8f46c..6bbab1e18 100644 --- a/builtin/providers/heroku/resource_heroku_drain.go +++ b/builtin/providers/heroku/resource_heroku_drain.go @@ -3,8 +3,11 @@ package heroku import ( "fmt" "log" + "strings" + "time" "github.com/cyberdelia/heroku-go/v3" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) @@ -35,6 +38,8 @@ func resourceHerokuDrain() *schema.Resource { } } +const retryableError = `App hasn't yet been assigned a log channel. Please try again momentarily.` + func resourceHerokuDrainCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*heroku.Service) @@ -43,7 +48,18 @@ func resourceHerokuDrainCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Drain create configuration: %#v, %#v", app, url) - dr, err := client.LogDrainCreate(app, heroku.LogDrainCreateOpts{url}) + var dr *heroku.LogDrain + err := resource.Retry(2*time.Minute, func() error { + d, err := client.LogDrainCreate(app, heroku.LogDrainCreateOpts{url}) + if err != nil { + if strings.Contains(err.Error(), retryableError) { + return err + } + return resource.RetryError{Err: err} + } + dr = d + return nil + }) if err != nil { return err }