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

extra_properties no longer supported? #408

Open apsamuel opened 10 months ago

apsamuel commented 10 months ago

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

❯ terraform version -v Terraform v1.5.7 on darwin_amd64

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "opsgenie_integration_action" "this" {
  for_each = local.integrations
  integration_id = flatten(
    [for k,v in resource.opsgenie_api_integration.this:
      v.id if v.name == "${var.service.name}-${each.value.source}-${lower(each.value.type)}"
    ]
  )[0]

  /*
    💡 we only create create actions for events we know how to create (eg. CloudWatch & Route53 event sources)
  */
  dynamic "create" {
    for_each = contains(["AmazonRoute53HealthCheck", "CloudWatch"], each.value.type) ? try(
      {
        for alert in each.value.alerts: index(each.value.alerts, alert) => alert
      },
      {}
    ) : {}
    iterator = alert
    content {
      // order = can(alert.value.order) ? alert.value.order : index(each.value.alerts, alert.value)
      name = "${var.service.name}-${lower(each.value.source)}-${lower(each.value.type)}-create-action"
      message = each.value.message
      alias = each.value.alias
      description = each.value.description
      custom_priority = each.value.custom_priority
      /* TODO: understand why extra_properties is not set */
      # extra_properties = tomap(each.value.properties)
      extra_properties = {
        for k,v in each.value.properties: k => v
      }

      tags = try(each.value.tags, ["alert"])

      filter {
        type = alert.value.type

        dynamic "conditions" {
          for_each = try(
            {
              # for condition in each.value.conditions: index(each.value.conditions, condition) => condition
              for condition in alert.value.conditions: index(alert.value.conditions, condition) => condition
            },
            {}
          )
          iterator = condition
          content {
            field = condition.value.field
            operation = condition.value.operation
            expected_value = condition.value.expected_value
            not = condition.value.not
          }
        }
      }
    }
  }
  /*
    💡 we only create close actions for events we know how to resolve (eg. CloudWatch & Route53 event sources)
  */

  dynamic "close" {
    /*
      💡 we only create close actions for events we know how to resolve (eg. CloudWatch & Route53 event sources)
    */
    for_each = contains(["AmazonRoute53HealthCheck", "CloudWatch"], each.value.type) ? try(
      {
        for alert in each.value.alerts: index(each.value.alerts, alert) => alert
      },
      {}
    ) : {}
    iterator = alert
    content {
      name = "${var.service.name}-${lower(each.value.source)}-${lower(each.value.type)}-close-action"
      note = "closing ${each.value.message}"
      filter {
        type = alert.value.type
        dynamic "conditions" {
          for_each = try(
            {
              for condition in alert.value.conditions: index(alert.value.conditions, condition) => condition
            },
            {}
          )
          iterator = condition
          content {
            field = condition.value.field
            operation = condition.value.operation
            expected_value = condition.value.expected_value
            not = condition.value.field == "{{NewStateValue}}" ? !condition.value.not : condition.value.not
          }
        }
      }
    }
  }

  dynamic "acknowledge" {
    /*
      💡 we only create close actions for events we know how to resolve (eg. CloudWatch & Route53 event sources)
    */
    for_each = contains(["AmazonRoute53HealthCheck", "CloudWatch"], each.value.type) ? try(
      {
        for alert in each.value.alerts: index(each.value.alerts, alert) => alert
      },
      {}
    ) : {}
    iterator = alert

    content {
      name = "${var.service.name}-${lower(each.value.source)}-${lower(each.value.type)}-acknowledge-action"
      user = each.value.user
      note = "${each.value.user} acknowledged ${each.value.message}"
      alias = each.value.alias
      filter {
        type = alert.value.type
        dynamic "conditions" {
          for_each = try(
            {
              for condition in concat(
                alert.value.conditions,
                var.defaults.actions.acknowledge.conditions
              ): condition.expected_value => condition
            },
            {}
          )
          iterator = condition
          content {
            field = condition.value.field
            operation = condition.value.operation
            expected_value = condition.value.expected_value
            not = condition.value.not
          }
        }
      }

    }
  }
}

extra_properties is defined in a terraform tfvars file as

                    "properties": {
                        "system": "{{AlarmName.extract(/\\/(?<system>.+)\\/(?<location>.+)\\/(?<sector>.*)\\/(?<path>.*)\\/(?<category>.*)\\/(?<resource>.*)\\/(?<metric>.*)/, 1).removeAllWhitespace()}}",
                        "location": "{{AlarmName.extract(/\\/(?<system>.+)\\/(?<location>.+)\\/(?<sector>.*)\\/(?<path>.*)\\/(?<category>.*)\\/(?<resource>.*)\\/(?<metric>.*)/, 2).removeAllWhitespace()}}",
                        "sector": "{{AlarmName.extract(/\\/(?<system>.+)\\/(?<location>.+)\\/(?<sector>.*)\\/(?<path>.*)\\/(?<category>.*)\\/(?<resource>.*)\\/(?<metric>.*)/, 3).removeAllWhitespace()}}",
                        "path": "{{AlarmName.extract(/\\/(?<system>.+)\\/(?<location>.+)\\/(?<sector>.*)\\/(?<path>.*)\\/(?<category>.*)\\/(?<resource>.*)\\/(?<metric>.*)/, 4).removeAllWhitespace()}}",
                        "category": "{{AlarmName.extract(/\\/(?<system>.+)\\/(?<location>.+)\\/(?<sector>.*)\\/(?<path>.*)\\/(?<category>.*)\\/(?<resource>.*)\\/(?<metric>.*)/, 5).removeAllWhitespace()}}",
                        "resource": "{{AlarmName.extract(/\\/(?<system>.+)\\/(?<location>.+)\\/(?<sector>.*)\\/(?<path>.*)\\/(?<category>.*)\\/(?<resource>.*)\\/(?<metric>.*)/, 6).removeAllWhitespace()}}",
                        "metric": "{{AlarmName.extract(/\\/(?<system>.+)\\/(?<location>.+)\\/(?<sector>.*)\\/(?<path>.*)\\/(?<category>.*)\\/(?<resource>.*)\\/(?<metric>.*)/, 7).removeAllWhitespace()}}"
                    },

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

What should have happened?

extra_properties should be added to the Alert(s)

Actual Behavior

What actually happened?

extra_properties does not exist, has been renamed to _extra_properties, and is an empty object

Steps to Reproduce

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

  1. terraform apply

Important Factoids

Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

No

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

Not that I am aware of