From 10279e89c40076d3ceca286e91af03afc60ca43d Mon Sep 17 00:00:00 2001 From: jfreedman Date: Fri, 22 Sep 2023 09:26:53 +0100 Subject: [PATCH 1/2] ignore Jetbrains project files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 09b996f6..e2a7b65e 100644 --- a/.gitignore +++ b/.gitignore @@ -89,6 +89,7 @@ cmake-build-*/ # File-based project format *.iws +*.iml # IntelliJ out/ From 501ecc786db194449e9895c7c27784b6d41e9181 Mon Sep 17 00:00:00 2001 From: jonfreedman Date: Fri, 22 Sep 2023 15:27:47 +0100 Subject: [PATCH 2/2] fix #398 specify order for opsgenie_alert_policy, use change-order endpoint to apply see https://docs.opsgenie.com/docs/alert-and-notification-policy-api#change-policy-order --- opsgenie/resource_opsgenie_alert_policy.go | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/opsgenie/resource_opsgenie_alert_policy.go b/opsgenie/resource_opsgenie_alert_policy.go index c4d2c476..6dbb82a8 100644 --- a/opsgenie/resource_opsgenie_alert_policy.go +++ b/opsgenie/resource_opsgenie_alert_policy.go @@ -279,6 +279,11 @@ func resourceOpsGenieAlertPolicy() *schema.Resource { Optional: true, ValidateFunc: validation.StringInSlice([]string{"P1", "P2", "P3", "P4", "P5"}, false), }, + "order": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + }, }, } } @@ -289,6 +294,8 @@ func resourceOpsGenieAlertPolicyCreate(ctx context.Context, d *schema.ResourceDa return diag.FromErr(err) } + name := d.Get("name").(string) + team_id := d.Get("team_id").(string) message := d.Get("message").(string) continue_policy := d.Get("continue_policy").(bool) alias := d.Get("alias").(string) @@ -300,6 +307,7 @@ func resourceOpsGenieAlertPolicyCreate(ctx context.Context, d *schema.ResourceDa ignore_original_responders := d.Get("ignore_original_responders").(bool) ignore_original_tags := d.Get("ignore_original_tags").(bool) priority := d.Get("priority").(string) + order := d.Get("order").(int) createRequest := &policy.CreateAlertPolicyRequest{ MainFields: *expandOpsGenieAlertPolicyRequestMainFields(d), @@ -322,7 +330,7 @@ func resourceOpsGenieAlertPolicyCreate(ctx context.Context, d *schema.ResourceDa createRequest.Responders = expandOpsGenieAlertPolicyResponders(d) } - log.Printf("[INFO] Creating Alert Policy '%s'", d.Get("name").(string)) + log.Printf("[INFO] Creating Alert Policy '%s'", name) result, err := client.CreateAlertPolicy(context.Background(), createRequest) if err != nil { return diag.FromErr(err) @@ -330,6 +338,19 @@ func resourceOpsGenieAlertPolicyCreate(ctx context.Context, d *schema.ResourceDa d.SetId(result.Id) + orderRequest := &policy.ChangeOrderRequest{ + Id: result.Id, + TeamId: team_id, + Type: "alert", + TargetIndex: order, + } + + log.Printf("[INFO] Setting Alert Policy '%s' order to '%d'", name, order) + _, err = client.ChangeOrder(context.Background(), orderRequest) + if err != nil { + return diag.FromErr(err) + } + return resourceOpsGenieAlertPolicyRead(ctx, d, meta) }