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

Add responders{type = "escalation"} in opsgenie_alert_policy #293

Closed
janhorstmann opened this issue Apr 6, 2022 · 5 comments
Closed

Add responders{type = "escalation"} in opsgenie_alert_policy #293

janhorstmann opened this issue Apr 6, 2022 · 5 comments

Comments

@janhorstmann
Copy link
Contributor

Hi,
this is a feature request to support

  responders {
    type = "escalation"
}

in resource opsgenie_alert_policy.
Although the API documentation states that only user and team are possible values to the responders field, the web interface definitely allows setting an escalation. When doing so the terraform-provider-opsgenie correctly identifies the type = "escalation" as configuration drift:

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # opsgenie_alert_policy.test has changed
  ~ resource "opsgenie_alert_policy" "test" {
        id                         = SOME_ID
        name                       = "test alert policy"
        tags                       = []
        # (14 unchanged attributes hidden)


      ~ responders {
            id   = SOME_ID
          ~ type = "team" -> "escalation"
        }
        # (1 unchanged block hidden)
    }

Please add responders{type = "escalation"} in opsgenie_alert_policy.

Affected Resource(s)

  • opsgenie_alert_policy

Terraform Configuration Files

resource "opsgenie_alert_policy" "test" {
  name               = "example policy"
  team_id            = opsgenie_team.test.id
  policy_description = "This is sample policy"
  message            = "{{message}}"

  filter {}
  responders {
    type = "escalation"
    id = opsgenie_escalation.some_resource.id
  }
}

Output

Error: expected responders.0.type to be one of [user team], got escalation
│ 
│   with opsgenie_alert_policy.test,
│   on main.tf line 336, in resource "opsgenie_alert_policy" "test":
│  336:     type = "escalation"
@ghost
Copy link

ghost commented Apr 6, 2022

I'm not familiar with the code base, but I believe this is defined here:

		responder := alert.Responder{
			Type:     alert.ResponderType(config["type"].(string)),
			Id:       responderID,
			Name:     name,
			Username: username,
		}

@janhorstmann
Copy link
Contributor Author

Although the API documentation states that only user and team are possible values to the responders field, the web interface definitely allows setting an escalation.

I have just tested the API and it seems to be possible to set a type: escalation in responders:

#TEAM_ID=""
#ESCALATION_ID=""
#OPSGENIE_API_KEY=""

ALERT_POLICY_ID="$( curl -X POST \
                   https://api.eu.opsgenie.com/v2/policies?teamId=$TEAM_ID \
                   --header "Authorization: GenieKey $OPSGENIE_API_KEY" \
                   --header 'Content-Type: application/json' \
                   --data \
'{
    "continue": false,
    "type": "alert",
    "name": "test",
    "enabled": false,
    "policyDescription": "test",
    "filter": {
      "type": "match-all"
    },
    "responders": [
      {
        "type": "escalation",
        "id": "'$ESCALATION_ID'"
      }
    ],
    "alias": "{{alias}}",
    "message": "{{message}}",
    "description": "{{description}}",
    "source": "{{source}}",
    "entity": "{{entity}}",
    "actions": [],
    "tags": [],
    "details": {},
    "ignoreOriginalActions": false,
    "ignoreOriginalDetails": false,
    "ignoreOriginalResponders": true,
    "ignoreOriginalTags": false
}' | jq -r '.data.id' )"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   806    0   163  100   643    714   2819 --:--:-- --:--:-- --:--:--  3535

curl -X GET \
      https://api.eu.opsgenie.com/v2/policies/$ALERT_POLICY_ID?teamId=$TEAM_ID \
     --header "Authorization: GenieKey $OPSGENIE_API_KEY" | jq '.data.responders[].type'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   593    0   593    0     0   4145      0 --:--:-- --:--:-- --:--:--  4176
"escalation"

I have submmited a suggestion to edit the API documentation.

janhorstmann added a commit to janhorstmann/terraform-provider-opsgenie that referenced this issue Apr 11, 2022
janhorstmann added a commit to janhorstmann/terraform-provider-opsgenie that referenced this issue Aug 23, 2022
@anjmao
Copy link

anjmao commented Sep 29, 2022

Hi, @grubernaut @fnuva @tombuildsstuff @janhorstmann
Can we merge opened PR for escalation type? We need this field to migrate to terraform.

@janhorstmann
Copy link
Contributor Author

janhorstmann commented Dec 12, 2022

I went ahead and tested this locally and realised that responder type is also validated in opsgenie-go-sdk-v2. I have also created an issue and a simple PR there.
With those changes everything worked as expected.

@frknyldz I have seen that you are doing releases. Could you provide me with some guidance and maybe help on how to move this along?

@arjunrajpal
Copy link
Contributor

Hi everyone, this issue has been fixed in v0.6.27. Kindly check !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants