Skip to content

Commit

Permalink
add support for resource `pagerduty_automation_actions_action_team_as…
Browse files Browse the repository at this point in the history
…sociation`
  • Loading branch information
imjaroiswebdev committed Dec 16, 2022
1 parent fda3333 commit 95d5aa9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func resourcePagerDutyAutomationActionsActionTeamAssociationCreate(d *schema.Res
actionID := d.Get("action_id").(string)
teamID := d.Get("team_id").(string)

log.Printf("[INFO] Creating PagerDuty AutomationActionsActionTeamAssociation %s:%s", d.Get("actionID").(string), d.Get("team_id").(string))
log.Printf("[INFO] Creating PagerDuty AutomationActionsActionTeamAssociation %s:%s", d.Get("action_id").(string), d.Get("team_id").(string))

retryErr := resource.Retry(10*time.Second, func() *resource.RetryError {
if teamRef, _, err := client.AutomationActionsAction.AssociateToTeam(actionID, teamID); err != nil {
Expand Down Expand Up @@ -73,7 +73,7 @@ func fetchPagerDutyAutomationActionsActionTeamAssociation(d *schema.ResourceData
actionID, teamID := resourcePagerDutyParseColonCompoundID(d.Id())
log.Printf("[DEBUG] Reading a2 action: %s from team: %s", actionID, teamID)
return resource.Retry(30*time.Second, func() *resource.RetryError {
teamRef, _, err := client.AutomationActionsAction.GetAssociationToTeam(actionID, teamID)
resp, _, err := client.AutomationActionsAction.GetAssociationToTeam(actionID, teamID)
if err != nil {
errResp := errCallback(err, d)
if errResp != nil {
Expand All @@ -84,14 +84,14 @@ func fetchPagerDutyAutomationActionsActionTeamAssociation(d *schema.ResourceData
return nil
}

if teamRef.ID != teamID {
if resp.Team.ID != teamID {
log.Printf("[WARN] Removing %s since the user: %s is not a member of: %s", d.Id(), actionID, teamID)
d.SetId("")
return nil
}

d.Set("action_id", actionID)
d.Set("team_id", teamRef.ID)
d.Set("team_id", resp.Team.ID)

return nil
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func testSweepAutomationActionsActionTeamAssociation(region string) error {
}

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

resource.Test(t, resource.TestCase{
Expand All @@ -29,7 +30,7 @@ func TestAccPagerDutyAutomationActionsActionTeamAssociation_Basic(t *testing.T)
CheckDestroy: testAccCheckPagerDutyAutomationActionsActionTeamAssociationDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyAutomationActionsActionTeamAssociationConfig(teamName),
Config: testAccCheckPagerDutyAutomationActionsActionTeamAssociationConfig(actionName, teamName),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyAutomationActionsActionTeamAssociationExists("pagerduty_automation_actions_action_team_association.foo"),
resource.TestCheckResourceAttrSet("pagerduty_automation_actions_action_team_association.foo", "action_id"),
Expand Down Expand Up @@ -70,27 +71,35 @@ func testAccCheckPagerDutyAutomationActionsActionTeamAssociationExists(n string)
if err != nil {
return err
}
if found.ID != rs.Primary.ID {
if fmt.Sprintf("%s:%s", actionID, found.Team.ID) != rs.Primary.ID {
return fmt.Errorf("Automation Actions Action association to team not found: %v - %v", rs.Primary.ID, found)
}

return nil
}
}

func testAccCheckPagerDutyAutomationActionsActionTeamAssociationConfig(teamName string) string {
func testAccCheckPagerDutyAutomationActionsActionTeamAssociationConfig(teamName, actionName string) string {
return fmt.Sprintf(`
resource "pagerduty_team" "foo" {
name = "%s"
description = "foo"
}
# expecting action resource to be here
resource "pagerduty_automation_actions_action" "foo" {
name = "%s"
description = "PA Action created by TF"
action_type = "script"
action_data_reference {
script = "java --version"
invocation_command = "/bin/bash"
}
}
resource "pagerduty_automation_actions_action_team_association" "foo" {
action_id = "action_id_will_be_here"
action_id = pagerduty_automation_actions_action.foo.id
team_id = pagerduty_team.foo.id
}
`, teamName)
`, teamName, actionName)
}

0 comments on commit 95d5aa9

Please sign in to comment.