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

opsgenie_integration_action does not set key despite field being set to "extra-properties" #322

Closed
upstream-dmahlberg opened this issue Aug 9, 2022 · 11 comments · Fixed by #411

Comments

@upstream-dmahlberg
Copy link

upstream-dmahlberg commented Aug 9, 2022

Terraform Version

Terraform v1.1.9
on linux_amd64

  • provider registry.terraform.io/opsgenie/opsgenie v0.6.10

Affected Resource(s)

  • opsgenie_integration_action

Terraform Configuration Files

resource "opsgenie_integration_action" "grafana" {
  integration_id = opsgenie_api_integration.grafana.id
  #P1
  create {
    name     = "Create Alert"
    message  = "[Grafana]: {{message}}"
    note     = "{{note}}"
    alias    = "{{monitor_id}}"
    source   = "{{source}}"
    entity   = "{{entity}}"
    priority = "P1"

    filter {
      type = "match-any-condition"
      conditions {
        field          = "extra-properties"
        key            = "severity"
        operation      = "contains"
        expected_value = "critical"
        not            = false
      }
    }
  }
  #P3
  create {
    name     = "Create Alert Warning"
    message  = "[Grafana]: {{message}}"
    note     = "{{note}}"
    alias    = "{{monitor_id}}"
    source   = "{{source}}"
    entity   = "{{entity}}"
    priority = "P3"

    filter {
      type = "match-any-condition"
      conditions {
        field          = "extra-properties"
        key            = "severity"
        operation      = "contains"
        expected_value = "warning"
        not            = false
      }
    }
  }
  #P4 Default Alerts
  create {
    name     = "Create Alert Default"
    message  = "[Grafana]: {{message}}"
    note     = "{{note}}"
    alias    = "{{monitor_id}}"
    source   = "{{source}}"
    entity   = "{{entity}}"
    priority = "P4"

    filter {
      type = "match-all"
    }
  }
  close {
    name  = "Close Alert"
    type  = "close"
    alias = "{{monitor_id}}"
    note  = "{{note}}"
    order = 1

    filter {
      type = "match-all"
    }
  }
}

Expected Behavior

OpsGenie Integration should have a filter looking like this
image

Actual Behavior

Opsgenie Integration has a filter looking like this:
image

Steps to Reproduce

See code above

Important Factoids

To put it bluntly, the whole provider is a complete mess. The documentation lacks proper real-world examples, and is full of bugs and inconsitencies. I dare you to write some TF code, run apply, then run plan / apply again - you WILL see several changes pending despite no code has been changed. Very disappointing from a paying customer's perspective.

@Kerwood
Copy link

Kerwood commented Feb 7, 2023

To put it bluntly, the whole provider is a complete mess. The documentation lacks proper real-world examples, and is full of bugs and inconsitencies.

Agree..

Very disappointing from a paying customer's perspective.

Absolutely agree. We are also a paying customer and deploy our infrastructure as code. This has been a real struggle with Opsgenie, and still is. Current issues are that integration actions and alert policies change every time you do a plan, which is a mess when you have jobs that run your IaaC.
Concidering giving PagerDuty a go.

If you use IaaC Opsgenie is not the way to go.

@upstream-dmahlberg
Copy link
Author

We ended up deleting our Terraform code and configure OpsGenie by hand now since that caused way less trouble than our IaaC approach. This is quite frustrating as the fact that OpsGenie offers a terraform provider for configuration was one of the main reasons causing us to choose OpsGenie in the first place. Lesson learned...

@Kerwood
Copy link

Kerwood commented Feb 7, 2023

Haha, yes.. Remember to check issues and PRs :D

@nvanheuverzwijn
Copy link
Contributor

Alright, for everyone coming here and saying this is bugged... you are right. It's completely bugged. However, here is a fix or a workaround I should say.

I debugged their code to the bone. I went through all 7 gates of hell to retrieve this information.

The first thing you want to do, is to get rid of the key value. That's right. It's useless. Don't even bother adding this value, it does not serve any purpose but to annoy you with validation that when key is there, field needs to be extra-properties.

The second thing you want to do, is to change your field type from extra-properties to extra_properties_key_prefix-KEYNAME. Yes, that's right. That's all you have to do and surprise, it will work. But why ? This field type is not documented, what the hell is this ? That's right, it's not documented, it's not even in the code but that's what the server returns when you set extra properties via the GUI and you ask what the value is.

Let's say your condition is this :

conditions {
                  expected_value = "infra"
                  field          = "extra-properties"
                  key            = "owner"
                  not            = false
                  operation      = "equals"
                }

You want to have this :

conditions {
                  expected_value = "infra"
                  field          = "extra_properties_key_prefix-owner"
                  not            = false
                  operation      = "equals"
                }

And it will work.

@nvanheuverzwijn
Copy link
Contributor

@Kerwood @upstream-dmahlberg I found the workaround if you guys are interested.

@nvanheuverzwijn
Copy link
Contributor

This issue : sensu-plugins/sensu-plugins-opsgenie#51 is also relevant and the fact that the key value is not documented in the integration api. The problem is that the conditions block is a copy paste of the team routing rules conditions block. It's not the same type in the api but considered the same type in the provider.

@upstream-dmahlberg
Copy link
Author

Holy sh..... I don't even want to imagine what kind of hoops you had to jump through to get to the bottom of this. I salute you, kind stranger.

@nvanheuverzwijn
Copy link
Contributor

@upstream-dmahlberg I did walk on the surface of the sun. It wasn't that bad. They do have good integration test so it was easy to test things out.

@koushik-swaminathan
Copy link
Contributor

Hi @nvanheuverzwijn @upstream-dmahlberg, sorry about the experience you've had with the terraform provider. We're trying to fix all the issues actively, thank you for your contributions :)

@upstream-dmahlberg
Copy link
Author

Hi @koushik-swaminathan , with all due respect - this post was created about 1,5 yrs ago. Altough I appreciate that someone is taking care of this, we seized using the terraform provider and have moved on a long time ago.

@nvanheuverzwijn
Copy link
Contributor

@koushik-swaminathan can you merge the MR ?

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