Skip to content

Commit

Permalink
added runner update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdubr committed Jan 4, 2023
1 parent de686af commit 92f244b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pagerduty/resource_pagerduty_automation_actions_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func resourcePagerDutyAutomationActionsRunner() *schema.Resource {
return &schema.Resource{
Create: resourcePagerDutyAutomationActionsRunnerCreate,
Read: resourcePagerDutyAutomationActionsRunnerRead,
Update: resourcePagerDutyAutomationActionsRunnerUpdate,
Delete: resourcePagerDutyAutomationActionsRunnerDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand All @@ -22,7 +23,6 @@ func resourcePagerDutyAutomationActionsRunner() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true, // Requires creation of new resource while support for update is not implemented
},
"runner_type": {
Type: schema.TypeString,
Expand All @@ -36,17 +36,14 @@ func resourcePagerDutyAutomationActionsRunner() *schema.Resource {
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true, // Requires creation of new resource while support for update is not implemented
},
"runbook_base_uri": {
Type: schema.TypeString,
Optional: true,
ForceNew: true, // Requires creation of new resource while support for update is not implemented
},
"runbook_api_key": {
Type: schema.TypeString,
Optional: true,
ForceNew: true, // Requires creation of new resource while support for update is not implemented
Sensitive: true,
},
"type": {
Expand Down Expand Up @@ -170,6 +167,26 @@ func resourcePagerDutyAutomationActionsRunnerRead(d *schema.ResourceData, meta i
})
}

func resourcePagerDutyAutomationActionsRunnerUpdate(d *schema.ResourceData, meta interface{}) error {
client, err := meta.(*Config).Client()
if err != nil {
return err
}

automationActionsRunner, err := buildAutomationActionsRunnerStruct(d)
if err != nil {
return err
}

log.Printf("[INFO] Updating PagerDuty AutomationActionsRunner %s", d.Id())

if _, _, err := client.AutomationActionsRunner.Update(d.Id(), automationActionsRunner); err != nil {
return err
}

return nil
}

func resourcePagerDutyAutomationActionsRunnerDelete(d *schema.ResourceData, meta interface{}) error {
client, err := meta.(*Config).Client()
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions pagerduty/resource_pagerduty_automation_actions_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func testSweepAutomationActionsRunner(region string) error {
func TestAccPagerDutyAutomationActionsRunner_Basic(t *testing.T) {
runnerName := fmt.Sprintf("tf-%s", acctest.RandString(5))

nameUpdated := fmt.Sprintf("%s-updated", runnerName)
descriptionUpdated := fmt.Sprintf("Description of %s-updated", runnerName)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -41,6 +44,19 @@ func TestAccPagerDutyAutomationActionsRunner_Basic(t *testing.T) {
resource.TestCheckResourceAttrSet("pagerduty_automation_actions_runner.foo", "creation_time"),
),
},
{
Config: testAccCheckPagerDutyAutomationActionsRunnerUpdatedConfig(nameUpdated, descriptionUpdated),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyAutomationActionsRunnerExists("pagerduty_automation_actions_runner.foo"),
resource.TestCheckResourceAttr("pagerduty_automation_actions_runner.foo", "name", nameUpdated),
resource.TestCheckResourceAttr("pagerduty_automation_actions_runner.foo", "runner_type", "runbook"),
resource.TestCheckResourceAttr("pagerduty_automation_actions_runner.foo", "description", descriptionUpdated),
resource.TestCheckResourceAttr("pagerduty_automation_actions_runner.foo", "runbook_base_uri", "cat-cat-updated"),
resource.TestCheckResourceAttr("pagerduty_automation_actions_runner.foo", "type", "runner"),
resource.TestCheckResourceAttrSet("pagerduty_automation_actions_runner.foo", "id"),
resource.TestCheckResourceAttrSet("pagerduty_automation_actions_runner.foo", "creation_time"),
),
},
},
})
}
Expand Down Expand Up @@ -92,3 +108,15 @@ resource "pagerduty_automation_actions_runner" "foo" {
}
`, runnerName)
}

func testAccCheckPagerDutyAutomationActionsRunnerUpdatedConfig(nameUpdated, descriptionUpdated string) string {
return fmt.Sprintf(`
resource "pagerduty_automation_actions_runner" "foo" {
name = "%s"
description = "%s"
runner_type = "runbook"
runbook_base_uri = "cat-cat-updated"
runbook_api_key = "cat-secret-updated"
}
`, nameUpdated, descriptionUpdated)
}

0 comments on commit 92f244b

Please sign in to comment.