PagerDuty / terraform-provider-pagerduty

Terraform PagerDuty provider
https://www.terraform.io/docs/providers/pagerduty/
Mozilla Public License 2.0
204 stars 212 forks source link

Missing "round robin" argument #518

Closed mjimeneznet closed 11 months ago

mjimeneznet commented 2 years ago

Terraform Version

Terraform v1.1.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/vault v3.5.0
+ provider registry.terraform.io/pagerduty/pagerduty v2.4.1

Affected Resource(s)

Please list the resources as a list, for example:

Expected Behavior

I'm missing the option to set "round robin" as I can do in the UI for the escalation policy

Actual Behavior

We don't have the option to set "round robin" therefore if you create a escalation policy in Terraform you still have to go to UI to set the "round robin".

aelmekeev commented 2 years ago

+ 1 to this since right now it prevents us from managing escalation policies in Terraform.

michaljmatusiak92 commented 2 years ago

+1 to this, it would be very helpful for our team

lydiamnash commented 1 year ago

+1 would be super helpful for our team 🙏🙏🙏

pascal-plamondon commented 1 year ago

+1

ericturcotte commented 1 year ago

+1

RATANAJANGIR commented 1 year ago

+1

neekolas commented 1 year ago

+1

liammac commented 1 year ago

+1

mattbates-CP commented 1 year ago

+1

Crevil commented 1 year ago

I'd be happy to take this one on and provide a PR 🎉

BillSidney commented 1 year ago

Also have a need for enabling Round Robin in escalation policies from Terraform. This is blocking some adoption in my organization.

Here is my workaround using a Null Provider

# Activate Round Robin Scheduling for first layer in Escalation Policy
resource "null_resource" "pagerduty_round_robin_scheduling" {
  count = var.service.roundrobin_scheduling == true ? 1 : 0

  triggers = {
    escalation_policy_id = pagerduty_escalation_policy.this.id,
  }

  provisioner "local-exec" {
    command = <<EOT
    set -e ; \
    TARGET_ID=$(curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request GET | jq '. | .escalation_policy.escalation_rules[0].escalation_rule_assignment_strategy.type = "round_robin"') ; \
    curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request PUT \
      --data "$TARGET_ID"
EOT
  }

  provisioner "local-exec" {
    when    = destroy
    command = <<-EOT
     TARGET_ID=$(curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request GET | jq '. | .escalation_policy.escalation_rules[0].escalation_rule_assignment_strategy.type = "assign_to_everyone"') ; \
    curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request PUT \
      --data "$TARGET_ID"
EOT
  }

  depends_on = [pagerduty_escalation_policy.this]
}
BillSidney commented 1 year ago

Is there any progress on adding this to the provider? I've got teams wanting this feature.

tmablunar commented 1 year ago

Also have a need for enabling Round Robin in escalation policies from Terraform. This is blocking some adoption in my organization.

Here is my workaround using a Null Provider

# Activate Round Robin Scheduling for first layer in Escalation Policy
resource "null_resource" "pagerduty_round_robin_scheduling" {
  count = var.service.roundrobin_scheduling == true ? 1 : 0

  triggers = {
    escalation_policy_id = pagerduty_escalation_policy.this.id,
  }

  provisioner "local-exec" {
    command = <<EOT
    set -e ; \
    TARGET_ID=$(curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request GET | jq '. | .escalation_policy.escalation_rules[0].escalation_rule_assignment_strategy.type = "round_robin"') ; \
    curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request PUT \
      --data "$TARGET_ID"
EOT
  }

  provisioner "local-exec" {
    when    = destroy
    command = <<-EOT
     TARGET_ID=$(curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request GET | jq '. | .escalation_policy.escalation_rules[0].escalation_rule_assignment_strategy.type = "assign_to_everyone"') ; \
    curl -s 'https://api.pagerduty.com/escalation_policies/${self.triggers.escalation_policy_id}?include[]=escalation_rule_assignment_strategies' \
      --header "Authorization: Token token=$TF_VAR_pagerduty_token" \
      --header 'Accept: application/vnd.pagerduty+json;version=2' \
      --header 'Content-Type: application/json' \
      --request PUT \
      --data "$TARGET_ID"
EOT
  }

  depends_on = [pagerduty_escalation_policy.this]
}

Building on the workaround from @BillSidney. Instead of only applying when the id of the escalation policy changes I trigger it every time anything in the escalation policy changes. Like this:

triggers = {
    escalation_policy_state = sha1(jsonencode({
      resource_state = pagerduty_escalation_policy.this
    }))
  }
imjaroiswebdev commented 11 months ago

Hi @mjimeneznet support for Round Robin escalation rule assignment strategy for incident is now available from version v3.3.0. Thank you all for the patience and support 🎉 🥳