opsgenie / terraform-provider-opsgenie

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

integration_action requires filter and conditions #406

Closed khalidsheikh closed 10 months ago

khalidsheikh commented 10 months ago

Hi there,

Terraform version is:

Terraform v1.6.2 on darwin_arm64

Affected resources are opsgenie_integration_action which don't seem to create correctly. According to the documentation filters and conditions are optional, however it seems to force you to use them.

Also, when creating multiple actions like create, close, and acknowledge not all of them are created.

resource "opsgenie_api_integration" "elastalert_syd_01" { name = "tf_sydim01_elastalert" type = "API" owner_team_id = opsgenie_team.sre.id

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

enabled = true allow_write_access = false suppress_notifications = true }

resource "opsgenie_integration_action" "create_action" { integration_id = opsgenie_api_integration.elastalert_syd_01.id

create { name = "tf_sydim01_default_rule" note = "{{note}}" user = "{{user}}" alias = "{{description.extract(/(?:opsgenie_entity:\W+)([^\)]+)/)}}" source = "{{source}}" message = "{{message}}" description = "{{description}}" entity = "{{description.extract(/(?:opsgenie_entity:\W+)([^\)]+)/)}}" type = "create" filter { type = "match-any-condition" conditions { field = "source" operation = "contains" expected_value = "ElastAlert" order = 1 } } responders { id = opsgenie_team.sre.id type = "team" } } }

resource "opsgenie_integration_action" "close_action" { integration_id = opsgenie_api_integration.elastalert_syd_01.id

close { name = "tf_sydim01_close_rule" note = "{{note}}" user = "{{user}}" alias = "{{alias}}" type = "close" order = 2

} }

resource "opsgenie_integration_action" "acknowledge_action" { integration_id = opsgenie_api_integration.elastalert_syd_01.id

acknowledge { name = "tf_sydim01_acknowledge_rule" note = "{{note}}" user = "{{user}}" alias = "{{alias}}" type = "acknowledge" order = 3 } }

resource "opsgenie_integration_action" "note_action" { integration_id = opsgenie_api_integration.elastalert_syd_01.id add_note { name = "tf_sydim01_note_rule" note = "{{note}}" user = "{{user}}" alias = "{{alias}}" order = 4 } }

Expected Behavior

Expected behaviour to create output similar to the following: image

Actual Behavior

When applied once, not all actions are created, it seems to be random. When applied again, another integration action will appear the rest will disappear

Steps to Reproduce

  1. terraform apply
khalidsheikh commented 10 months ago

fixed by changing code to include all actions in a single integration action like so:

resource "opsgenie_integration_action" "create_action" { integration_id = opsgenie_api_integration.elastalert_syd_01.id

create { name = "tf_sydim01_default_rule" note = "{{note}}" user = "{{user}}" alias = "{{description.extract(/(?:opsgenie_entity:\W+)([^\)]+)/)}}" source = "{{source}}" message = "{{message}}" description = "{{description}}" entity = "{{description.extract(/(?:opsgenie_entity:\W+)([^\)]+)/)}}" type = "create" filter { type = "match-any-condition" conditions { field = "source" operation = "contains" expected_value = "ElastAlert" order = 1 } } responders { id = opsgenie_team.sre.id type = "team" } }

close { name = "tf_sydim01_close_rule" note = "{{note}}" user = "{{user}}" alias = "{{alias}}" type = "close" order = 2

}

acknowledge { name = "tf_sydim01_acknowledge_rule" note = "{{note}}" user = "{{user}}" alias = "{{alias}}" type = "acknowledge" order = 3 }

add_note { name = "tf_sydim01_note_rule" note = "{{note}}" user = "{{user}}" alias = "{{alias}}" order = 4 } }