diff --git a/CHANGELOG.md b/CHANGELOG.md index ea2ab5e9..5b096254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.4.9 (September 17, 2020) +NEW RESOURCE: +* Incident Template implemented (#178) + + ## 0.4.8 (September 4, 2020) NEW RESOURCE: * Notification rule implemented (#121) diff --git a/go.mod b/go.mod index c273b76e..22d44bfc 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.14 require ( github.com/hashicorp/go-retryablehttp v0.6.6 github.com/hashicorp/terraform-plugin-sdk v1.15.0 - github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200820123717-3bcc8ea32b68 + github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac github.com/pkg/errors v0.8.1 ) diff --git a/go.sum b/go.sum index 8f4358fa..256eed41 100644 --- a/go.sum +++ b/go.sum @@ -169,8 +169,8 @@ github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY7 github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200820123717-3bcc8ea32b68 h1:aeMcivVe6oeKG+2eIml82VULDUIRLXfqEDNmfjesf5o= -github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200820123717-3bcc8ea32b68/go.mod h1:VOkJ7STzYj+nXRhMcBTcmt8uZZ17KZKJdZtJpgHLbT8= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac h1:SxtpD9CfTncbSkcNVYeqW46DXJqz5b7HH8/BB43D+h0= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac/go.mod h1:VOkJ7STzYj+nXRhMcBTcmt8uZZ17KZKJdZtJpgHLbT8= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/opsgenie/provider.go b/opsgenie/provider.go index e5d66c78..1985fa1f 100644 --- a/opsgenie/provider.go +++ b/opsgenie/provider.go @@ -40,6 +40,7 @@ func Provider() terraform.ResourceProvider { "opsgenie_heartbeat": resourceOpsgenieHeartbeat(), "opsgenie_alert_policy": resourceOpsGenieAlertPolicy(), "opsgenie_service_incident_rule": resourceOpsGenieServiceIncidentRule(), + "opsgenie_incident_template": resourceOpsgenieIncidentTemplate(), }, DataSourcesMap: map[string]*schema.Resource{ diff --git a/opsgenie/resource_opsgenie_incident_template.go b/opsgenie/resource_opsgenie_incident_template.go new file mode 100644 index 00000000..56111efa --- /dev/null +++ b/opsgenie/resource_opsgenie_incident_template.go @@ -0,0 +1,216 @@ +package opsgenie + +import ( + "context" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/opsgenie/opsgenie-go-sdk-v2/incident" + "log" +) + +func resourceOpsgenieIncidentTemplate() *schema.Resource { + return &schema.Resource{ + Create: resourceOpsgenieIncidentTemplateCreate, + Read: resourceOpsgenieIncidentTemplateRead, + Update: resourceOpsgenieIncidentTemplateUpdate, + Delete: resourceOpsgenieIncidentTemplateDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "message": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "tags": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "details": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "priority": { + Type: schema.TypeString, + Required: true, + }, + "impacted_services": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "stakeholder_properties": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "message": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 15000), + }, + }, + }, + }, + }, + } +} + +func resourceOpsgenieIncidentTemplateCreate(d *schema.ResourceData, meta interface{}) error { + client, err := incident.NewClient(meta.(*OpsgenieClient).client.Config) + if err != nil { + return err + } + createRequest := &incident.CreateIncidentTemplateRequest{ + Name: d.Get("name").(string), + Message: d.Get("message").(string), + Description: d.Get("description").(string), + Tags: expandOpsgenieIncidentTemplateTags(d.Get("tags").(*schema.Set)), + Details: expandOpsgenieIncidentTemplateDetails(d.Get("details").(map[string]interface{})), + Priority: incident.Priority(d.Get("priority").(string)), + ImpactedServices: expandOpsgenieIncidentTemplateImpactedServices(d.Get("impacted_services").(*schema.Set)), + StakeholderProperties: expandOpsgenieIncidentTemplateStakeholderProperties(d.Get("stakeholder_properties").([]interface{})), + } + result, err := client.CreateIncidentTemplate(context.Background(), createRequest) + if err != nil { + return err + } + d.SetId(result.IncidentTemplateId) + return resourceOpsgenieIncidentTemplateRead(d, meta) +} + +func resourceOpsgenieIncidentTemplateRead(d *schema.ResourceData, meta interface{}) error { + client, err := incident.NewClient(meta.(*OpsgenieClient).client.Config) + if err != nil { + return err + } + result, err := client.GetIncidentTemplate(context.Background(), &incident.GetIncidentTemplateRequest{}) + if err != nil { + return err + } + if result != nil { + for _, value := range result.IncidentTemplates["incidentTemplates"] { + if d.Id() == value.IncidentTemplateId { + d.Set("name", value.Name) + d.Set("id", value.IncidentTemplateId) + d.Set("message", value.Message) + d.Set("tags", value.Tags) + d.Set("description", value.Description) + d.Set("details", value.Details) + d.Set("priority", value.Priority) + d.Set("stakeholderProperties", value.StakeholderProperties) + d.Set("impactedServices", value.ImpactedServices) + break + } + } + } else { + d.SetId("") + log.Printf("[INFO] Incident template not found") + } + return nil +} + +func resourceOpsgenieIncidentTemplateUpdate(d *schema.ResourceData, meta interface{}) error { + client, err := incident.NewClient(meta.(*OpsgenieClient).client.Config) + if err != nil { + return err + } + updateRequest := &incident.UpdateIncidentTemplateRequest{ + IncidentTemplateId: d.Id(), + Name: d.Get("name").(string), + Message: d.Get("message").(string), + Description: d.Get("description").(string), + Tags: expandOpsgenieIncidentTemplateTags(d.Get("tags").(*schema.Set)), + Details: expandOpsgenieIncidentTemplateDetails(d.Get("details").(map[string]interface{})), + Priority: incident.Priority(d.Get("priority").(string)), + ImpactedServices: expandOpsgenieIncidentTemplateImpactedServices(d.Get("impacted_services").(*schema.Set)), + StakeholderProperties: expandOpsgenieIncidentTemplateStakeholderProperties(d.Get("stakeholder_properties").([]interface{})), + } + _, err = client.UpdateIncidentTemplate(context.Background(), updateRequest) + if err != nil { + return err + } + return nil +} + +func resourceOpsgenieIncidentTemplateDelete(d *schema.ResourceData, meta interface{}) error { + client, err := incident.NewClient(meta.(*OpsgenieClient).client.Config) + if err != nil { + return err + } + deleteRequest := &incident.DeleteIncidentTemplateRequest{IncidentTemplateId: d.Id()} + _, err = client.DeleteIncidentTemplate(context.Background(), deleteRequest) + if err != nil { + return err + } + return nil +} + +func expandOpsgenieIncidentTemplateTags(input *schema.Set) []string { + tags := make([]string, len(input.List())) + if input != nil { + for k, v := range input.List() { + tags[k] = v.(string) + } + } + return tags +} + +func expandOpsgenieIncidentTemplateDetails(input map[string]interface{}) map[string]string { + details := make(map[string]string) + if input != nil { + for k, v := range input { + details[k] = v.(string) + } + } + return details +} + +func expandOpsgenieIncidentTemplateImpactedServices(input *schema.Set) []string { + impactedService := make([]string, len(input.List())) + if input != nil { + for k, v := range input.List() { + impactedService[k] = v.(string) + } + } + return impactedService +} + +func expandOpsgenieIncidentTemplateStakeholderProperties(input []interface{}) incident.StakeholderProperties { + stakeholderProperties := incident.StakeholderProperties{} + if input != nil { + for _, v := range input { + config := v.(map[string]interface{}) + enable := config["enable"].(bool) + stakeholderProperties.Enable = &enable + stakeholderProperties.Message = config["message"].(string) + stakeholderProperties.Description = config["description"].(string) + } + } + return stakeholderProperties +} diff --git a/opsgenie/resource_opsgenie_incident_template_test.go b/opsgenie/resource_opsgenie_incident_template_test.go new file mode 100644 index 00000000..b58dbd00 --- /dev/null +++ b/opsgenie/resource_opsgenie_incident_template_test.go @@ -0,0 +1,146 @@ +package opsgenie + +import ( + "context" + "errors" + "fmt" + "log" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + ogClient "github.com/opsgenie/opsgenie-go-sdk-v2/client" + "github.com/opsgenie/opsgenie-go-sdk-v2/incident" +) + +func init() { + resource.AddTestSweepers("opsgenie_incident_template", &resource.Sweeper{ + Name: "opsgenie_incident_template", + F: testSweepIncidentTemplate, + }) +} + +func testSweepIncidentTemplate(region string) error { + meta, err := sharedConfigForRegion() + if err != nil { + return err + } + client, err := incident.NewClient(meta.(*OpsgenieClient).client.Config) + if err != nil { + return err + } + result, err := client.GetIncidentTemplate(context.Background(), &incident.GetIncidentTemplateRequest{}) + if err != nil { + return err + } + if result != nil { + for _, value := range result.IncidentTemplates["incidentTemplates"] { + if strings.HasPrefix(value.Name, "genietest-incident-template-") { + log.Printf("Destroying incident template %s", value.Name) + deleteRequest := incident.DeleteIncidentTemplateRequest{IncidentTemplateId: value.IncidentTemplateId} + if _, err := client.DeleteIncidentTemplate(context.Background(), &deleteRequest); err != nil { + return err + } + break + } + } + } + return nil +} + +func TestAccOpsGenieIncidentTemplate_basic(t *testing.T) { + config := testAccOpsGenieIncidentTemplate_basic(acctest.RandString(6)) + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testCheckOpsGenieIncidentTemplateDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckOpsGenieIncidentTemplateExists(), + ), + }, + }, + }) +} + +func testCheckOpsGenieIncidentTemplateDestroy(s *terraform.State) error { + client, err := incident.NewClient(testAccProvider.Meta().(*OpsgenieClient).client.Config) + if err != nil { + return err + } + for _, rs := range s.RootModule().Resources { + if rs.Type != "opsgenie_incident_template" { + continue + } + result, err := client.GetIncidentTemplate(context.Background(), &incident.GetIncidentTemplateRequest{}) + if err != nil { + x := err.(*ogClient.ApiError) + if x.StatusCode != 404 { + return errors.New(fmt.Sprintf("Incident template still exists: %s", x.Error())) + } + } else if result != nil { + for _, value := range result.IncidentTemplates["incidentTemplates"] { + if strings.HasPrefix(value.Name, "genietest-incident-template-") { + return fmt.Errorf("incident template still exists(it shouldn't exist)") + } + } + } + } + return nil +} + +func testCheckOpsGenieIncidentTemplateExists() resource.TestCheckFunc { + return func(s *terraform.State) error { + client, err := incident.NewClient(testAccProvider.Meta().(*OpsgenieClient).client.Config) + if err != nil { + return err + } + result, err := client.GetIncidentTemplate(context.Background(), &incident.GetIncidentTemplateRequest{}) + if err != nil && result != nil { + for _, value := range result.IncidentTemplates["incidentTemplates"] { + if strings.HasPrefix(value.Name, "genietest-incident-template-") { + log.Printf("Incident template found.") + return nil + } + } + return fmt.Errorf("incident template does not exist (and it should)") + } else { + return err + } + } +} + +func testAccOpsGenieIncidentTemplate_basic(randomName string) string { + return fmt.Sprintf(` +resource "opsgenie_team" "test" { + name = "genietest-team-%s" + description = "This team deals with all the things" +} +resource "opsgenie_service" "test" { + name = "genietest-service-%s" + team_id = opsgenie_team.test.id +} +resource "opsgenie_incident_template" "test" { + name = "genietest-incident-template-%s" + message = "Incident Message" + priority = "P2" + stakeholder_properties { + enable = true + message = "Stakeholder Message" + description = "Stakeholder Description" + } + tags = ["tag1", "tag2"] + description = "Incident Description" + details = { + key1 = "value1" + key2 = "value2" + } + impacted_services = [ + opsgenie_service.test.id + ] +} +`, randomName, randomName, randomName) +} diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident.go new file mode 100644 index 00000000..c5625fc2 --- /dev/null +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident.go @@ -0,0 +1,171 @@ +package incident + +import ( + "context" + "github.com/opsgenie/opsgenie-go-sdk-v2/client" +) + +type Client struct { + client *client.OpsGenieClient +} + +func NewClient(config *client.Config) (*Client, error) { + opsgenieClient, err := client.NewOpsGenieClient(config) + if err != nil { + return nil, err + } + return &Client{opsgenieClient}, nil +} + +func (c *Client) GetRequestStatus(context context.Context, request *RequestStatusRequest) (*RequestStatusResult, error) { + result := &RequestStatusResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) Create(context context.Context, request *CreateRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) Delete(context context.Context, request *DeleteRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) Get(context context.Context, request *GetRequest) (*GetResult, error) { + result := &GetResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) List(context context.Context, request *ListRequest) (*ListResult, error) { + result := &ListResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) Close(context context.Context, request *CloseRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) AddNote(context context.Context, request *AddNoteRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) AddResponder(context context.Context, request *AddResponderRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) AddTags(context context.Context, request *AddTagsRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) RemoveTags(context context.Context, request *RemoveTagsRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) AddDetails(context context.Context, request *AddDetailsRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) RemoveDetails(context context.Context, request *RemoveDetailsRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) UpdatePriority(context context.Context, request *UpdatePriorityRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) UpdateMessage(context context.Context, request *UpdateMessageRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) UpdateDescription(context context.Context, request *UpdateDescriptionRequest) (*AsyncResult, error) { + result := &AsyncResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) ListLogs(context context.Context, request *ListLogsRequest) (*ListLogsResult, error) { + result := &ListLogsResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) ListNotes(context context.Context, request *ListNotesRequest) (*ListNotesResult, error) { + result := &ListNotesResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template.go new file mode 100644 index 00000000..876b1823 --- /dev/null +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template.go @@ -0,0 +1,35 @@ +package incident + +import "context" + +func (c *Client) CreateIncidentTemplate(context context.Context, request *CreateIncidentTemplateRequest) (*CreateIncidentTemplateResult, error) { + result := &CreateIncidentTemplateResult{} + if err := c.client.Exec(context, request, result); err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) UpdateIncidentTemplate(context context.Context, request *UpdateIncidentTemplateRequest) (*UpdateIncidentTemplateResult, error) { + result := &UpdateIncidentTemplateResult{} + if err := c.client.Exec(context, request, result); err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) DeleteIncidentTemplate(context context.Context, request *DeleteIncidentTemplateRequest) (*DeleteIncidentTemplateResult, error) { + result := &DeleteIncidentTemplateResult{} + if err := c.client.Exec(context, request, result); err != nil { + return nil, err + } + return result, nil +} + +func (c *Client) GetIncidentTemplate(context context.Context, request *GetIncidentTemplateRequest) (*GetIncidentTemplateResult, error) { + result := &GetIncidentTemplateResult{} + if err := c.client.Exec(context, request, result); err != nil { + return nil, err + } + return result, nil +} diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template_request.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template_request.go new file mode 100644 index 00000000..1fff76e7 --- /dev/null +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template_request.go @@ -0,0 +1,207 @@ +package incident + +import ( + "net/http" + "strconv" + + "github.com/opsgenie/opsgenie-go-sdk-v2/client" + "github.com/pkg/errors" +) + +type CreateIncidentTemplateRequest struct { + client.BaseRequest + Name string `json:"name"` + Message string `json:"message"` + Description string `json:"description,omitempty"` + Tags []string `json:"tags,omitempty"` + Details map[string]string `json:"details,omitempty"` + Priority Priority `json:"priority"` + ImpactedServices []string `json:"impactedServices,omitempty"` + StakeholderProperties StakeholderProperties `json:"stakeholderProperties"` +} + +func (r *CreateIncidentTemplateRequest) Validate() error { + if r.Name == "" { + return errors.New("Name property cannot be empty.") + } + if err := validateMessage(r.Message); err != nil { + return err + } + if err := validateDescription(r.Description); err != nil { + return err + } + if err := validatePriority(r.Priority); err != nil { + return err + } + if err := validateImpactedServices(r.ImpactedServices); err != nil { + return err + } + if err := validateStakeholderProperties(r.StakeholderProperties); err != nil { + return err + } + return nil +} + +func (r *CreateIncidentTemplateRequest) ResourcePath() string { + return "v1/incident-templates/" +} + +func (r *CreateIncidentTemplateRequest) Method() string { + return http.MethodPost +} + +type UpdateIncidentTemplateRequest struct { + client.BaseRequest + IncidentTemplateId string `json:"id"` + Name string `json:"name"` + Message string `json:"message"` + Description string `json:"description,omitempty"` + Tags []string `json:"tags,omitempty"` + Details map[string]string `json:"details,omitempty"` + Priority Priority `json:"priority"` + ImpactedServices []string `json:"impactedServices,omitempty"` + StakeholderProperties StakeholderProperties `json:"stakeholderProperties"` +} + +func (r *UpdateIncidentTemplateRequest) Validate() error { + if err := validateIncidentTemplateId(r.IncidentTemplateId); err != nil { + return err + } + if r.Name == "" { + return errors.New("Name property cannot be empty.") + } + if err := validateMessage(r.Message); err != nil { + return err + } + if err := validateDescription(r.Description); err != nil { + return err + } + if err := validatePriority(r.Priority); err != nil { + return err + } + if err := validateImpactedServices(r.ImpactedServices); err != nil { + return err + } + if err := validateStakeholderProperties(r.StakeholderProperties); err != nil { + return err + } + return nil +} + +func (r *UpdateIncidentTemplateRequest) ResourcePath() string { + return "v1/incident-templates/" + r.IncidentTemplateId +} + +func (r *UpdateIncidentTemplateRequest) Method() string { + return http.MethodPut +} + +type DeleteIncidentTemplateRequest struct { + client.BaseRequest + IncidentTemplateId string `json:"id"` +} + +func (r *DeleteIncidentTemplateRequest) Validate() error { + if err := validateIncidentTemplateId(r.IncidentTemplateId); err != nil { + return err + } + return nil +} + +func (r *DeleteIncidentTemplateRequest) ResourcePath() string { + return "v1/incident-templates/" + r.IncidentTemplateId +} + +func (r *DeleteIncidentTemplateRequest) Method() string { + return http.MethodDelete +} + +type GetIncidentTemplateRequest struct { + client.BaseRequest + Limit int + Offset int + Order Order +} + +func (r *GetIncidentTemplateRequest) Validate() error { + return nil +} + +func (r *GetIncidentTemplateRequest) ResourcePath() string { + return "v1/incident-templates" +} + +func (r *GetIncidentTemplateRequest) Method() string { + return http.MethodGet +} + +func (r *GetIncidentTemplateRequest) RequestParams() map[string]string { + params := make(map[string]string) + if r.Limit != 0 { + params["limit"] = strconv.Itoa(r.Limit) + } + if r.Order != "" { + params["order"] = string(r.Order) + } + if r.Offset != 0 { + params["offset"] = strconv.Itoa(r.Offset) + } + return params +} + +type StakeholderProperties struct { + Enable *bool `json:"enable,omitempty"` + Message string `json:"message"` + Description string `json:"description,omitempty"` +} + +func validateMessage(message string) error { + if message == "" { + return errors.New("Message property cannot be empty.") + } else if len(message) > 130 { + return errors.New("Message property cannot be longer than 130 characters.") + } + return nil +} + +func validateDescription(description string) error { + if description != "" && len(description) > 1000 { + return errors.New("Description property cannot be longer than 1000 characters.") + } + return nil +} + +func validatePriority(priority Priority) error { + switch priority { + case P1, P2, P3, P4, P5: + return nil + } + return errors.New("Priority should be one of these: " + + "'P1', 'P2', 'P3', 'P4' and 'P5'") +} + +func validateImpactedServices(impactedServices []string) error { + if len(impactedServices) > 20 { + return errors.New("Impacted services property cannot have services more than 20.") + } + return nil +} + +func validateStakeholderProperties(stakeholderProperties StakeholderProperties) error { + if stakeholderProperties.Message == "" { + return errors.New("Message field of stakeholder property cannot be empty.") + } + if stakeholderProperties.Description != "" && len(stakeholderProperties.Description) > 15000 { + return errors.New("Description field of stakeholder property cannot be longer than 15000 characters.") + } + return nil +} + +func validateIncidentTemplateId(incidentTemplateId string) error { + if incidentTemplateId == "" { + return errors.New("Incident Template Id property cannot be empty.") + } else if len(incidentTemplateId) > 130 { + return errors.New("Incident Template Id property cannot be longer than 130 characters.") + } + return nil +} diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template_result.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template_result.go new file mode 100644 index 00000000..681649c1 --- /dev/null +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/incident_template_result.go @@ -0,0 +1,38 @@ +package incident + +import "github.com/opsgenie/opsgenie-go-sdk-v2/client" + +type TemplateIncident struct { + Name string `json:"name"` + IncidentTemplateId string `json:"id"` + Message string `json:"message"` + Description string `json:"description,omitempty"` + Tags []string `json:"tags,omitempty"` + Details map[string]string `json:"details,omitempty"` + Priority Priority `json:"priority"` + ImpactedServices []string `json:"impactedServices,omitempty"` + StakeholderProperties StakeholderProperties `json:"stakeholderProperties"` +} + +type CreateIncidentTemplateResult struct { + client.ResultMetadata + Result string `json:"result"` + IncidentTemplateId string `json:"id"` +} + +type UpdateIncidentTemplateResult struct { + client.ResultMetadata + Result string `json:"result"` + IncidentTemplateId string `json:"id"` +} + +type DeleteIncidentTemplateResult struct { + client.ResultMetadata + Result string `json:"result"` +} + +type GetIncidentTemplateResult struct { + client.ResultMetadata + IncidentTemplates map[string][]TemplateIncident `json:"data"` + Paging Paging `json:"paging"` +} diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/request.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/request.go new file mode 100644 index 00000000..3bfc6732 --- /dev/null +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/request.go @@ -0,0 +1,795 @@ +package incident + +import ( + "net/http" + "strconv" + "strings" + + "github.com/opsgenie/opsgenie-go-sdk-v2/client" + "github.com/pkg/errors" +) + +type RequestStatusRequest struct { + client.BaseRequest + Id string +} + +func (r *RequestStatusRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + return nil +} + +func (r *RequestStatusRequest) ResourcePath() string { + return "/v1/incidents/requests/" + r.Id +} + +func (r *RequestStatusRequest) Method() string { + return http.MethodGet +} + +type CreateRequest struct { + client.BaseRequest + Message string `json:"message"` + Description string `json:"description,omitempty"` + Responders []Responder `json:"responders,omitempty"` + Tags []string `json:"tags,omitempty"` + Details map[string]string `json:"details,omitempty"` + Priority Priority `json:"priority,omitempty"` + Note string `json:"note,omitempty"` + ServiceId string `json:"serviceId"` + StatusPageEntity *StatusPageEntity `json:"statusPageEntry,omitempty"` + NotifyStakeholders *bool `json:"notifyStakeholders,omitempty"` +} + +type StatusPageEntity struct { + Title string `json:"title,omitempty"` + Description string `json:"description,omitempty"` +} + +func (r *CreateRequest) Validate() error { + if r.Message == "" || r.ServiceId == "" { + return errors.New("Message and ServiceId fields cannot be blank.") + } + if r.StatusPageEntity != nil { + if r.StatusPageEntity.Title == "" { + return errors.New("StatusPageEntity.Title cannot be blank.") + } + } + err := ValidatePriority(r.Priority) + if err != nil { + return err + } + err = validateResponders(r.Responders) + if err != nil { + return err + } + return nil +} + +func (r *CreateRequest) ResourcePath() string { + return "/v1/incidents/create" +} + +func (r *CreateRequest) Method() string { + return http.MethodPost +} + +type DeleteRequest struct { + client.BaseRequest + Id string + Identifier IdentifierType +} + +func (r *DeleteRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *DeleteRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id +} + +func (r *DeleteRequest) Method() string { + return http.MethodDelete +} + +func (r *DeleteRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type GetRequest struct { + client.BaseRequest + Id string + Identifier IdentifierType +} + +func (r *GetRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *GetRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id +} + +func (r *GetRequest) Method() string { + return http.MethodGet +} + +func (r *GetRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + return params +} + +type ListRequest struct { + client.BaseRequest + Limit int + Sort SortField + Offset int + Order Order + Query string +} + +func (r *ListRequest) Validate() error { + if r.Query == "" { + return errors.New("Query field cannot be empty.") + } + return nil +} + +func (r *ListRequest) ResourcePath() string { + return "/v1/incidents" +} + +func (r *ListRequest) Method() string { + return http.MethodGet +} + +func (r *ListRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Limit != 0 { + params["limit"] = strconv.Itoa(r.Limit) + } + if r.Sort != "" { + params["sort"] = string(r.Sort) + } + if r.Offset != 0 { + params["offset"] = strconv.Itoa(r.Offset) + } + if r.Query != "" { + params["query"] = r.Query + + } + if r.Order != "" { + params["order"] = string(r.Order) + + } + return params +} + +type CloseRequest struct { + client.BaseRequest + Id string + Identifier IdentifierType + Note string `json:"note,omitempty"` +} + +func (r *CloseRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *CloseRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/close" +} + +func (r *CloseRequest) Method() string { + return http.MethodPost +} + +func (r *CloseRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type AddNoteRequest struct { + client.BaseRequest + Id string + Identifier IdentifierType + Note string `json:"note"` +} + +func (r *AddNoteRequest) Validate() error { + if r.Id == "" || r.Note == "" { + return errors.New("Incident ID and Note fields cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *AddNoteRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/notes" + +} + +func (r *AddNoteRequest) Method() string { + return http.MethodPost +} + +func (r *AddNoteRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type AddResponderRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string `json:"incidentId"` + Note string `json:"note"` + Responders []Responder `json:"responder"` +} + +func (r *AddResponderRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if len(r.Responders) == 0 { + return errors.New("Responders field cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + err := validateResponders(r.Responders) + if err != nil { + return err + } + return nil +} + +func (r *AddResponderRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/responders" + +} + +func (r *AddResponderRequest) Method() string { + return http.MethodPost +} + +func (r *AddResponderRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type AddTagsRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Note string `json:"note"` + Tags []string `json:"tags"` +} + +func (r *AddTagsRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if len(r.Tags) == 0 { + return errors.New("Tags field cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *AddTagsRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/tags" +} + +func (r *AddTagsRequest) Method() string { + return http.MethodPost +} + +func (r *AddTagsRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type RemoveTagsRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Note string + Tags []string +} + +func (r *RemoveTagsRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if len(r.Tags) == 0 { + return errors.New("Tags field cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *RemoveTagsRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/tags" +} + +func (r *RemoveTagsRequest) Method() string { + return http.MethodDelete +} + +func (r *RemoveTagsRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + //comma separated tag list + params["tags"] = strings.Join(r.Tags[:], ",") + + if r.Note != "" { + params["note"] = r.Note + + } + return params +} + +type AddDetailsRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Note string `json:"note,omitempty"` + Details map[string]string `json:"details"` +} + +func (r *AddDetailsRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if len(r.Details) == 0 { + return errors.New("Details field cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *AddDetailsRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/details" +} + +func (r *AddDetailsRequest) Method() string { + return http.MethodPost +} + +func (r *AddDetailsRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type RemoveDetailsRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Note string + Keys []string +} + +func (r *RemoveDetailsRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if len(r.Keys) == 0 { + return errors.New("Details field cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *RemoveDetailsRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/details" +} + +func (r *RemoveDetailsRequest) Method() string { + return http.MethodDelete +} + +func (r *RemoveDetailsRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + //comma separated key list + params["keys"] = strings.Join(r.Keys[:], ",") + + if r.Note != "" { + params["note"] = r.Note + + } + return params +} + +type UpdatePriorityRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Priority Priority `json:"priority"` +} + +func (r *UpdatePriorityRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + err := ValidatePriority(r.Priority) + if err != nil { + return err + } + return nil +} + +func (r *UpdatePriorityRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/priority" + +} + +func (r *UpdatePriorityRequest) Method() string { + return http.MethodPut +} + +func (r *UpdatePriorityRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type UpdateMessageRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Message string `json:"message"` +} + +func (r *UpdateMessageRequest) Validate() error { + if r.Id == "" || r.Message == "" { + return errors.New("Incident ID and Message fields cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *UpdateMessageRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/message" + +} + +func (r *UpdateMessageRequest) Method() string { + return http.MethodPost +} + +func (r *UpdateMessageRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type UpdateDescriptionRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Description string `json:"description"` +} + +func (r *UpdateDescriptionRequest) Validate() error { + if r.Id == "" || r.Description == "" { + return errors.New("Incident ID and Description fields cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *UpdateDescriptionRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/description" +} + +func (r *UpdateDescriptionRequest) Method() string { + return http.MethodPost +} + +func (r *UpdateDescriptionRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + return params +} + +type ListLogsRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Limit int + Offset int + Order Order + Direction string +} + +func (r *ListLogsRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *ListLogsRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/logs" +} + +func (r *ListLogsRequest) Method() string { + return http.MethodGet +} + +func (r *ListLogsRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + if r.Limit != 0 { + params["limit"] = strconv.Itoa(r.Limit) + } + if r.Offset != 0 { + params["offset"] = strconv.Itoa(r.Offset) + } + if r.Direction != "" { + params["direction"] = r.Direction + + } + if r.Order != "" { + params["order"] = string(r.Order) + } + + return params +} + +type ListNotesRequest struct { + client.BaseRequest + Identifier IdentifierType + Id string + Limit int + Offset int + Order Order + Direction string +} + +func (r *ListNotesRequest) Validate() error { + if r.Id == "" { + return errors.New("Incident ID cannot be blank.") + } + if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny { + return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.") + } + return nil +} + +func (r *ListNotesRequest) ResourcePath() string { + return "/v1/incidents/" + r.Id + "/notes" + +} + +func (r *ListNotesRequest) Method() string { + return http.MethodGet +} + +func (r *ListNotesRequest) RequestParams() map[string]string { + + params := make(map[string]string) + + if r.Identifier == Tiny { + params["identifierType"] = "tiny" + } else { + params["identifierType"] = "id" + } + + if r.Limit != 0 { + params["limit"] = strconv.Itoa(r.Limit) + } + if r.Offset != 0 { + params["offset"] = strconv.Itoa(r.Offset) + } + if r.Direction != "" { + params["direction"] = r.Direction + + } + if r.Order != "" { + params["order"] = string(r.Order) + } + + return params +} + +type IdentifierType string +type ResponderType string +type Priority string +type Order string +type SortField string + +const ( + Id IdentifierType = "id" + Tiny IdentifierType = "tiny" + + User ResponderType = "user" + Team ResponderType = "team" + + P1 Priority = "P1" + P2 Priority = "P2" + P3 Priority = "P3" + P4 Priority = "P4" + P5 Priority = "P5" + + Asc Order = "asc" + Desc Order = "desc" + + CreatedAt SortField = "createdAt" + TinyId SortField = "tinyId" + Message SortField = "message" + Status SortField = "status" + IsSeen SortField = "isSeen" + Owner SortField = "owner" +) + +type Responder struct { + Type ResponderType `json:"type,omitempty"` + Name string `json:"name,omitempty"` + Id string `json:"id,omitempty"` +} + +func validateResponders(responders []Responder) error { + for _, responder := range responders { + if responder.Type == "" { + return errors.New("Responder type cannot be empty.") + } + if !(responder.Type == User || responder.Type == Team) { + return errors.New("Responder type should be one of these: 'User', 'Team'.") + } + if responder.Name == "" && responder.Id == "" { + return errors.New("For responder either name or id must be provided.") + } + } + return nil +} + +func ValidatePriority(priority Priority) error { + switch priority { + case P1, P2, P3, P4, P5, "": + return nil + } + return errors.New("Priority should be one of these: " + + "'P1', 'P2', 'P3', 'P4' and 'P5' or empty") +} diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/result.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/result.go new file mode 100644 index 00000000..b8d35e7c --- /dev/null +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/incident/result.go @@ -0,0 +1,82 @@ +package incident + +import ( + "github.com/opsgenie/opsgenie-go-sdk-v2/client" + "time" +) + +type Incident struct { + Id string `json:"id"` + ServiceId string `json:"serviceId"` + TinyId string `json:"tinyId"` + Message string `json:"message"` + Status string `json:"status"` + Tags []string `json:"tags"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + Priority Priority `json:"priority"` + OwnerTeam string `json:"ownerTeam"` + Responders []Responder `json:"responders"` + ExtraProperties map[string]string `json:"extraProperties"` +} + +type RequestStatusResult struct { + client.ResultMetadata + Success bool `json:"success"` + Action string `json:"action"` + ProcessedAt string `json:"processedAt"` + IntegrationId string `json:"integrationId"` + IsSuccess bool `json:"isSuccess"` + Status string `json:"status"` + IncidentId string `json:"incidentId"` +} + +type AsyncResult struct { + client.ResultMetadata + Result string `json:"result"` +} + +type GetResult struct { + client.ResultMetadata + Incident +} + +type ListResult struct { + client.ResultMetadata + Incidents []Incident `json:"data"` + Paging Paging `json:"paging"` +} + +type LogResult struct { + Log string `json:"log"` + Type string `json:"type"` + Owner string `json:"owner"` + CreatedAt time.Time `json:"createdAt"` + Offset string `json:"offset"` +} + +type ListLogsResult struct { + client.ResultMetadata + Logs []LogResult `json:"data"` + Paging Paging `json:"paging"` +} + +type NoteResult struct { + Note string `json:"note"` + Owner string `json:"owner"` + CreatedAt time.Time `json:"createdAt"` + Offset string `json:"offset"` +} + +type ListNotesResult struct { + client.ResultMetadata + Notes []NoteResult `json:"data"` + Paging Paging `json:"paging"` +} + +type Paging struct { + Next string `json:"next"` + Prev string `json:"prev"` + First string `json:"first"` + Last string `json:"last"` +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 09c75df6..eed0195b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -215,13 +215,14 @@ github.com/mitchellh/mapstructure github.com/mitchellh/reflectwalk # github.com/oklog/run v1.0.0 github.com/oklog/run -# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200820123717-3bcc8ea32b68 +# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac ## explicit github.com/opsgenie/opsgenie-go-sdk-v2/alert github.com/opsgenie/opsgenie-go-sdk-v2/client github.com/opsgenie/opsgenie-go-sdk-v2/contact github.com/opsgenie/opsgenie-go-sdk-v2/escalation github.com/opsgenie/opsgenie-go-sdk-v2/heartbeat +github.com/opsgenie/opsgenie-go-sdk-v2/incident github.com/opsgenie/opsgenie-go-sdk-v2/integration github.com/opsgenie/opsgenie-go-sdk-v2/maintenance github.com/opsgenie/opsgenie-go-sdk-v2/notification diff --git a/website/docs/r/incident_template.html.markdown b/website/docs/r/incident_template.html.markdown new file mode 100644 index 00000000..0fc2761c --- /dev/null +++ b/website/docs/r/incident_template.html.markdown @@ -0,0 +1,82 @@ +--- +layout: "opsgenie" +page_title: "Opsgenie: opsgenie_incident_template" +sidebar_current: "docs-opsgenie-resource-incident-template" +description: |- + Manages an Incident Template within Opsgenie. +--- + +# opsgenie\_incident_template + +Manages an Incident Template within Opsgenie. + +## Example Usage + +```hcl +resource "opsgenie_team" "test" { + name = "genietest-team" + description = "This team deals with all the things" +} +resource "opsgenie_service" "test" { + name = "genietest-service" + team_id = opsgenie_team.test.id +} +resource "opsgenie_incident_template" "test" { + name = "genietest-incident-template" + message = "Incident Message" + priority = "P2" + stakeholder_properties { + enable = true + message = "Stakeholder Message" + description = "Stakeholder Description" + } + tags = ["tag1", "tag2"] + description = "Incident Description" + details = { + key1 = "value1" + key2 = "value2" + } + impacted_services = [ + opsgenie_service.test.id + ] +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` (Required) Name of the incident template. + +* `message` (Required) Message of the related incident template. This field must not be longer than 130 characters. + +* `description` (Optional) Description field of the incident template. This field must not be longer than 10000 characters. + +* `tags` (Optional) Tags of the incident template. + +* `details` (Optional) Map of key-value pairs to use as custom properties of the incident template. This field must not be longer than 8000 characters. + +* `priority` (Required) Priority level of the incident. Possible values are P1, P2, P3, P4 and P5. + +* `impactedServices` (Optional) Impacted services of incident template. Maximum 20 services. + +* `stakeholderProperties` (Required) + + * `enable` (Optional) Option to enable stakeholder notifications.Default value is true. + + * `message` (Required) Message that is to be passed to audience that is generally used to provide a content information about the alert. + + * `description` (Optional) Description that is generally used to provide a detailed information about the alert. This field must not be longer than 15000 characters. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Opsgenie Incident Template. + +## Import + +Service can be imported using the `id`, e.g. + +`$ terraform import opsgenie_incident_template.test 812be1a1-32c8-4666-a7fb-03ecc385106c` diff --git a/website/opsgenie.erb b/website/opsgenie.erb index 4c8851f1..327b8ff0 100644 --- a/website/opsgenie.erb +++ b/website/opsgenie.erb @@ -83,11 +83,12 @@ > opsgenie_notification_rule - > opsgenie_alert_policy - + > + opsgenie_incident_template +