Skip to content

Commit a917411

Browse files
dineshpandaclaude
andauthored
Fix: allow deleting alert_source_urgency_rules_attributes on rootly_alerts_source (#360)
The alert_source_urgency_rules_attributes attribute was declared Optional+Computed. For optional+computed attributes, removing the block from config makes Terraform reuse the prior state value instead of planning it to empty, so HasChange never fired and the deletion was never sent to the API. The backend supports full deletion via an empty list (it destroys all existing rules whenever the key is present) — the provider just wasn't sending it. Unlike alert_source_fields_attributes, urgency rules are never auto-created server-side, so Computed was both unnecessary and the cause of the bug. Removing Computed lets Terraform detect block removal and send an empty list, which clears the rules. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4fd9cdb commit a917411

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

provider/resource_alerts_source.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ func resourceAlertsSource() *schema.Resource {
175175

176176
"alert_source_urgency_rules_attributes": &schema.Schema{
177177
Type: schema.TypeList,
178-
Computed: true,
179178
Required: false,
180179
Optional: true,
181180
Sensitive: false,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package provider
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
)
10+
11+
func TestAccResourceAlertsSource_UrgencyRulesDeletion(t *testing.T) {
12+
rName := acctest.RandomWithPrefix("tf-alert-source")
13+
14+
resource.UnitTest(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProviderFactories: providerFactories,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccResourceAlertsSourceWithUrgencyRule(rName),
20+
Check: resource.ComposeTestCheckFunc(
21+
resource.TestCheckResourceAttr("rootly_alerts_source.test", "name", rName),
22+
resource.TestCheckResourceAttr("rootly_alerts_source.test", "alert_source_urgency_rules_attributes.#", "1"),
23+
resource.TestCheckResourceAttr("rootly_alerts_source.test", "alert_source_urgency_rules_attributes.0.json_path", "$.severity"),
24+
),
25+
},
26+
{
27+
Config: testAccResourceAlertsSourceWithoutUrgencyRule(rName),
28+
Check: resource.ComposeTestCheckFunc(
29+
resource.TestCheckResourceAttr("rootly_alerts_source.test", "name", rName),
30+
resource.TestCheckResourceAttr("rootly_alerts_source.test", "alert_source_urgency_rules_attributes.#", "0"),
31+
),
32+
},
33+
},
34+
})
35+
}
36+
37+
func testAccResourceAlertsSourceWithUrgencyRule(name string) string {
38+
return fmt.Sprintf(`
39+
resource "rootly_alert_urgency" "test" {
40+
name = "%[1]s-urgency"
41+
description = "Test urgency"
42+
}
43+
44+
resource "rootly_alerts_source" "test" {
45+
name = "%[1]s"
46+
source_type = "generic_webhook"
47+
48+
alert_source_urgency_rules_attributes {
49+
json_path = "$.severity"
50+
operator = "is"
51+
value = "critical"
52+
kind = "payload"
53+
alert_urgency_id = rootly_alert_urgency.test.id
54+
}
55+
}
56+
`, name)
57+
}
58+
59+
func testAccResourceAlertsSourceWithoutUrgencyRule(name string) string {
60+
return fmt.Sprintf(`
61+
resource "rootly_alert_urgency" "test" {
62+
name = "%[1]s-urgency"
63+
description = "Test urgency"
64+
}
65+
66+
resource "rootly_alerts_source" "test" {
67+
name = "%[1]s"
68+
source_type = "generic_webhook"
69+
}
70+
`, name)
71+
}

0 commit comments

Comments
 (0)