-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for teams in escalation policies & vendor support
- Loading branch information
Showing
23 changed files
with
661 additions
and
469 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
builtin/providers/pagerduty/data_source_pagerduty_vendor.go
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"regexp" | ||
|
||
pagerduty "github.com/PagerDuty/go-pagerduty" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourcePagerDutyVendor() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourcePagerDutyVendorRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name_regex": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePagerDutyVendorRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*pagerduty.Client) | ||
|
||
log.Printf("[INFO] Reading PagerDuty vendors") | ||
|
||
resp, err := getVendors(client) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
r := regexp.MustCompile("(?i)" + d.Get("name_regex").(string)) | ||
|
||
var vendors []pagerduty.Vendor | ||
var vendorNames []string | ||
|
||
for _, v := range resp { | ||
if r.MatchString(v.Name) { | ||
vendors = append(vendors, v) | ||
vendorNames = append(vendorNames, v.Name) | ||
} | ||
} | ||
|
||
if len(vendors) == 0 { | ||
return fmt.Errorf("Unable to locate any vendor using the regex string: %s", r.String()) | ||
} else if len(vendors) > 1 { | ||
return fmt.Errorf("Your query returned more than one result using the regex string: %#v. Found vendors: %#v", r.String(), vendorNames) | ||
} | ||
|
||
vendor := vendors[0] | ||
|
||
genericServiceType := vendor.GenericServiceType | ||
|
||
switch { | ||
case genericServiceType == "email": | ||
genericServiceType = "generic_email_inbound_integration" | ||
case genericServiceType == "api": | ||
genericServiceType = "generic_events_api_inbound_integration" | ||
} | ||
|
||
d.SetId(vendor.ID) | ||
d.Set("name", vendor.Name) | ||
d.Set("type", genericServiceType) | ||
|
||
return nil | ||
} |
49 changes: 49 additions & 0 deletions
49
builtin/providers/pagerduty/data_source_pagerduty_vendor_test.go
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccPagerDutyVendor_Basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckPagerDutyScheduleDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccPagerDutyVendorsConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccPagerDutyVendors("data.pagerduty_vendor.datadog"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccPagerDutyVendors(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
|
||
r := s.RootModule().Resources[n] | ||
a := r.Primary.Attributes | ||
|
||
if a["id"] == "" { | ||
return fmt.Errorf("Expected to get a vendor ID from PagerDuty") | ||
} | ||
|
||
if a["id"] != "PAM4FGS" { | ||
return fmt.Errorf("Expected the Datadog Vendor ID to be: PAM4FGS, but got: %s", a["id"]) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccPagerDutyVendorsConfig = ` | ||
data "pagerduty_vendor" "datadog" { | ||
name_regex = "Datadog" | ||
} | ||
` |
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
Oops, something went wrong.