Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions internal/provider/connection/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ type filterRuleProperty struct {
}

type retryRule struct {
Count types.Int64 `tfsdk:"count"`
Interval types.Int64 `tfsdk:"interval"`
Strategy types.String `tfsdk:"strategy"`
Count types.Int64 `tfsdk:"count"`
Interval types.Int64 `tfsdk:"interval"`
Strategy types.String `tfsdk:"strategy"`
ResponseStatusCodes types.List `tfsdk:"response_status_codes"`
}

type transformRule struct {
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/connection/schema_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func schemaAttributesV1() map[string]schema.Attribute {
MarkdownDescription: `must be one of ["linear", "exponential"]` + "\n" +
`Algorithm to use when calculating delay between retries`,
},
"response_status_codes": schema.ListAttribute{
Optional: true,
ElementType: types.StringType,
Description: `HTTP codes to retry on. Accepts: range expressions (e.g., "400-499", ">400"), specific codes (e.g., 404), and exclusions (e.g., "!401"). Example: ["500-599", ">400", 404, "!401"]`,
},
},
},
"transform_rule": schema.SingleNestedAttribute{
Expand Down
22 changes: 22 additions & 0 deletions internal/provider/connection/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,15 @@ func rulesToAPI(ctx context.Context, rules []rule) ([]interface{}, error) {
rule["interval"] = ruleItem.RetryRule.Interval.ValueInt64()
}

responseStatusCodesFieldsSet := !ruleItem.RetryRule.ResponseStatusCodes.IsNull() && !ruleItem.RetryRule.ResponseStatusCodes.IsUnknown()
if responseStatusCodesFieldsSet {
responseStatusCodes := []string{}
ruleItem.RetryRule.ResponseStatusCodes.ElementsAs(ctx, &responseStatusCodes, false)
if len(responseStatusCodes) > 0 {
rule["response_status_codes"] = responseStatusCodes
}
}

result = append(result, rule)
}

Expand Down Expand Up @@ -554,6 +563,19 @@ func rulesFromAPI(rules []interface{}) []rule {
} else {
retryRule.Interval = types.Int64Null()
}
if responseStatusCodes, ok := ruleMap["response_status_codes"].([]interface{}); ok {
statusCodeExpressions := []types.String{}
for _, expression := range responseStatusCodes {
if expressionStr, ok := expression.(string); ok {
statusCodeExpressions = append(statusCodeExpressions, types.StringValue(expressionStr))
}
}
if len(statusCodeExpressions) > 0 {
retryRule.ResponseStatusCodes, _ = types.ListValueFrom(context.Background(), types.StringType, statusCodeExpressions)
} else {
retryRule.ResponseStatusCodes = types.ListNull(types.StringType)
}
}

result = append(result, rule{RetryRule: retryRule})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "hookdeck_source" "test_%[1]s" {
name = "test-source-%[1]s"
}

resource "hookdeck_destination" "test_%[1]s" {
name = "test-destination-%[1]s"
config = jsonencode({
url = "https://mock.hookdeck.com"
})
}

resource "hookdeck_connection" "test_%[1]s" {
name = "test-connection-retry-%[1]s"
source_id = hookdeck_source.test_%[1]s.id
destination_id = hookdeck_destination.test_%[1]s.id

rules = [
{
retry_rule = {
strategy = "exponential"
count = 5
interval = 1000
response_status_codes = ["500-599"]
}
}
]
}