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

Can't create opsgenie_service_incident_rule : 422 response #454

Closed
ppiotrlach opened this issue Oct 16, 2024 · 5 comments · May be fixed by #455
Closed

Can't create opsgenie_service_incident_rule : 422 response #454

ppiotrlach opened this issue Oct 16, 2024 · 5 comments · May be fixed by #455

Comments

@ppiotrlach
Copy link

Terraform Version

  • opsgenie/opsgenie v0.6.37

Affected Resource(s)

  • opsgenie_service_incident_rule

Terraform Configuration Files

resource "opsgenie_service" "empty" {
  name = "Empty Service"
  description = "Terraform requires an associated service to create incident rules, unlike the Opsgenie GUI, which allows rule creation without a service. This service fulfills that requirement and serves as work-around to create such incident rules."
  team_id = data.opsgenie_team.team.id
}

resource "opsgenie_service_incident_rule" "manual_reports_rule" {
  service_id = opsgenie_service.empty.id
  incident_rule {
    condition_match_type = "match-all-conditions"
    conditions {
      field          = "priority"
      not            = false
      operation      = "equals"
      expected_value = "P1"
    }
    conditions {
      field          = "tags"
      not            = false
      operation      = "contains"
      expected_value = "manual"
    }

    incident_properties {
      message     = "{{message}}"
      description = "{{description}}"
      priority    = "P1"
      tags        = ["{{tags}}"]

      stakeholder_properties {
        message     = "{{message}}"
        description = "{{description}}"
        enable      = "true"
      }
    }
  }
}

Expected Behavior

New incident rule should be created.

Actual Behavior

opsgenie_service_incident_rule.manual_reports_rule: Creating...
╷
│ Error: Error occurred with Status code: 422, Message: Request body is not processable. Please check the errors., Took: 0.004000, RequestId: 2d0929fa-c74e-4cd6-9d4c-0f50729ed0de, Error Detail: map[incidentRule:Request property [incidentRule] may not be empty.]
│ 
│   with opsgenie_service_incident_rule.manual_reports_rule,
│   on incidentrules.tf line [91](https://gitlab.xxx.com/opsgenie/opsgenie-alerting/some-team/-/jobs/8390788#L91), in resource "opsgenie_service_incident_rule" "manual_reports_rule":
│   91: resource "opsgenie_service_incident_rule" "manual_reports_rule" {

I also have tried without some of optional fields but result was all the same.

Additional notes

I was updating multiple Opsgenie repositories across our organization with mentioned changes. MRs which were merged previous week were applied without issues, afterwards we started experiencing this issue. Seems like something have changed in Opsgenie API during this period?

@T0tt1
Copy link

T0tt1 commented Oct 16, 2024

I have the same problem.

Looks like API request expected by OG API has changed.
Please help!

Talking with the support currently.
According to https://docs.opsgenie.com/docs/service-incident-rules-api

expected body is

curl -X POST "https://api.opsgenie.com/v1/services/<OBFUSCATED>/incident-rules" \
-H "Authorization: GenieKey <OBFUSCATED>" \
-H "Content-Type: application/json" \
-d '{
  "conditionMatchType": "match-all-conditions",
  "conditions": [{
      "expectedValue": "Incident",
      "operation": "contains",
      "not": false,
      "field": "message"
  }],
  "incidentProperties": {
      "message": "Incident Message",
      "description": "Incident Description",
      "tags": ["Tag1", "Tag2"],
      "priority": "P4",
      "stakeholderProperties": {
          "enable": true,
          "message": "Stakeholder Message",
          "description": "Stakeholder Description"
      }
  }
}'

However this returns 422. Support asked to add one layer of abstraction in the payload and this below then returns 200 but we need to work on this to reflect that change to the go file for TF module:

curl -X POST "https://api.opsgenie.com/v1/services/<OBFUSCATED>/incident-rules" \
-H "Authorization: GenieKey <OBFUSCATED>" \
-H "Content-Type: application/json" \
-d '{
 "incidentRule": { <<<--- This line added
  "conditionMatchType": "match-all-conditions",
  "conditions": [{
      "expectedValue": "Incident",
      "operation": "contains",
      "not": false,
      "field": "message"
  }],
  "incidentProperties": {
      "message": "Incident Message",
      "description": "Incident Description",
      "tags": ["Tag1", "Tag2"],
      "priority": "P4",
      "stakeholderProperties": {
          "enable": true,
          "message": "Stakeholder Message",
          "description": "Stakeholder Description"
      }
   }
  } <<<--- ends here
}'

@T0tt1
Copy link

T0tt1 commented Oct 16, 2024

Maybe Solution would be something similar?
#455

@edletifov
Copy link

This has been accepted as a bug by Atlassian after P1 for a customer has been reported by us, so perhaps fixing it here is not correct, as instead it may be fixed by Atlassian: https://jira.atlassian.com/browse/OPSGENIE-2359

@T0tt1
Copy link

T0tt1 commented Oct 18, 2024

This has been accepted as a bug by Atlassian after P1 for a customer has been reported by us, so perhaps fixing it here is not correct, as instead it may be fixed by Atlassian: https://jira.atlassian.com/browse/OPSGENIE-2359

Whatever works for them, sir. I just tried to help but still, they have the full context of what has happened and how to mitigate it. Proposal here maybe not the cleanest and long term solution, more on setting fire off. :)

@ppiotrlach
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants