Skip to content

Commit 7498c3a

Browse files
authored
Allow to set the retry setting in all webhooks (#665)
* Allow to set the retry setting in all webhooks * use optional bool
1 parent 12c143b commit 7498c3a

20 files changed

+178
-89
lines changed

docs/data-sources/named_webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ description: |-
2626
- `id` (String) The ID of this resource.
2727
- `labels` (Set of String) labels for the webhook to use when referring in policies or filtering them
2828
- `name` (String) the name for the webhook which will also be used to generate the id
29+
- `retry_on_failure` (Boolean) whether to retry the webhook in case of failure
2930
- `secret_header_keys` (Set of String) secret header keys which are currently set for this webhook
3031
- `space_id` (String) ID of the space the webhook is in

docs/data-sources/webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ data "spacelift_webhook" "webhook" {
3535
- `enabled` (Boolean) enables or disables sending webhooks
3636
- `endpoint` (String) endpoint to send the POST request to
3737
- `id` (String) The ID of this resource.
38+
- `retry_on_failure` (Boolean) whether to retry the webhook in case of failure

docs/resources/audit_trail_webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ resource "spacelift_audit_trail_webhook" "example" {
3333

3434
- `custom_headers` (Map of String) `custom_headers` is a Map of key-value strings, that will be passed as headers with audit trail requests.
3535
- `include_runs` (Boolean) `include_runs` determines whether the webhook should include information about the run that triggered the event.
36+
- `retry_on_failure` (Boolean) whether to retry the webhook in case of failure. Defaults to `false`.
3637

3738
### Read-Only
3839

docs/resources/named_webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ description: |-
2525
### Optional
2626

2727
- `labels` (Set of String) labels for the webhook to use when referring in policies or filtering them
28+
- `retry_on_failure` (Boolean) whether to retry the webhook in case of failure. Defaults to `false`.
2829
- `secret` (String, Sensitive) secret used to sign each request so you're able to verify that the request comes from us. Defaults to an empty value. Note that once it's created, it will be just an empty string in the state due to security reasons.
2930

3031
### Read-Only

docs/resources/webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ resource "spacelift_webhook" "webhook" {
3030

3131
- `enabled` (Boolean) enables or disables sending webhooks. Defaults to `true`.
3232
- `module_id` (String) ID of the module which triggers the webhooks
33+
- `retry_on_failure` (Boolean) whether to retry the webhook in case of failure. Defaults to `false`.
3334
- `secret` (String, Sensitive) secret used to sign each POST request so you're able to verify that the request comes from us. Defaults to an empty value. Note that once it's created, it will be just an empty string in the state due to security reasons.
3435
- `stack_id` (String) ID of the stack which triggers the webhooks
3536

spacelift/data_named_webhook.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func dataNamedWebhook() *schema.Resource {
6363
Required: true,
6464
ValidateDiagFunc: validations.DisallowEmptyString,
6565
},
66+
"retry_on_failure": {
67+
Type: schema.TypeBool,
68+
Description: "whether to retry the webhook in case of failure",
69+
Computed: true,
70+
},
6671
},
6772
}
6873
}
@@ -88,6 +93,7 @@ func dataNamedWebhookRead(ctx context.Context, d *schema.ResourceData, meta inte
8893
d.Set("endpoint", wh.Endpoint)
8994
d.Set("enabled", wh.Enabled)
9095
d.Set("space_id", wh.Space.ID)
96+
d.Set("retry_on_failure", wh.RetryOnFailure)
9197

9298
labels := schema.NewSet(schema.HashString, []interface{}{})
9399
for _, label := range wh.Labels {

spacelift/data_named_webhook_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ func TestNamedWebhookData(t *testing.T) {
1515
testSteps(t, []resource.TestStep{{
1616
Config: fmt.Sprintf(`
1717
resource "spacelift_named_webhook" "test" {
18-
endpoint = "https://bacon.org"
19-
space_id = "root"
20-
name = "%s"
21-
labels = ["1", "2"]
22-
secret = "super-secret"
23-
enabled = true
18+
endpoint = "https://bacon.org"
19+
space_id = "root"
20+
name = "%s"
21+
labels = ["1", "2"]
22+
secret = "super-secret"
23+
enabled = true
24+
retry_on_failure = false
2425
}
2526
2627
resource "spacelift_named_webhook_secret_header" "test-secret" {

spacelift/data_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func dataWebhook() *schema.Resource {
4747
Required: true,
4848
ValidateDiagFunc: validations.DisallowEmptyString,
4949
},
50+
"retry_on_failure": {
51+
Type: schema.TypeBool,
52+
Description: "whether to retry the webhook in case of failure",
53+
Computed: true,
54+
},
5055
},
5156
}
5257
}
@@ -91,6 +96,7 @@ func dataModuleWebhookRead(ctx context.Context, d *schema.ResourceData, meta int
9196
d.SetId(webhookID)
9297
d.Set("enabled", module.Integrations.Webhooks[webhookIndex].Enabled)
9398
d.Set("endpoint", module.Integrations.Webhooks[webhookIndex].Endpoint)
99+
d.Set("retry_on_failure", module.Integrations.Webhooks[webhookIndex].RetryOnFailure)
94100

95101
return nil
96102
}
@@ -126,6 +132,7 @@ func dataStackWebhookRead(ctx context.Context, d *schema.ResourceData, meta inte
126132
d.SetId(webhookID)
127133
d.Set("enabled", stack.Integrations.Webhooks[webhookIndex].Enabled)
128134
d.Set("endpoint", stack.Integrations.Webhooks[webhookIndex].Endpoint)
135+
d.Set("retry_on_failure", stack.Integrations.Webhooks[webhookIndex].RetryOnFailure)
129136

130137
return nil
131138
}

spacelift/data_webhook_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ func TestWebhookData(t *testing.T) {
2323
}
2424
2525
resource "spacelift_webhook" "test" {
26-
stack_id = spacelift_stack.test.id
27-
endpoint = "https://bacon.org"
28-
secret = "very-very-secret"
26+
stack_id = spacelift_stack.test.id
27+
endpoint = "https://bacon.org"
28+
secret = "very-very-secret"
29+
retry_on_failure = false
2930
}
3031
3132
data "spacelift_webhook" "test" {
@@ -56,9 +57,10 @@ func TestWebhookData(t *testing.T) {
5657
}
5758
5859
resource "spacelift_webhook" "test" {
59-
module_id = spacelift_module.test.id
60-
endpoint = "https://bacon.org"
61-
secret = "very-very-secret"
60+
module_id = spacelift_module.test.id
61+
endpoint = "https://bacon.org"
62+
secret = "very-very-secret"
63+
retry_on_failure = false
6264
}
6365
6466
data "spacelift_webhook" "test" {

spacelift/internal/structs/audit_trail_webhook.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ type AuditTrailWebhook struct {
77
}
88

99
type AuditTrailWebhookRead struct {
10-
Enabled bool `graphql:"enabled"`
11-
Endpoint string `graphql:"endpoint"`
12-
IncludeRuns bool `graphql:"includeRuns"`
13-
Secret string `graphql:"secret"`
10+
Enabled bool `graphql:"enabled"`
11+
Endpoint string `graphql:"endpoint"`
12+
IncludeRuns bool `graphql:"includeRuns"`
13+
Secret string `graphql:"secret"`
14+
RetryOnFailure *bool `graphql:"retryOnFailure"`
1415
}

0 commit comments

Comments
 (0)