From aa93eab0ecb8cda077dc04ae965c2fe504eeb19a Mon Sep 17 00:00:00 2001 From: Julianna Green Date: Tue, 29 Oct 2024 10:50:24 -0700 Subject: [PATCH 1/3] AA-1837 add only_invocable_on_unresolved_incidents attribute to automation action --- ...rce_pagerduty_automation_actions_action.go | 5 ++++ ...agerduty_automation_actions_action_test.go | 1 + ...rce_pagerduty_automation_actions_action.go | 14 +++++++++ ...agerduty_automation_actions_action_test.go | 7 ++++- .../pagerduty/automation_actions_action.go | 29 ++++++++++--------- .../d/automation_actions_action.html.markdown | 7 +++-- .../r/automation_actions_action.html.markdown | 3 +- 7 files changed, 47 insertions(+), 19 deletions(-) diff --git a/pagerduty/data_source_pagerduty_automation_actions_action.go b/pagerduty/data_source_pagerduty_automation_actions_action.go index ed16962cc..f977beed4 100644 --- a/pagerduty/data_source_pagerduty_automation_actions_action.go +++ b/pagerduty/data_source_pagerduty_automation_actions_action.go @@ -94,6 +94,11 @@ func dataSourcePagerDutyAutomationActionsAction() *schema.Resource { Computed: true, Optional: true, }, + "only_invocable_on_unresolved_incidents": { + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, }, } } diff --git a/pagerduty/data_source_pagerduty_automation_actions_action_test.go b/pagerduty/data_source_pagerduty_automation_actions_action_test.go index fa10025b6..59110783d 100644 --- a/pagerduty/data_source_pagerduty_automation_actions_action_test.go +++ b/pagerduty/data_source_pagerduty_automation_actions_action_test.go @@ -75,6 +75,7 @@ resource "pagerduty_automation_actions_action" "test" { process_automation_job_arguments = "-arg 1" process_automation_node_filter = "tags: production" } + only_invocable_on_unresolved_incidents: true } data "pagerduty_automation_actions_action" "foo" { diff --git a/pagerduty/resource_pagerduty_automation_actions_action.go b/pagerduty/resource_pagerduty_automation_actions_action.go index 907afdc7a..b26e9fc52 100644 --- a/pagerduty/resource_pagerduty_automation_actions_action.go +++ b/pagerduty/resource_pagerduty_automation_actions_action.go @@ -99,6 +99,11 @@ func resourcePagerDutyAutomationActionsAction() *schema.Resource { Computed: true, Optional: true, }, + "only_invocable_on_unresolved_incidents": { + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, }, } } @@ -153,6 +158,11 @@ func buildAutomationActionsActionStruct(d *schema.ResourceData) (*pagerduty.Auto automationActionsAction.ModifyTime = &val } + if attr, ok := d.GetOk("only_invocable_on_unresolved_incidents"); ok { + val := attr.(bool) + automationActionsAction.OnlyInvocableOnUnresolvedIncidents = &val + } + return &automationActionsAction, nil } @@ -298,6 +308,10 @@ func resourcePagerDutyAutomationActionsActionRead(d *schema.ResourceData, meta i if automationActionsAction.ActionClassification != nil { d.Set("action_classification", &automationActionsAction.ActionClassification) } + + if automationActionsAction.OnlyInvocableOnUnresolvedIncidents != nil { + d.Set("only_invocable_on_unresolved_incidents", &automationActionsAction.OnlyInvocableOnUnresolvedIncidents) + } } return nil }) diff --git a/pagerduty/resource_pagerduty_automation_actions_action_test.go b/pagerduty/resource_pagerduty_automation_actions_action_test.go index e47e21ed6..b7f6266d7 100644 --- a/pagerduty/resource_pagerduty_automation_actions_action_test.go +++ b/pagerduty/resource_pagerduty_automation_actions_action_test.go @@ -57,6 +57,7 @@ func TestAccPagerDutyAutomationActionsActionTypeProcessAutomation_Basic(t *testi resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "modify_time"), resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "runner_id"), resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "runner_type", "runbook"), + resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents", "true"), ), }, { @@ -84,6 +85,7 @@ func TestAccPagerDutyAutomationActionsActionTypeProcessAutomation_Basic(t *testi resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "modify_time"), resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "runner_id"), resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "runner_type", "runbook"), + resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents", "true"), ), }, }, @@ -127,6 +129,7 @@ func TestAccPagerDutyAutomationActionsActionTypeScript_Basic(t *testing.T) { resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "modify_time"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_type"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_id"), + resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents"), ), }, { @@ -152,6 +155,7 @@ func TestAccPagerDutyAutomationActionsActionTypeScript_Basic(t *testing.T) { resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "modify_time"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_type"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_id"), + resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents"), ), }, }, @@ -214,7 +218,8 @@ resource "pagerduty_automation_actions_action" "foo" { process_automation_job_id = "pa_job_id_123" process_automation_job_arguments = "-arg 1" process_automation_node_filter = "tags: production" - } + }, + only_invocable_on_unresolved_incidents = "true" } `, actionName, actionName) } diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go index a2eb1ecc5..65ab7d850 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go @@ -7,20 +7,21 @@ import "fmt" type AutomationActionsActionService service type AutomationActionsAction struct { - ID string `json:"id"` - Name string `json:"name"` - Description *string `json:"description,omitempty"` - ActionType string `json:"action_type"` - RunnerID *string `json:"runner,omitempty"` - ActionDataReference AutomationActionsActionDataReference `json:"action_data_reference"` - Services []*ServiceReference `json:"services,omitempty"` - Teams []*TeamReference `json:"teams,omitempty"` - Privileges *AutomationActionsPrivileges `json:"privileges,omitempty"` - Type *string `json:"type,omitempty"` - ActionClassification *string `json:"action_classification,omitempty"` - RunnerType *string `json:"runner_type,omitempty"` - CreationTime *string `json:"creation_time,omitempty"` - ModifyTime *string `json:"modify_time,omitempty"` + ID string `json:"id"` + Name string `json:"name"` + Description *string `json:"description,omitempty"` + ActionType string `json:"action_type"` + RunnerID *string `json:"runner,omitempty"` + ActionDataReference AutomationActionsActionDataReference `json:"action_data_reference"` + Services []*ServiceReference `json:"services,omitempty"` + Teams []*TeamReference `json:"teams,omitempty"` + Privileges *AutomationActionsPrivileges `json:"privileges,omitempty"` + Type *string `json:"type,omitempty"` + ActionClassification *string `json:"action_classification,omitempty"` + RunnerType *string `json:"runner_type,omitempty"` + CreationTime *string `json:"creation_time,omitempty"` + ModifyTime *string `json:"modify_time,omitempty"` + OnlyInvocableOnUnresolvedIncidents *bool `json:"only_invocable_on_unresolved_incidents,omitempty"` } type AutomationActionsActionDataReference struct { diff --git a/website/docs/d/automation_actions_action.html.markdown b/website/docs/d/automation_actions_action.html.markdown index 94420e951..9b50201c8 100644 --- a/website/docs/d/automation_actions_action.html.markdown +++ b/website/docs/d/automation_actions_action.html.markdown @@ -31,14 +31,15 @@ The following attributes are exported: * `id` - The ID of the action. * `name` - The name of the action. * `type` - The type of object. The value returned will be `action`. -* `action_type` - The type of the action. The only allowed values are `process_automation` and `script`. +* `action_type` - The type of the action. The only allowed values are `process_automation` and `script`. * `creation_time` - The time action was created. Represented as an ISO 8601 timestamp. * `action_data_reference` - Action Data block. Action Data is documented below. * `description` - (Optional) The description of the action. -* `runner_id` - (Optional) The Process Automation Actions runner to associate the action with. +* `runner_id` - (Optional) The Process Automation Actions runner to associate the action with. * `runner_type` - (Optional) The type of the runner associated with the action. -* `action_classification` - (Optional) The category of the action. The only allowed values are `diagnostic` and `remediation`. +* `action_classification` - (Optional) The category of the action. The only allowed values are `diagnostic` and `remediation`. * `modify_time` - (Optional) The last time action has been modified. Represented as an ISO 8601 timestamp. +* `only_invocable_on_unresolved_incidents` - (Optional) Whether or not the action can be invoked on unresolved incidents. Action Data (`action_data_reference`) supports the following: diff --git a/website/docs/r/automation_actions_action.html.markdown b/website/docs/r/automation_actions_action.html.markdown index 7c5155473..30abc0452 100644 --- a/website/docs/r/automation_actions_action.html.markdown +++ b/website/docs/r/automation_actions_action.html.markdown @@ -43,7 +43,7 @@ The following arguments are supported: * `action_type` - (Required) The type of the action. The only allowed values are `process_automation` and `script`. Cannot be changed once set. * `action_data_reference` - (Required) Action Data block. Action Data is documented below. * `runner_id` - (Optional) The Process Automation Actions runner to associate the action with. Cannot be changed for the `process_automation` action type once set. - * `action_classification` - (Optional) The category of the action. The only allowed values are `diagnostic` and `remediation`. + * `action_classification` - (Optional) The category of the action. The only allowed values are `diagnostic` and `remediation`. Action Data (`action_data_reference`) supports the following: @@ -52,6 +52,7 @@ Action Data (`action_data_reference`) supports the following: * `process_automation_node_filter` - (Optional) The expression that filters on which nodes a Process Automation Job executes [Learn more](https://docs.rundeck.com/docs/manual/05-nodes.html#node-filtering). * `script` - (Required for `script` action_type) Body of the script to be executed on the Runner. Max length is 16777215 characters. * `invocation_command` - (Optional) The command to execute the script with. + * `only_invocable_on_unresolved_incidents` - (Optional) Whether or not the action can be invoked on unresolved incidents. ## Attributes Reference From 2482d66403ca81fd06fe240531ea9b325926b7db Mon Sep 17 00:00:00 2001 From: Julianna Green Date: Mon, 11 Nov 2024 11:31:23 -0800 Subject: [PATCH 2/3] address PR feedback --- .../data_source_pagerduty_automation_actions_action_test.go | 2 +- pagerduty/resource_pagerduty_automation_actions_action.go | 5 ++++- .../resource_pagerduty_automation_actions_action_test.go | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pagerduty/data_source_pagerduty_automation_actions_action_test.go b/pagerduty/data_source_pagerduty_automation_actions_action_test.go index 59110783d..d44cfdfb1 100644 --- a/pagerduty/data_source_pagerduty_automation_actions_action_test.go +++ b/pagerduty/data_source_pagerduty_automation_actions_action_test.go @@ -75,7 +75,7 @@ resource "pagerduty_automation_actions_action" "test" { process_automation_job_arguments = "-arg 1" process_automation_node_filter = "tags: production" } - only_invocable_on_unresolved_incidents: true + only_invocable_on_unresolved_incidents = true } data "pagerduty_automation_actions_action" "foo" { diff --git a/pagerduty/resource_pagerduty_automation_actions_action.go b/pagerduty/resource_pagerduty_automation_actions_action.go index b26e9fc52..2384f3860 100644 --- a/pagerduty/resource_pagerduty_automation_actions_action.go +++ b/pagerduty/resource_pagerduty_automation_actions_action.go @@ -163,6 +163,9 @@ func buildAutomationActionsActionStruct(d *schema.ResourceData) (*pagerduty.Auto automationActionsAction.OnlyInvocableOnUnresolvedIncidents = &val } + attr, _ := d.Get("only_invocable_on_unresolved_incidents").(bool) + automationActionsAction.OnlyInvocableOnUnresolvedIncidents = &attr + return &automationActionsAction, nil } @@ -310,7 +313,7 @@ func resourcePagerDutyAutomationActionsActionRead(d *schema.ResourceData, meta i } if automationActionsAction.OnlyInvocableOnUnresolvedIncidents != nil { - d.Set("only_invocable_on_unresolved_incidents", &automationActionsAction.OnlyInvocableOnUnresolvedIncidents) + d.Set("only_invocable_on_unresolved_incidents", *automationActionsAction.OnlyInvocableOnUnresolvedIncidents) } } return nil diff --git a/pagerduty/resource_pagerduty_automation_actions_action_test.go b/pagerduty/resource_pagerduty_automation_actions_action_test.go index b7f6266d7..1f681bc98 100644 --- a/pagerduty/resource_pagerduty_automation_actions_action_test.go +++ b/pagerduty/resource_pagerduty_automation_actions_action_test.go @@ -85,7 +85,7 @@ func TestAccPagerDutyAutomationActionsActionTypeProcessAutomation_Basic(t *testi resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "modify_time"), resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "runner_id"), resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "runner_type", "runbook"), - resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents", "true"), + resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents", "false"), ), }, }, @@ -218,7 +218,7 @@ resource "pagerduty_automation_actions_action" "foo" { process_automation_job_id = "pa_job_id_123" process_automation_job_arguments = "-arg 1" process_automation_node_filter = "tags: production" - }, + } only_invocable_on_unresolved_incidents = "true" } `, actionName, actionName) From dc52cb361d1b8edd052bac9a6bd50aa4f6027ae9 Mon Sep 17 00:00:00 2001 From: Carlos Gajardo Date: Wed, 13 Nov 2024 11:33:31 -0300 Subject: [PATCH 3/3] Fix tests for false only_invocable_on_unresolved_incidents of automation actions --- .../resource_pagerduty_automation_actions_action_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pagerduty/resource_pagerduty_automation_actions_action_test.go b/pagerduty/resource_pagerduty_automation_actions_action_test.go index 1f681bc98..94e312d43 100644 --- a/pagerduty/resource_pagerduty_automation_actions_action_test.go +++ b/pagerduty/resource_pagerduty_automation_actions_action_test.go @@ -129,7 +129,7 @@ func TestAccPagerDutyAutomationActionsActionTypeScript_Basic(t *testing.T) { resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "modify_time"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_type"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_id"), - resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents"), + resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents", "false"), ), }, { @@ -155,7 +155,7 @@ func TestAccPagerDutyAutomationActionsActionTypeScript_Basic(t *testing.T) { resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action.foo", "modify_time"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_type"), resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "runner_id"), - resource.TestCheckNoResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents"), + resource.TestCheckResourceAttr("pagerduty_automation_actions_action.foo", "only_invocable_on_unresolved_incidents", "false"), ), }, }, @@ -243,7 +243,8 @@ resource "pagerduty_automation_actions_action" "foo" { runner_id = pagerduty_automation_actions_runner.foo_runner.id action_data_reference { process_automation_job_id = "updated_pa_job_id_123" - } + } + only_invocable_on_unresolved_incidents = "false" } `, previousActionName, actionName, actionDescription, actionClassification) }