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

Gotcha when creating Escalation Policies #427

Open
stan-hill-oxa opened this issue Feb 27, 2024 · 0 comments
Open

Gotcha when creating Escalation Policies #427

stan-hill-oxa opened this issue Feb 27, 2024 · 0 comments

Comments

@stan-hill-oxa
Copy link

When creating an escalation policy, the plugin crashes if you include a repeat block in the code, but set all of the values inside to null.
However, if you make this block dynamic, and set the default to {} using a try block, it works.
See below for details:

Terraform Version

Terraform v1.5.7

Affected Resource(s)

  • opsgenie_escalation

Terraform Configuration Files

Escalations are being passed in via YAML, like so:

escalations:
  support_escalation:
    description: Escalation Policy for Support Tickets
    rules:
      initial:
        condition: if-not-acked
        notify_type: users
        delay: 0
        recipient:
          type: team
          id: <team-id>
    repeat:
      wait_interval: 10
      count: 1
      reset_recipient_states: true
      close_alert_after_all: false

When the repeat yaml is removed from above, and all values in the terraform block are set to null, the plugin crashes. The Terraform code is below:

locals {
  escalations_raw = { for team_name, team_data in local.team_data : team_name => {
      for escalation_name, escalation_data in team_data.escalations : escalation_name => merge({"owner_team_id" = data.terraform_remote_state.opsgenie_teams.outputs.teams[team_name].id}, escalation_data)
    }
  }
  escalations = { for escalation in values(local.escalations_raw) : keys(escalation)[0] => values(escalation)[0] }
}

resource "opsgenie_escalation" "escalations" {
  for_each = local.escalations
  name          = each.key
  description   = lookup(each.value, "description", null)
  owner_team_id = lookup(each.value, "owner_team_id", null)

 dynamic "rules" {
    for_each = each.value.rules

    content {
        condition   = rules.value.condition
        notify_type = rules.value.notify_type
        delay       = rules.value.delay
        recipient {
            type = rules.value.recipient.type
            id   = rules.value.recipient.type == "schedule" ? opsgenie_schedule.schedules[rules.value.recipient.id].id : data.terraform_remote_state.opsgenie_teams.outputs.teams[rules.value.recipient.id].id
        }
    }
  }

  repeat {
    wait_interval          = try(each.value.repeat.wait_interval, null)
    count                  = try(each.value.repeat.count, null)
    reset_recipient_states = try(each.value.repeat.reset_recipient_states, null)
    close_alert_after_all  = try(each.value.repeat.close_alert_after_all, null)
  }
}

However, change that repeat block to dynamic, and it works:

  dynamic "repeat" {
    for_each = try(each.value.repeat, {})
    content {
        wait_interval          = try(each.value.repeat.wait_interval, null)
        count                  = try(each.value.repeat.count, null)
        reset_recipient_states = try(each.value.repeat.reset_recipient_states, null)
        close_alert_after_all  = try(each.value.repeat.close_alert_after_all, null)
    }
  }

Debug Output

https://gist.github.com/stan-hill-oxa/767ac5e31f32cddda8c5bad159542ba8

Expected Behavior

An opsgenie_escalation resource (i.e an Escalation Policy) is created without the repeat configuration, without using a dynamic block.

Actual Behavior

Error: The terraform-provider-opsgenie_v0.6.35 plugin crashed! - when block is not dynamic.
Terraform is successful when block is dynamic.

Steps to Reproduce

  • Create an escalation policy which is configured by passing in YAML values, similar to above.
  • Do not include repeat in your YAML, and the plugin will crash
  • Now change the repeat terraform block to be dyanmic, with a default of {} (see above).
  • See that the plugin does not break.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant