Skip to content

Commit

Permalink
added retry to Login() when API rate limit is exceeded Mongey#50
Browse files Browse the repository at this point in the history
  • Loading branch information
obrientimothya committed Nov 30, 2020
1 parent e3a6ed8 commit 51703c0
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions ccloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package ccloud

import (
"log"
"strings"
"time"

confluentcloud "github.com/cgroschupp/go-client-confluent-cloud/confluentcloud"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
Expand Down Expand Up @@ -35,12 +38,26 @@ func Provider() terraform.ResourceProvider {
}
}


func providerConfigure(d *schema.ResourceData) (interface{}, error) {
log.Printf("[INFO] Initializing ConfluentCloud client")
username := d.Get("username").(string)
password := d.Get("password").(string)
c := confluentcloud.NewClient(username, password)

return c, c.Login()
loginE := c.Login()

if loginE == nil {
return c, loginE
}

return c, resource.Retry(30*time.Minute, func() *resource.RetryError {
err := c.Login()

if strings.Contains(err.Error(), "Exceeded rate limit") {
log.Printf("[INFO] ConfluentCloud API rate limit exceeded, retrying.")
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
})
}

0 comments on commit 51703c0

Please sign in to comment.