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

resource/pagerduty_maintenance_window: Allow services to be unordered #142

Merged
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
13 changes: 7 additions & 6 deletions pagerduty/resource_pagerduty_maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func resourcePagerDutyMaintenanceWindow() *schema.Resource {
},

"services": {
Type: schema.TypeList,
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"description": {
Expand All @@ -49,7 +50,7 @@ func buildMaintenanceWindowStruct(d *schema.ResourceData) *pagerduty.Maintenance
window := &pagerduty.MaintenanceWindow{
StartTime: d.Get("start_time").(string),
EndTime: d.Get("end_time").(string),
Services: expandServices(d.Get("services")),
Services: expandServices(d.Get("services").(*schema.Set)),
}

if v, ok := d.GetOk("description"); ok {
Expand Down Expand Up @@ -125,10 +126,10 @@ func resourcePagerDutyMaintenanceWindowDelete(d *schema.ResourceData, meta inter
return nil
}

func expandServices(v interface{}) []*pagerduty.ServiceReference {
func expandServices(v *schema.Set) []*pagerduty.ServiceReference {
var services []*pagerduty.ServiceReference

for _, srv := range v.([]interface{}) {
for _, srv := range v.List() {
service := &pagerduty.ServiceReference{
Type: "service_reference",
ID: srv.(string),
Expand All @@ -139,12 +140,12 @@ func expandServices(v interface{}) []*pagerduty.ServiceReference {
return services
}

func flattenServices(v []*pagerduty.ServiceReference) []interface{} {
func flattenServices(v []*pagerduty.ServiceReference) *schema.Set {
var services []interface{}

for _, srv := range v {
services = append(services, srv.ID)
}

return services
return schema.NewSet(schema.HashString, services)
}
15 changes: 14 additions & 1 deletion pagerduty/resource_pagerduty_maintenance_window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,24 @@ resource "pagerduty_service" "foo" {
}
}

resource "pagerduty_service" "foo2" {
name = "%[1]v2"
description = "foo2"
auto_resolve_timeout = 1800
acknowledgement_timeout = 1800
escalation_policy = "${pagerduty_escalation_policy.foo.id}"

incident_urgency_rule {
type = "constant"
urgency = "high"
}
}

resource "pagerduty_maintenance_window" "foo" {
description = "%[1]v"
start_time = "%[2]v"
end_time = "%[3]v"
services = ["${pagerduty_service.foo.id}"]
services = ["${pagerduty_service.foo.id}", "${pagerduty_service.foo2.id}"]
}
`, desc, start, end)
}