From c3ac5612fdf8247519ea87c493abeeae229944d2 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 23 Dec 2020 12:04:44 -0800 Subject: [PATCH] Add diff suppress for max retry 0s on google_cloud_tasks_queue.retry_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 --- .changelog/4337.txt | 3 ++ google-beta/resource_cloud_tasks_queue.go | 15 ++++++-- .../resource_cloud_tasks_queue_test.go | 37 +++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 .changelog/4337.txt diff --git a/.changelog/4337.txt b/.changelog/4337.txt new file mode 100644 index 0000000000..2dc2915d55 --- /dev/null +++ b/.changelog/4337.txt @@ -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 +``` diff --git a/google-beta/resource_cloud_tasks_queue.go b/google-beta/resource_cloud_tasks_queue.go index 7fba6b6dc3..e3b2f02940 100644 --- a/google-beta/resource_cloud_tasks_queue.go +++ b/google-beta/resource_cloud_tasks_queue.go @@ -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, @@ -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 diff --git a/google-beta/resource_cloud_tasks_queue_test.go b/google-beta/resource_cloud_tasks_queue_test.go index 66530d44cf..f7803f0be8 100644 --- a/google-beta/resource_cloud_tasks_queue_test.go +++ b/google-beta/resource_cloud_tasks_queue_test.go @@ -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" { @@ -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) +}