Skip to content

Commit

Permalink
handle diff for duration (#4753) (#3214)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 30, 2021
1 parent 3e9be72 commit 64e840d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/4753.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pubsub: fixed diff for `minimum_backoff & maximum_backoff` on `google_pubsub_subscription`
```
14 changes: 14 additions & 0 deletions google-beta/common_diff_suppress.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,17 @@ func timestampDiffSuppress(format string) schema.SchemaDiffSuppressFunc {
func internalIpDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
return (net.ParseIP(old) != nil) && (net.ParseIP(new) == nil)
}

// Suppress diffs for duration format. ex "60.0s" and "60s" same
// https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#duration
func durationDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
oDuration, err := time.ParseDuration(old)
if err != nil {
return false
}
nDuration, err := time.ParseDuration(new)
if err != nil {
return false
}
return oDuration == nDuration
}
3 changes: 2 additions & 1 deletion google-beta/resource_dataproc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

dataproc "google.golang.org/api/dataproc/v1beta2"
"google.golang.org/api/googleapi"

dataproc "google.golang.org/api/dataproc/v1beta2"
)

func TestDataprocExtractInitTimeout(t *testing.T) {
Expand Down
14 changes: 8 additions & 6 deletions google-beta/resource_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,18 @@ RetryPolicy will be triggered on NACKs or acknowledgement deadline exceeded even
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"maximum_backoff": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Type: schema.TypeString,
Computed: true,
Optional: true,
DiffSuppressFunc: durationDiffSuppress,
Description: `The maximum delay between consecutive deliveries of a given message. Value should be between 0 and 600 seconds. Defaults to 600 seconds.
A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".`,
},
"minimum_backoff": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Type: schema.TypeString,
Computed: true,
Optional: true,
DiffSuppressFunc: durationDiffSuppress,
Description: `The minimum delay between consecutive deliveries of a given message. Value should be between 0 and 600 seconds. Defaults to 10 seconds.
A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".`,
},
Expand Down
3 changes: 3 additions & 0 deletions google-beta/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ resource "google_pubsub_subscription" "foo" {
labels = {
foo = "%s"
}
retry_policy {
minimum_backoff = "60.0s"
}
ack_deadline_seconds = %d
}
`, topic, subscription, label, deadline)
Expand Down

0 comments on commit 64e840d

Please sign in to comment.