Skip to content

Commit

Permalink
Add diff suppress for max retry 0s on google_cloud_tasks_queue.retry_…
Browse files Browse the repository at this point in the history
…config.max_retry_duration (#4337) (#2812)

* adding diff supress for max retry 0s

* update file extension in comment to be accurate

* Update cloud_tasks_retry_config_custom_diff.go

* line too long. me make line less long

* update to pass rake test

* Update file_template.rb

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Dec 23, 2020
1 parent 7caba34 commit c3ac561
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/4337.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloud_tasks: fixed permadiff on retry_config.max_retry_duration for `google_cloud_tasks_queue` when the 0s is supplied
```
15 changes: 12 additions & 3 deletions google-beta/resource_cloud_tasks_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func suppressOmittedMaxDuration(_, old, new string, _ *schema.ResourceData) bool {
if old == "" && new == "0s" {
log.Printf("[INFO] max retry is 0s and api omitted field, suppressing diff")
return true
}
return false
}

func resourceCloudTasksQueue() *schema.Resource {
return &schema.Resource{
Create: resourceCloudTasksQueueCreate,
Expand Down Expand Up @@ -180,9 +188,10 @@ then increases linearly, and finally retries retries at intervals of maxBackoff
up to maxAttempts times.`,
},
"max_retry_duration": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Type: schema.TypeString,
Computed: true,
Optional: true,
DiffSuppressFunc: suppressOmittedMaxDuration,
Description: `If positive, maxRetryDuration specifies the time limit for
retrying a failed task, measured from when the task was first
attempted. Once maxRetryDuration time has passed and the task has
Expand Down
37 changes: 37 additions & 0 deletions google-beta/resource_cloud_tasks_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ func TestAccCloudTasksQueue_update2Basic(t *testing.T) {
})
}

func TestAccCloudTasksQueue_MaxRetryDiffSuppress0s(t *testing.T) {
t.Parallel()
testID := randString(t, 10)
cloudTaskName := fmt.Sprintf("tf-test-%s", testID)
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudtasksQueueMaxRetry0s(cloudTaskName),
},
{
ResourceName: "google_cloud_tasks_queue.default",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCloudTasksQueue_basic(name string) string {
return fmt.Sprintf(`
resource "google_cloud_tasks_queue" "default" {
Expand Down Expand Up @@ -146,3 +166,20 @@ resource "google_cloud_tasks_queue" "default" {
}
`, name)
}

func testAccCloudtasksQueueMaxRetry0s(cloudTaskName string) string {
return fmt.Sprintf(`
resource "google_cloud_tasks_queue" "default" {
name = "%s"
location = "us-central1"
retry_config {
max_attempts = -1
max_backoff = "3600s"
max_doublings = 16
max_retry_duration = "0s"
min_backoff = "0.100s"
}
}
`, cloudTaskName)
}

0 comments on commit c3ac561

Please sign in to comment.