Skip to content

Commit

Permalink
Trigger resource replace when Incident Workflow Trigger type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonw committed Nov 30, 2023
1 parent 179a846 commit 8259138
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions pagerduty/resource_pagerduty_incident_workflow_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func resourcePagerDutyIncidentWorkflowTrigger() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateDiagFunc: validateValueDiagFunc([]string{
"manual",
"conditional",
Expand Down
84 changes: 84 additions & 0 deletions pagerduty/resource_pagerduty_incident_workflow_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,41 @@ func TestAccPagerDutyIncidentWorkflowTrigger_BasicConditionalAllServices(t *test
})
}

func TestAccPagerDutyIncidentWorkflowTrigger_ChangeTypeCausesReplace(t *testing.T) {
workflow := fmt.Sprintf("tf-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckIncidentWorkflows(t)
},
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckPagerDutyIncidentWorkflowTriggerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigConditionalAllServices(workflow, "incident.priority matches 'P1'"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyIncidentWorkflowTriggerExists("pagerduty_incident_workflow_trigger.test"),
resource.TestCheckResourceAttr(
"pagerduty_incident_workflow_trigger.test", "type", "conditional"),
resource.TestCheckResourceAttr(
"pagerduty_incident_workflow_trigger.test", "condition", "incident.priority matches 'P1'"),
resource.TestCheckResourceAttr("pagerduty_incident_workflow_trigger.test", "subscribed_to_all_services", "true"),
),
},
{
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualAllServices(workflow),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyIncidentWorkflowTriggerExists("pagerduty_incident_workflow_trigger.test"),
resource.TestCheckResourceAttr(
"pagerduty_incident_workflow_trigger.test", "type", "manual"),
resource.TestCheckResourceAttr("pagerduty_incident_workflow_trigger.test", "subscribed_to_all_services", "true"),
),
},
},
})
}

func testAccCheckPagerDutyIncidentWorkflowTriggerConfigConditionalAllServices(workflow, condition string) string {
return fmt.Sprintf(`
%s
Expand All @@ -242,6 +277,55 @@ resource "pagerduty_incident_workflow_trigger" "test" {
`, testAccCheckPagerDutyIncidentWorkflowConfig(workflow), condition)
}

func testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualAllServices(workflow string) string {
return fmt.Sprintf(`
%s
resource "pagerduty_incident_workflow_trigger" "test" {
type = "manual"
workflow = pagerduty_incident_workflow.test.id
services = []
subscribed_to_all_services = true
}
`, testAccCheckPagerDutyIncidentWorkflowConfig(workflow))
}

func TestAccPagerDutyIncidentWorkflowTrigger_CannotChangeType(t *testing.T) {
workflow := fmt.Sprintf("tf-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckIncidentWorkflows(t)
},
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckPagerDutyIncidentWorkflowTriggerDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigConditionalAllServices(workflow, "incident.priority matches 'P1'"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyIncidentWorkflowTriggerExists("pagerduty_incident_workflow_trigger.test"),
resource.TestCheckResourceAttr(
"pagerduty_incident_workflow_trigger.test", "type", "conditional"),
resource.TestCheckResourceAttr(
"pagerduty_incident_workflow_trigger.test", "condition", "incident.priority matches 'P1'"),
resource.TestCheckResourceAttr("pagerduty_incident_workflow_trigger.test", "subscribed_to_all_services", "true"),
),
},
{
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigConditionalAllServices(workflow, "incident.priority matches 'P2'"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyIncidentWorkflowTriggerExists("pagerduty_incident_workflow_trigger.test"),
resource.TestCheckResourceAttr(
"pagerduty_incident_workflow_trigger.test", "type", "conditional"),
resource.TestCheckResourceAttr(
"pagerduty_incident_workflow_trigger.test", "condition", "incident.priority matches 'P2'"),
),
},
},
})
}

func testAccCheckPagerDutyIncidentWorkflowTriggerDestroy(s *terraform.State) error {
client, _ := testAccProvider.Meta().(*Config).Client()
for _, r := range s.RootModule().Resources {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/incident_workflow_trigger.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ resource "pagerduty_incident_workflow_trigger" "manual_trigger" {

The following arguments are supported:

* `type` - (Required) May be either `manual` or `conditional`.
* `type` - (Required) [Updating causes resource replacement] May be either `manual` or `conditional`.
* `workflow` - (Required) The workflow ID for the workflow to trigger.
* `services` - (Optional) A list of service IDs. Incidents in any of the listed services are eligible to fire this trigger.
* `subscribed_to_all_services` - (Required) Set to `true` if the trigger should be eligible for firing on all services. Only allowed to be `true` if the services list is not defined or empty.
Expand Down

0 comments on commit 8259138

Please sign in to comment.