From b537e5e9661a07144547e0a00b45231f2c0ca2c0 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 25 Jan 2016 09:55:44 -0600 Subject: [PATCH] provider/heroku: retry drain create until log channel is assigned Should fix the build error encountered here: https://travis-ci.org/hashicorp/terraform/builds/104548513 --- .../providers/heroku/resource_heroku_drain.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/builtin/providers/heroku/resource_heroku_drain.go b/builtin/providers/heroku/resource_heroku_drain.go index 9c1c8f46c89d..6bbab1e18fad 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 }