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

Fixing Bug in Service Resource Where alert_grouping_timeout wasn't saving 0 values #190

Merged
merged 16 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-pagerduty
require (
github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.7.0
github.com/heimweh/go-pagerduty v0.0.0-20190807171021-2a6540956dc5
github.com/heimweh/go-pagerduty v0.0.0-20200303231559-1936667f26f9
)

go 1.13
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/heimweh/go-pagerduty v0.0.0-20190807171021-2a6540956dc5 h1:UZQ03lpxS/AUrMTlh1yQ/MJEJ+2he5bCItZ4W9Lgs1c=
github.com/heimweh/go-pagerduty v0.0.0-20190807171021-2a6540956dc5/go.mod h1:6+bccpjQ/PM8uQY9m8avM4MJea+3vo3ta9r8kGQ4XFY=
github.com/heimweh/go-pagerduty v0.0.0-20200303231559-1936667f26f9 h1:C3Wdm8ZIXNM9oP2lWdAjtP3b1J41lb4IJ9ib71QzzZ8=
github.com/heimweh/go-pagerduty v0.0.0-20200303231559-1936667f26f9/go.mod h1:6+bccpjQ/PM8uQY9m8avM4MJea+3vo3ta9r8kGQ4XFY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
20 changes: 0 additions & 20 deletions pagerduty/resource_pagerduty_event_rule.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pagerduty

import (
"encoding/json"
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -55,25 +54,6 @@ func buildEventRuleStruct(d *schema.ResourceData) *pagerduty.EventRule {
return eventRule
}

func expandString(v string) []interface{} {
var obj []interface{}
if err := json.Unmarshal([]byte(v), &obj); err != nil {
log.Printf("[ERROR] Could not unmarshal event rule field %s: %v", v, err)
return nil
}

return obj
}

func flattenSlice(v []interface{}) interface{} {
b, err := json.Marshal(v)
if err != nil {
log.Printf("[ERROR] Could not marshal event rule field %s: %v", v, err)
return nil
}
return string(b)
}

func resourcePagerDutyEventRuleCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*pagerduty.Client)

Expand Down
3 changes: 2 additions & 1 deletion pagerduty/resource_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ func buildServiceStruct(d *schema.ResourceData) (*pagerduty.Service, error) {
service.AlertGrouping = attr.(string)
}

if attr, ok := d.GetOk("alert_grouping_timeout"); ok {
// Using GetOkExists to allow for alert_grouping_timeout to be set to 0 if needed.
if attr, ok := d.GetOkExists("alert_grouping_timeout"); ok {
val := attr.(int)
service.AlertGroupingTimeout = &val
}
Expand Down
20 changes: 20 additions & 0 deletions pagerduty/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pagerduty

import (
"encoding/json"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -69,3 +70,22 @@ func expandStringList(configured []interface{}) []string {
}
return vs
}

func expandString(v string) []interface{} {
var obj []interface{}
if err := json.Unmarshal([]byte(v), &obj); err != nil {
log.Printf("[ERROR] Could not unmarshal field %s: %v", v, err)
return nil
}

return obj
}

func flattenSlice(v []interface{}) interface{} {
b, err := json.Marshal(v)
if err != nil {
log.Printf("[ERROR] Could not marshal field %s: %v", v, err)
return nil
}
return string(b)
}
2 changes: 1 addition & 1 deletion website/docs/r/event_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The following attributes are exported:

## Import

Escalation policies can be imported using the `id`, e.g.
Event rules can be imported using the `id`, e.g.

```
$ terraform import pagerduty_event_rule.main 19acac92-027a-4ea0-b06c-bbf516519601
Expand Down