Skip to content

Commit

Permalink
feat: include rexex on getafterput client
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF committed Nov 30, 2024
1 parent 20507eb commit e839466
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 15 deletions.
15 changes: 14 additions & 1 deletion internal/retry/retryable_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"regexp"
"strings"

"github.com/hashicorp/terraform-plugin-framework/attr"
Expand Down Expand Up @@ -575,7 +576,7 @@ func (v RetryValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
}
}

func (v RetryValue) GetErrorMessageRegex() []string {
func (v RetryValue) GetErrorMessages() []string {
if v.IsNull() {
return nil
}
Expand All @@ -589,6 +590,18 @@ func (v RetryValue) GetErrorMessageRegex() []string {
return res
}

func (v RetryValue) GetErrorMessagesRegex() []regexp.Regexp {
msgs := v.GetErrorMessages()
if msgs == nil {
return nil
}
res := make([]regexp.Regexp, len(msgs))
for i, msg := range msgs {
res[i] = *regexp.MustCompile(msg)
}
return res
}

func (v RetryValue) GetIntervalSeconds() int {
return v.getInt64AttrValue(intervalSecondsAttributeName)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/services/azapi_data_plane_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func (r *DataPlaneResource) CreateUpdate(ctx context.Context, plan tfsdk.Plan, s
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "azapi_data_plane_resource.CreateUpdate is using retry")
client = r.ProviderData.DataPlaneClient.WithRetry(bkof, regexps, nil, nil)
Expand Down Expand Up @@ -444,7 +444,7 @@ func (r *DataPlaneResource) CreateUpdate(ctx context.Context, plan tfsdk.Plan, s
backoff.WithMaxInterval(30*time.Second),
backoff.WithMaxElapsedTime(RetryGetAfterPut()),
),
nil,
model.Retry.GetErrorMessagesRegex(),
[]int{404},
[]func(d interface{}) bool{
func(d interface{}) bool {
Expand Down Expand Up @@ -505,7 +505,7 @@ func (r *DataPlaneResource) Read(ctx context.Context, request resource.ReadReque
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "azapi_data_plane_resource.Read is using retry")
client = r.ProviderData.DataPlaneClient.WithRetry(bkof, regexps, nil, nil)
Expand Down Expand Up @@ -597,7 +597,7 @@ func (r *DataPlaneResource) Delete(ctx context.Context, request resource.DeleteR
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "azapi_data_plane_resource.Delete is using retry")
client = r.ProviderData.DataPlaneClient.WithRetry(bkof, regexps, nil, nil)
Expand Down
8 changes: 4 additions & 4 deletions internal/services/azapi_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func (r *AzapiResource) CreateUpdate(ctx context.Context, requestPlan tfsdk.Plan
plan.Retry.GetMaxIntervalSeconds(),
plan.Retry.GetMultiplier(),
plan.Retry.GetRandomizationFactor(),
plan.Retry.GetErrorMessageRegex(),
plan.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "azapi_resource.CreateUpdate is using retry")
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
Expand Down Expand Up @@ -732,7 +732,7 @@ func (r *AzapiResource) CreateUpdate(ctx context.Context, requestPlan tfsdk.Plan
backoff.WithMaxInterval(30*time.Second),
backoff.WithMaxElapsedTime(RetryGetAfterPut()),
),
nil,
plan.Retry.GetErrorMessagesRegex(),
[]int{404},
[]func(d interface{}) bool{
func(d interface{}) bool {
Expand Down Expand Up @@ -813,7 +813,7 @@ func (r *AzapiResource) Read(ctx context.Context, request resource.ReadRequest,
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "azapi_resource.Read is using retry")
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
Expand Down Expand Up @@ -953,7 +953,7 @@ func (r *AzapiResource) Delete(ctx context.Context, request resource.DeleteReque
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "azapi_resource.Delete is using retry")
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/azapi_resource_action_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (r *ResourceActionDataSource) Read(ctx context.Context, request datasource.
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "data.azapi_resource_action.Read is using retry")
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/azapi_resource_action_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (r *ActionResource) Action(ctx context.Context, model ActionResourceModel,
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "azapi_resource_action.Read is using retry")
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/azapi_resource_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (r *AzapiResourceDataSource) Read(ctx context.Context, request datasource.R
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "data.azapi_resource.Read is using retry")
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion internal/services/azapi_resource_list_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (r *ResourceListDataSource) Read(ctx context.Context, request datasource.Re
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
tflog.Debug(ctx, "data.azapi_resource_list.Read is using retry")
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
Expand Down
4 changes: 2 additions & 2 deletions internal/services/azapi_update_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (r *AzapiUpdateResource) CreateUpdate(ctx context.Context, plan tfsdk.Plan,
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
}
Expand Down Expand Up @@ -458,7 +458,7 @@ func (r *AzapiUpdateResource) Read(ctx context.Context, request resource.ReadReq
model.Retry.GetMaxIntervalSeconds(),
model.Retry.GetMultiplier(),
model.Retry.GetRandomizationFactor(),
model.Retry.GetErrorMessageRegex(),
model.Retry.GetErrorMessages(),
)
client = r.ProviderData.ResourceClient.WithRetry(bkof, regexps, nil, nil)
}
Expand Down

0 comments on commit e839466

Please sign in to comment.