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
This commit is contained in:
Paul Hinze 2016-01-25 09:55:44 -06:00
parent 5f8b0e8b89
commit b537e5e966
1 changed files with 17 additions and 1 deletions

View File

@ -3,8 +3,11 @@ package heroku
import ( import (
"fmt" "fmt"
"log" "log"
"strings"
"time"
"github.com/cyberdelia/heroku-go/v3" "github.com/cyberdelia/heroku-go/v3"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "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 { func resourceHerokuDrainCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service) 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) 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 { if err != nil {
return err return err
} }