Skip to content

Commit

Permalink
feat(Variable): add retries to Variable creation (#247)
Browse files Browse the repository at this point in the history
Adds retries on the attempt to Create a Variable for resiliency.

Related to #157
  • Loading branch information
mitchnielsen authored Aug 22, 2024
1 parent b1d88a8 commit 7d75c2f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions internal/provider/resources/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"strings"

"github.com/avast/retry-go/v4"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
Expand All @@ -19,6 +20,7 @@ import (
"github.com/prefecthq/terraform-provider-prefect/internal/api"
"github.com/prefecthq/terraform-provider-prefect/internal/provider/customtypes"
"github.com/prefecthq/terraform-provider-prefect/internal/provider/helpers"
"github.com/prefecthq/terraform-provider-prefect/internal/utils"
)

var (
Expand Down Expand Up @@ -175,11 +177,17 @@ func (r *VariableResource) Create(ctx context.Context, req resource.CreateReques
return
}

variable, err := client.Create(ctx, api.VariableCreate{
Name: plan.Name.ValueString(),
Value: plan.Value.ValueString(),
Tags: tags,
})
variable, err := retry.DoWithData(
func() (*api.Variable, error) {
return client.Create(ctx, api.VariableCreate{
Name: plan.Name.ValueString(),
Value: plan.Value.ValueString(),
Tags: tags,
})
},
utils.DefaultRetryOptions...,
)

if err != nil {
resp.Diagnostics.Append(helpers.ResourceClientErrorDiagnostic("Variable", "create", err))

Expand Down

0 comments on commit 7d75c2f

Please sign in to comment.