provider/pagerduty Add delete support to pagerduty_service_integration (#10891)
* Vendor update * Add delete support * Update documentation
This commit is contained in:
parent
82288c6064
commit
bac59eb531
|
@ -0,0 +1,11 @@
|
|||
package pagerduty
|
||||
|
||||
import "strings"
|
||||
|
||||
func isNotFound(err error) bool {
|
||||
if strings.Contains(err.Error(), "Failed call API endpoint. HTTP response code: 404") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
|
@ -12,8 +12,6 @@ func resourcePagerDutyServiceIntegration() *schema.Resource {
|
|||
Create: resourcePagerDutyServiceIntegrationCreate,
|
||||
Read: resourcePagerDutyServiceIntegrationRead,
|
||||
Update: resourcePagerDutyServiceIntegrationUpdate,
|
||||
// NOTE: It's currently not possible to delete integrations via the API.
|
||||
// Therefore it needs to be manually removed from the Web UI.
|
||||
Delete: resourcePagerDutyServiceIntegrationDelete,
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
|
@ -123,6 +121,10 @@ func resourcePagerDutyServiceIntegrationRead(d *schema.ResourceData, meta interf
|
|||
serviceIntegration, err := client.GetIntegration(service, d.Id(), *o)
|
||||
|
||||
if err != nil {
|
||||
if isNotFound(err) {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -153,8 +155,20 @@ func resourcePagerDutyServiceIntegrationUpdate(d *schema.ResourceData, meta inte
|
|||
}
|
||||
|
||||
func resourcePagerDutyServiceIntegrationDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*pagerduty.Client)
|
||||
|
||||
service := d.Get("service").(string)
|
||||
|
||||
log.Printf("[INFO] Removing PagerDuty service integration %s", d.Id())
|
||||
|
||||
if err := client.DeleteIntegration(service, d.Id()); err != nil {
|
||||
if isNotFound(err) {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
|
|
|
@ -2,6 +2,7 @@ package pagerduty
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
|
@ -39,6 +40,7 @@ type Incident struct {
|
|||
EscalationPolicy APIObject `json:"escalation_policy,omitempty"`
|
||||
Teams []APIObject `json:"teams,omitempty"`
|
||||
Urgency string `json:"urgency,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// ListIncidentsResponse is the response structure when calling the ListIncident API endpoint.
|
||||
|
@ -145,3 +147,31 @@ func (c *Client) SnoozeIncident(id string, duration uint) error {
|
|||
_, err := c.post("/incidents/"+id+"/snooze", data)
|
||||
return err
|
||||
}
|
||||
|
||||
// ListIncidentLogEntriesResponse is the response structure when calling the ListIncidentLogEntires API endpoint.
|
||||
type ListIncidentLogEntriesResponse struct {
|
||||
APIListObject
|
||||
LogEntires []LogEntry `json:"log_entries,omitempty"`
|
||||
}
|
||||
|
||||
// ListIncidentLogEntriesOptions is the structure used when passing parameters to the ListIncidentLogEntires API endpoint.
|
||||
type ListIncidentLogEntriesOptions struct {
|
||||
APIListObject
|
||||
Includes []string `url:"include,omitempty,brackets"`
|
||||
IsOverview bool `url:"is_overview,omitempty"`
|
||||
TimeZone string `url:"time_zone,omitempty"`
|
||||
}
|
||||
|
||||
// ListIncidentLogEntries lists existing log entires for the specified incident.
|
||||
func (c *Client) ListIncidentLogEntries(id string, o ListIncidentLogEntriesOptions) (*ListIncidentLogEntriesResponse, error) {
|
||||
v, err := query.Values(o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := c.get("/incidents/" + id + "/log_entries?" + v.Encode())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result ListIncidentLogEntriesResponse
|
||||
return &result, c.decodeJSON(resp, &result)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package pagerduty
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
|
@ -13,6 +14,15 @@ type Channel struct {
|
|||
Type string
|
||||
}
|
||||
|
||||
// Context are to be included with the trigger such as links to graphs or images.
|
||||
type Context struct {
|
||||
Alt string
|
||||
Href string
|
||||
Src string
|
||||
Text string
|
||||
Type string
|
||||
}
|
||||
|
||||
// LogEntry is a list of all of the events that happened to an incident.
|
||||
type LogEntry struct {
|
||||
APIObject
|
||||
|
@ -21,7 +31,8 @@ type LogEntry struct {
|
|||
Channel Channel
|
||||
Incident Incident
|
||||
Teams []Team
|
||||
Contexts []string
|
||||
Contexts []Context
|
||||
AcknowledgementTimeout int `json:"acknowledgement_timeout"`
|
||||
EventDetails map[string]string
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ func (c *Client) UpdateIntegration(serviceID string, i Integration) (*Integratio
|
|||
|
||||
// DeleteIntegration deletes an existing integration.
|
||||
func (c *Client) DeleteIntegration(serviceID string, integrationID string) error {
|
||||
_, err := c.delete("/services/" + serviceID + "/integrations" + integrationID)
|
||||
_, err := c.delete("/services/" + serviceID + "/integrations/" + integrationID)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ type IncidentDetail struct {
|
|||
AssignedToUser *json.RawMessage `json:"assigned_to_user"`
|
||||
AssignedTo []string `json:"assigned_to"`
|
||||
TriggerSummaryData *json.RawMessage `json:"trigger_summary_data"`
|
||||
TriggerDeatilsHTMLUrl string `json:"trigger_details_html_url"`
|
||||
TriggerDetailsHTMLUrl string `json:"trigger_details_html_url"`
|
||||
}
|
||||
|
||||
// WebhookPayload is a single message array for a webhook.
|
||||
|
|
|
@ -333,10 +333,10 @@
|
|||
"revisionTime": "2016-11-03T18:56:17Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "yAhUY67XCnf+0jpIsQ53lirk+GM=",
|
||||
"checksumSHA1": "wzzdybMOEWsQ/crdkpTLneeob2U=",
|
||||
"path": "github.com/PagerDuty/go-pagerduty",
|
||||
"revision": "b98d93d395cd13b0438ad908b5f7c608f1f74c38",
|
||||
"revisionTime": "2016-12-16T21:25:03Z"
|
||||
"revision": "317bca1364fc322f4d6f8eeb276e931b6667b43b",
|
||||
"revisionTime": "2016-12-20T22:05:08Z"
|
||||
},
|
||||
{
|
||||
"path": "github.com/Unknwon/com",
|
||||
|
|
|
@ -10,9 +10,6 @@ description: |-
|
|||
|
||||
A [service integration](https://v2.developer.pagerduty.com/v2/page/api-reference#!/Services/post_services_id_integrations) is an integration that belongs to a service.
|
||||
|
||||
`Note`: A service integration `cannot` be deleted via Terraform nor the PagerDuty API so if you remove a service integration, be sure to remove it from the PagerDuty Web UI afterwards. However, if you delete the `service` attached to the `integration`, the integration will be removed.
|
||||
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue