-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #861 from imjaroiswebdev/issue-848-support-iw-perm…
…issions Add support for Incident Workflow triggers team restrictions
- Loading branch information
Showing
10 changed files
with
244 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,150 @@ func TestAccPagerDutyIncidentWorkflowTrigger_BasicConditionalAllServices(t *test | |
}) | ||
} | ||
|
||
func TestAccPagerDutyIncidentWorkflowTrigger_ManualWithTeamPermissions(t *testing.T) { | ||
username := fmt.Sprintf("tf-%s", acctest.RandString(5)) | ||
email := fmt.Sprintf("%[email protected]", username) | ||
escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5)) | ||
service := fmt.Sprintf("tf-%s", acctest.RandString(5)) | ||
workflow := fmt.Sprintf("tf-%s", acctest.RandString(5)) | ||
teamName := fmt.Sprintf("tf-%s", acctest.RandString(5)) | ||
teamIDTFRef := "pagerduty_team.foo.id" | ||
emptyCondition := "" | ||
dummyCondition := "event.summary matches 'foo'" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
testAccPreCheckIncidentWorkflows(t) | ||
}, | ||
ProviderFactories: testAccProviderFactories, | ||
CheckDestroy: testAccCheckPagerDutyIncidentWorkflowTriggerDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualWithPermissions(username, email, escalationPolicy, service, teamName, 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", "permissions.0.restricted", "false"), | ||
), | ||
}, | ||
{ | ||
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualWithPermissionsUpdated(username, email, escalationPolicy, service, teamName, workflow, "manual", emptyCondition, "true", teamIDTFRef), | ||
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", "permissions.0.restricted", "true"), | ||
testAccCheckPagerDutyIncidentWorkflowTriggerCheckPermissionsTeamId("pagerduty_incident_workflow_trigger.test", "pagerduty_team.foo"), | ||
), | ||
}, | ||
// Check input validation conditions for permissions configuration | ||
{ | ||
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualWithPermissionsUpdated(username, email, escalationPolicy, service, teamName, workflow, "conditional", dummyCondition, "true", teamIDTFRef), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckPagerDutyIncidentWorkflowTriggerExists("pagerduty_incident_workflow_trigger.test"), | ||
), | ||
PlanOnly: true, | ||
ExpectError: regexp.MustCompile("restricted can only be true when trigger type is manual"), | ||
}, | ||
{ | ||
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualWithPermissionsUpdated(username, email, escalationPolicy, service, teamName, workflow, "manual", emptyCondition, "false", teamIDTFRef), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckPagerDutyIncidentWorkflowTriggerExists("pagerduty_incident_workflow_trigger.test"), | ||
), | ||
PlanOnly: true, | ||
ExpectError: regexp.MustCompile("team_id not allowed when restricted is false"), | ||
}, | ||
{ | ||
Config: testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualWithPermissionsUpdated(username, email, escalationPolicy, service, teamName, workflow, "manual", emptyCondition, "true", `""`), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckPagerDutyIncidentWorkflowTriggerExists("pagerduty_incident_workflow_trigger.test"), | ||
), | ||
ExpectError: regexp.MustCompile("team_id must be specified when restricted is true"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualWithPermissions(username, email, escalationPolicy, service, workflow, team string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
%s | ||
resource "pagerduty_team" "foo" { | ||
name = %q | ||
} | ||
resource "pagerduty_incident_workflow_trigger" "test" { | ||
type = "manual" | ||
workflow = pagerduty_incident_workflow.test.id | ||
services = [pagerduty_service.foo.id] | ||
subscribed_to_all_services = false | ||
} | ||
`, testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service), testAccCheckPagerDutyIncidentWorkflowConfig(workflow), team) | ||
} | ||
|
||
func testAccCheckPagerDutyIncidentWorkflowTriggerConfigManualWithPermissionsUpdated(username, email, escalationPolicy, service, workflow, team, triggerType, condition, isRestricted, teamId string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
%s | ||
resource "pagerduty_team" "foo" { | ||
name = "%s" | ||
} | ||
resource "pagerduty_incident_workflow_trigger" "test" { | ||
type = "%s" | ||
condition = "%s" | ||
workflow = pagerduty_incident_workflow.test.id | ||
services = [pagerduty_service.foo.id] | ||
subscribed_to_all_services = false | ||
permissions { | ||
restricted = %s | ||
team_id = %s | ||
} | ||
} | ||
`, testAccCheckPagerDutyServiceConfig(username, email, escalationPolicy, service), testAccCheckPagerDutyIncidentWorkflowConfig(workflow), team, triggerType, condition, isRestricted, teamId) | ||
} | ||
|
||
func testAccCheckPagerDutyIncidentWorkflowTriggerCheckPermissionsTeamId(iwtName, teamName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rsIWT, ok := s.RootModule().Resources[iwtName] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", iwtName) | ||
} | ||
if rsIWT.Primary.ID == "" { | ||
return fmt.Errorf("no incident workflow trigger ID is set") | ||
} | ||
|
||
rsTeam, ok := s.RootModule().Resources[teamName] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", teamName) | ||
} | ||
if rsTeam.Primary.ID == "" { | ||
return fmt.Errorf("no team ID is set") | ||
} | ||
|
||
client, _ := testAccProvider.Meta().(*Config).Client() | ||
|
||
found, _, err := client.IncidentWorkflowTriggers.Get(rsIWT.Primary.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if found.Permissions.TeamID != rsTeam.Primary.ID { | ||
return fmt.Errorf("incident workflow trigger team restriction wanted %q, but got %q", rsTeam.Primary.ID, found.Permissions.TeamID) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func TestAccPagerDutyIncidentWorkflowTrigger_ChangeTypeCausesReplace(t *testing.T) { | ||
workflow := fmt.Sprintf("tf-%s", acctest.RandString(5)) | ||
|
||
|
16 changes: 8 additions & 8 deletions
16
vendor/github.com/heimweh/go-pagerduty/pagerduty/event_orchestration_cache_variable.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
vendor/github.com/heimweh/go-pagerduty/pagerduty/event_orchestration_path.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 13 additions & 7 deletions
20
vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow_trigger.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters