opsgenie / terraform-provider-opsgenie

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

opsgenie_service_incident_rule cannot detect manually deleted rules #365

Closed bahram-cdt closed 1 year ago

bahram-cdt commented 1 year ago

Hi there,

TL/DR:

The opsgenie_service_incident_rule resource cannot detect if any managed rule is deleted manually from the OpsGenie console. If you delete any rule managed by terraform provider it still shows as existing upon plan or apply.

Terraform Version

Terraform v0.14.11 (Same behaviour on latest version)

Provider version

opsgenie/opsgenie: 0.6.20

Affected Resource(s)

Terraform Configuration Files


resource "opsgenie_team" "this" {
  name                     = "test-team"
  description              = "Sample description"
  delete_default_resources = true
}

resource "opsgenie_service" "this" {
  name        = "test-service"
  team_id     = opsgenie_team.this.id
  description = "Example service"
}

resource "opsgenie_service_incident_rule" "this" {
  service_id = opsgenie_service.this.id
  incident_rule {
    condition_match_type = "match-all-conditions"

    conditions {
      expected_value = "test-service"
      field          = "tags"
      not            = false
      operation      = "contains"
    }

    incident_properties {
      description = "test description"
      message     = "test message"
      priority    = "P1"
      tags = [
        "is-incident",
        "{{tags}}",
      ]

      details = "Some more details"

      stakeholder_properties {
        message     = "Message for stakeholders"
        description = "Stake holders description"
        enable      = "true"
      }
    }
  }
}

Expected Behavior

As the rule is deleted manually, the terraform apply should detect the rule as not existing and start destroying the resource by removing it from the state.

Actual Behavior

Terraform apply or plan shows the rule still exist and exists without any change detected. It will only throw error when the resource is commented out (or removed) from the code and start complaining like this:

Error: Error occurred with Status code: 404, Message: IncidentRollupRule with id [XXXXXXXX] does not exist., Took: 0.036000, RequestId: XXXXXX

Releasing state lock. This may take a few moments...
ERRO[0225] 1 error occurred:
    * exit status 1

Steps to Reproduce

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

  1. terraform apply
  2. Wait for the incident rule to be created in the OpsGenie console
  3. Delete the incident rule from OpsGenie manually
  4. Run terraform apply again. NO CHANGES ARE DETECTED!
  5. Comment out the opsgenie_service_incident_rule from the terraform code
  6. Run terraform apply again
  7. It tries to destroy the incident rule but it fails with the mentioned error Error: Error occurred with Status code: 404, Message: IncidentRollupRule with id [XXXXXXXX] does not exist

References

Could not find any issue raised about this so I am reporting it here.

arjunrajpal commented 1 year ago

This issue has been fixed. It is available in v0.6.29.