Skip to content

Commit

Permalink
[opendistro tenant] Retry to avoid conflicts.
Browse files Browse the repository at this point in the history
Closes #206
  • Loading branch information
phillbaker committed Aug 9, 2021
1 parent aecc92d commit 807047b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions es/resource_elasticsearch_opendistro_kibana_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"errors"
"fmt"
"log"
"net/http"
"regexp"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/olivere/elastic/uritemplates"
Expand Down Expand Up @@ -124,8 +126,12 @@ func resourceElasticsearchOpenDistroKibanaTenantDelete(d *schema.ResourceData, m
switch client := esClient.(type) {
case *elastic7.Client:
_, err = client.PerformRequest(context.TODO(), elastic7.PerformRequestOptions{
Method: "DELETE",
Path: path,
Method: "DELETE",
Path: path,
RetryStatusCodes: []int{http.StatusConflict, http.StatusInternalServerError},
Retrier: elastic7.NewBackoffRetrier(
elastic7.NewExponentialBackoff(100*time.Millisecond, 30*time.Second),
),
})
default:
err = errors.New("Creating tenants requires elastic v7 client")
Expand Down Expand Up @@ -205,9 +211,13 @@ func resourceElasticsearchPutOpenDistroKibanaTenant(d *schema.ResourceData, m in
case *elastic7.Client:
var res *elastic7.Response
res, err = client.PerformRequest(context.TODO(), elastic7.PerformRequestOptions{
Method: "PUT",
Path: path,
Body: string(tenantJSON),
Method: "PUT",
Path: path,
Body: string(tenantJSON),
RetryStatusCodes: []int{http.StatusConflict, http.StatusInternalServerError},
Retrier: elastic7.NewBackoffRetrier(
elastic7.NewExponentialBackoff(100*time.Millisecond, 30*time.Second),
),
})
body = res.Body
default:
Expand Down

0 comments on commit 807047b

Please sign in to comment.