opsgenie / terraform-provider-opsgenie

Terraform OpsGenie provider
https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs
Mozilla Public License 2.0
101 stars 134 forks source link

Duplicated alerts in opsgenie_integration_action #369

Open OliverKlette85 opened 1 year ago

OliverKlette85 commented 1 year ago

Terraform Version

Terraform v1.4.2 on darwin_amd64

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_providers {
    opsgenie = {
      source  = "opsgenie/opsgenie"
      version = "0.6.20"
    }
  }

  required_version = "= 1.4.2"
}

# export OPSGENIE_API_KEY environment variable
provider "opsgenie" {}

resource "opsgenie_email_integration" "test" {
  name           = "mail-test"
  email_username = "test"
}

resource "opsgenie_integration_action" "actions" {
  integration_id = opsgenie_email_integration.test.id

  create {
    name  = "Test 1"
    source = "Email"
    note = "Test 1"

    filter {
      type = "match-any-condition"
      conditions {
        field          = "subject"
        operation      = "contains"
        expected_value = "test"
      }
      conditions {
        field          = "From Address"
        operation      = "contains"
        expected_value = "test@test.com"
      }
    }
    responders {
      id   = "ff2c2f8f-54d7-4071-92a9-f6cac5d8b076"
      type = "team"
    }
  }

  create {
    name  = "Test 2"
    description = "Test"
    note = "Test"
    source = "Email test 2"

    filter {
      type = "match-any-condition"
      conditions {
        field          = "From Address"
        operation      = "contains"
        expected_value = "test@test.com"
      }
      conditions {
        field          = "subject"
        operation      = "contains"
        expected_value = "test"
      }
    }
    responders {
      id   = "a5a077b1-dc13-45de-a961-9a91ddda1836"
      type = "team"
    }
  }
}

Expected Behavior

The terraform code should create a opsgenie_integration_action with two alerts ("Test 1" and "Test 2") if you run it initially. A second terraform plan/apply shouldn't show/perform any changes.

Actual Behavior

When you apply the code initially it creates the opsgenie_integration_action with the two alerts as expected, but if you plan it a second time, it shows unexpected changes (resorting of the alerts). If you apply the changes you can see both alerts created twice with the same names an contents (see screenshots). If you really doing a change (like changing a value of a field), it just duplicates the alert which wasn't changed.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. check integration in opsgenie image
  3. terraform apply again (unexpected reordering)
  4. check integration in opsgenie again image

Important Factoids

The unexpected behaviour only happens if the responders argument is set for the alerts.

mjooz commented 1 year ago

I got the same behaviour. Same versions of provider and TF.

TomashWroblewski commented 1 year ago

I got the same behaviour: v0.6.20

exeding commented 1 year ago

same behaviour with v0.6.24 on my end.

martinlechner1 commented 3 months ago

Opsgenie fixed the underlying bug in their API — This should be resolved now. Can anyone try to reproduce?

exeding commented 3 months ago

just redeployed via terraform and it looks good. thx for the update