Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration: Validate that email integration has email #382

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pagerduty/resource_pagerduty_service_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ func resourcePagerDutyServiceIntegration() *schema.Resource {
Read: resourcePagerDutyServiceIntegrationRead,
Update: resourcePagerDutyServiceIntegrationUpdate,
Delete: resourcePagerDutyServiceIntegrationDelete,
CustomizeDiff: func(diff *schema.ResourceDiff, i interface{}) error {
t := diff.Get("type").(string)
if t == "generic_email_inbound_integration" && diff.Get("integration_email").(string) == "" {
return fmt.Errorf("integration_email attribute must be set for an integration type generic_email_inbound_integration")
}
return nil
},
Importer: &schema.ResourceImporter{
State: resourcePagerDutyServiceIntegrationImport,
},
Expand Down
63 changes: 63 additions & 0 deletions pagerduty/resource_pagerduty_service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pagerduty

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
Expand Down Expand Up @@ -86,6 +87,20 @@ func TestAccPagerDutyServiceIntegrationGeneric_Basic(t *testing.T) {
"pagerduty_service_integration.foo", "type", "generic_events_api_inbound_integration"),
),
},
{
Config: testAccCheckPagerDutyServiceIntegrationGenericEmail(username, email, escalationPolicy, service, serviceIntegration, ""),
PlanOnly: true,
ExpectError: regexp.MustCompile("integration_email attribute must be set for an integration type generic_email_inbound_integration"),
},
{
Config: testAccCheckPagerDutyServiceIntegrationGenericEmail(username, email, escalationPolicy, service, serviceIntegration, "user@pagerduty.com"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"pagerduty_service_integration.foo", "type", "generic_email_inbound_integration"),
),
PlanOnly: true,
ExpectNonEmptyPlan: true,
},
},
})
}
Expand Down Expand Up @@ -322,3 +337,51 @@ resource "pagerduty_service_integration" "foo" {
}
`, username, email, escalationPolicy, service, serviceIntegration)
}

func testAccCheckPagerDutyServiceIntegrationGenericEmail(username, email, escalationPolicy, service, serviceIntegration, integrationEmail string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" {
name = "%s"
email = "%s"
color = "green"
role = "user"
job_title = "foo"
description = "foo"
}

resource "pagerduty_escalation_policy" "foo" {
name = "%s"
description = "bar"
num_loops = 2

rule {
escalation_delay_in_minutes = 10

target {
type = "user_reference"
id = pagerduty_user.foo.id
}
}
}

resource "pagerduty_service" "foo" {
name = "%s"
description = "bar"
auto_resolve_timeout = 3600
acknowledgement_timeout = 3600
escalation_policy = pagerduty_escalation_policy.foo.id

incident_urgency_rule {
type = "constant"
urgency = "high"
}
}

resource "pagerduty_service_integration" "foo" {
name = "%s"
service = pagerduty_service.foo.id
type = "generic_email_inbound_integration"
integration_email = "%s"
}
`, username, email, escalationPolicy, service, serviceIntegration, integrationEmail)
}