Skip to content

Commit

Permalink
Merge pull request #116 from terraform-providers/b-mw-time-diff
Browse files Browse the repository at this point in the history
resource/pagerduty_maintenance_window: Suppress spurious diff
  • Loading branch information
radeksimko authored Mar 13, 2019
2 parents ca07c08 + 88f50a5 commit 9f1e062
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pagerduty/resource_pagerduty_maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ func resourcePagerDutyMaintenanceWindow() *schema.Resource {
},
Schema: map[string]*schema.Schema{
"start_time": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRFC3339,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRFC3339,
DiffSuppressFunc: suppressRFC3339Diff,
},
"end_time": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRFC3339,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateRFC3339,
DiffSuppressFunc: suppressRFC3339Diff,
},

"services": {
Expand Down
15 changes: 15 additions & 0 deletions pagerduty/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pagerduty

import (
"fmt"
"log"
"time"

"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -26,6 +27,20 @@ func validateRFC3339(v interface{}, k string) (we []string, errors []error) {
return
}

func suppressRFC3339Diff(k, oldTime, newTime string, d *schema.ResourceData) bool {
oldT, err := time.Parse(time.RFC3339, oldTime)
if err != nil {
log.Printf("[ERROR] Failed to parse %q (old %q). Expected format: %s (RFC3339)", oldTime, k, time.RFC3339)
return false
}
newT, err := time.Parse(time.RFC3339, newTime)
if err != nil {
log.Printf("[ERROR] Failed to parse %q (new %q). Expected format: %s (RFC3339)", newTime, k, time.RFC3339)
return false
}
return oldT.Equal(newT)
}

// Validate a value against a set of possible values
func validateValueFunc(values []string) schema.SchemaValidateFunc {
return func(v interface{}, k string) (we []string, errors []error) {
Expand Down

0 comments on commit 9f1e062

Please sign in to comment.