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

Control order of Alert Policies #223

Closed
axdotl opened this issue Feb 16, 2021 · 15 comments · May be fixed by #388
Closed

Control order of Alert Policies #223

axdotl opened this issue Feb 16, 2021 · 15 comments · May be fixed by #388

Comments

@axdotl
Copy link

axdotl commented Feb 16, 2021

Hi there,

this is more a feature request than an issue report.

Terraform Version

0.14.3

Affected Resource(s)

  • opsgenie_alert_policy

Terraform Configuration Files

resource "opsgenie_alert_policy" "test" {
  name               = "Test"
  policy_description = "This is an example policy"
  message            = "{{message}}"

  responders {
    type = "team"
    id   = opsgenie_team.test.id
  }

  filter {}
}

Debug Output

n/a

Panic Output

n/a

Expected Behavior

It would be great to have control about the policy order.
Policies retrieved from WebAPI /webapi/policies have an element order.

{
    "policyType": "alert",
    "description": "This is an example policy",
    "name": "Test",
    "teamId": "",
    "enabled": true,
    "order": 1.0,
    "conditionMatchType": 0,
    "message": "{{message}}",

    "responders": [
        {
            "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
            "type": "team",
            "name": "Test"
        }
    ]
}

Actual Behavior

It is not possible to define the order of (global) policies. As a result, one has to sort the policies manually.

Steps to Reproduce

n/a

Important Factoids

n/a

References

n/a

@axdotl
Copy link
Author

axdotl commented Oct 22, 2021

@ffahri Sorry for bothering you. Can you help us with this or is the maintenance of this project somehow on-hold?

@emmahsax
Copy link

I think #191 is similar.

@gdlx
Copy link

gdlx commented Feb 8, 2023

@emmahsax No, #191 is about conditions order inside a policy, not policies order.

@emmahsax
Copy link

emmahsax commented Feb 8, 2023

@emmahsax No, #191 is about conditions order inside a policy, not policies order.

Okay. I just glanced briefly, not in detail... just saw they were both ordering issues.

@gdlx
Copy link

gdlx commented Feb 8, 2023

@axdotl Looking at the policy API doc, the order can't be set when creating/updating a policy but only through a specific request: https://docs.opsgenie.com/docs/alert-and-notification-policy-api#change-policy-order

It's a bad API design leaded by the UI needs (you create the policy first, then change its order).

Not sure if the clean Terraform way to handle this should be to hide the second request behind the same alert policy resource, or to create a specific "alert policy order" resource.

Both looks dirty to me in their respective way, but as policies order may have a real impact on the result, I think it's important to fix this.

@axdotl
Copy link
Author

axdotl commented Feb 9, 2023

@gdlx Thanks for this investigation. You're right it's again a situation where the Opsgenie API design is not that great.

Based on your proposals I think the least dirty way is to introduce a new policy_order resource where one can reference existing policies.

@gdlx
Copy link

gdlx commented Feb 9, 2023

Based on your proposals I think the least dirty way is to introduce a new policy_order resource where one can reference existing policies.

@axdotl I tended to agree but looking at the structure (long time since I coded for a TF provider), I think keeping a single resource (well, actually 2 with notification policies, but I'm not sure the order is as much important) may be better since there's no actual resource behind the change-order endpoint, so TF would have nothing with an ID to actually create/update/delete and store in the tfstate: at the end it's just a property in the policy itself.

@gdlx
Copy link

gdlx commented Feb 10, 2023

This is actually worse than I thought since, unlike the WebAPI, the Policy API used by Terraform does not provide the order in the policy data.
It's only given in the policies list.
That means you also have to make an extra request to read the order 😩

@gdlx
Copy link

gdlx commented Jun 30, 2023

@axdotl you may want to give a try: #388

@agoel2-atlassian
Copy link

At present, the GET Api https://docs.opsgenie.com/docs/alert-and-notification-policy-api#get-policy doesn't provide us the attribute of order. So we will not be able to support this request in terraform.

1 similar comment
@agoel2-atlassian
Copy link

At present, the GET Api https://docs.opsgenie.com/docs/alert-and-notification-policy-api#get-policy doesn't provide us the attribute of order. So we will not be able to support this request in terraform.

@gdlx
Copy link

gdlx commented Jul 6, 2023

@agoel2-atlassian The order is provided by the policies list: https://docs.opsgenie.com/docs/alert-and-notification-policy-api#list-alert-policies

That's what I've used in #388.

Order has a strong impact on policies behavior. Not handling this almost prevents managing policies through terraform.

@Shadow6363
Copy link

@agoel2-atlassian would it be possible to reopen this issue? This is a significant blocker to us defining alert policies in Terraform and it seems like gdx' PR would address the use case.

@gdlx
Copy link

gdlx commented Mar 10, 2024

Looks like they closed it without even noting there's a PR fixing it.
They didn't even review the PR.

@jonswar
Copy link

jonswar commented Jun 3, 2024

@agoel2-atlassian pinging again. #388 appears to address your concern, can you take a look?

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

Successfully merging a pull request may close this issue.

6 participants