-
Notifications
You must be signed in to change notification settings - Fork 216
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
Issue 463: Introduce catch_all #481
Conversation
I took a look to the deletion, I confirm that catch_all rule cannot be deleted and it results in an error:
I tried to apply this code: // Don't delete catch_all resource
if _, ok := d.GetOk(("catch_all")); ok {
log.Printf("[INFO] Rule %s is a catch_all rule, don't delete it, reset it instead", d.Id())
rule, _, err := client.Rulesets.GetRule(rulesetID, d.Id())
if err != nil {
return err
}
rule.Actions = nil
rule.TimeFrame = nil
if err := performRulesetRuleUpdate(rulesetID, d.Id(), rule, client); err != nil {
return err
}
d.SetId("")
return nil
} But the PUT action is not removing the Input payload {
"rule": {
"id": "ID",
"position": 0,
"disabled": false,
"self": "SELF",
"catch_all": true
}
} I also tried this: rule.Actions = new(pagerduty.RuleActions) Input payload {
"rule": {
"id": "ID",
"position": 0,
"actions": {},
"disabled": false,
"self": "SELF",
"catch_all": true
}
} and rule.Actions = new(pagerduty.RuleActions)
rule.Actions.Route = new(pagerduty.RuleActionParameter) Input payload {
"rule": {
"id": "ID",
"position": 0,
"actions": {
"route": {}
},
"disabled": false,
"self": "SELF",
"catch_all": true
}
} The route to service is not removed. This looks like a PATCH feature If I remember well in API design:
Here as I am using the PUT the resource must be fully replaced with actions = null (or empty) Waiting for your answer |
Any news ? |
Signed-off-by: Gavin Reynolds <[email protected]>
Signed-off-by: Gavin Reynolds <[email protected]>
Signed-off-by: Gavin Reynolds <[email protected]>
…ault Signed-off-by: Gavin Reynolds <[email protected]>
Signed-off-by: Gavin Reynolds <[email protected]>
Hi @speedfl - thanks for your first-time contribution! Nicely done! I've taken a look through your pull request and added some appropriate tests, as well as a little documentation. I've also taken a look at your issue with deletion/resetting a
So we need to do something more like this in the resource: // Reset all available actions back to the default state of the catch_all rule
rule.Actions.Annotate = nil
rule.Actions.EventAction = nil
rule.Actions.Extractions = nil
rule.Actions.Priority = nil
rule.Actions.Route = nil
rule.Actions.Severity = nil
rule.Actions.Suppress.Value = true
rule.Actions.Suspend = nil However, what also needed to be changed was to stop omitting those keys if the values were Debug log excerpts from the catch_all rule "deletion"/reset, successfully resetting the (If we are about to delete the ruleset, this probably doesn't matter much. If we were to stop managing the and finally the test output:
|
Thanks a lot for your help @gsreynolds ! |
@stmcallister we'll need to merge heimweh/go-pagerduty#84 and revendor here, FYI. |
@gsreynolds hope you are doing well heimweh/go-pagerduty#84 has been merged. I will make a try |
@gsreynolds I did a fix of an NPE. After validation: According to the destroy logs we can see that routing is removed
If you want to validate on your side you can use: terraform {
required_version = ">= 1.0"
required_providers {
pagerduty = {
source = "hashicorp/pagerduty"
version = "2.4.0"
}
}
}
provider "pagerduty" {
}
data "pagerduty_user" "foo" {
email = "[email protected]"
}
resource "pagerduty_escalation_policy" "foo" {
name = "Engineering Escalation Policy"
num_loops = 2
rule {
escalation_delay_in_minutes = 10
target {
type = "user_reference"
id = data.pagerduty_user.foo.id
}
}
}
resource "pagerduty_service" "foo" {
name = "My Web App"
auto_resolve_timeout = 14400
acknowledgement_timeout = 600
escalation_policy = pagerduty_escalation_policy.foo.id
alert_creation = "create_alerts_and_incidents"
}
resource "pagerduty_team" "foo" {
name = "Engineering (Seattle)"
}
resource "pagerduty_ruleset" "foo" {
name = "Primary Ruleset"
team {
id = pagerduty_team.foo.id
}
}
resource "pagerduty_ruleset_rule" "foo" {
ruleset = pagerduty_ruleset.foo.id
position = 0
disabled = "false"
catch_all = "true"
actions {
route {
value = pagerduty_service.foo.id
}
}
} For info I am using https://www.terraform.io/cli/config/config-file#filesystem_mirror (I put in hashicorp/pagerduty) |
@gsreynolds any news ? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Thank you @speedfl for the contribution!! And thanks @gsreynolds for the help! Teamwork!!! 🎉 👍 🌮
Reference: #463
Proposal is to introduce
catch_all
parameter as parameter to reflect what is in the API.Then if
catch_all
is present, as catch-all rule is created at Ruleset creation, an update is performed instead of a create (PUT instead of POST)Concerning the delete, I am skipping it but maybe it could be better to do another update to reset the catch-all rule (to be discussed in this thread)
Concerning the the
conditions
as mentioned, it is optional. So in case ofcatch_all
it must be removed