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

provider/heroku: retry drain create until log channel is assigned #4823

Merged
merged 1 commit into from
Jan 25, 2016
Merged
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
18 changes: 17 additions & 1 deletion builtin/providers/heroku/resource_heroku_drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)

Expand All @@ -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
}
Expand Down