From 179fb23656ca20e9bf8804e494124853f5bd0605 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 20 Jul 2023 10:21:51 -0700 Subject: [PATCH] cloud_tasks_queue: supress permadiffs on backoff settings (#8359) (#15237) Add `tpgresource.DurationDiffSuppress` to min / max backoff Fixes https://github.com/hashicorp/terraform-provider-google/issues/15166x Signed-off-by: Modular Magician --- .changelog/8359.txt | 3 ++ google/resource_cloud_tasks_queue_test.go | 40 +++++++++++++++++++ .../cloudtasks/resource_cloud_tasks_queue.go | 18 +++++---- 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 .changelog/8359.txt diff --git a/.changelog/8359.txt b/.changelog/8359.txt new file mode 100644 index 00000000000..1dbf7915c4b --- /dev/null +++ b/.changelog/8359.txt @@ -0,0 +1,3 @@ +```release-note:bug +cloud_tasks: suppressed time-unit permadiffs on `google_cloud_tasks_queue` min and max backoff settings +``` diff --git a/google/resource_cloud_tasks_queue_test.go b/google/resource_cloud_tasks_queue_test.go index 90b908ebe94..564e0321a49 100644 --- a/google/resource_cloud_tasks_queue_test.go +++ b/google/resource_cloud_tasks_queue_test.go @@ -92,6 +92,29 @@ func TestAccCloudTasksQueue_MaxRetryDiffSuppress0s(t *testing.T) { }) } +// Make sure the diff suppression function handles the situation where an +// unexpected time unit is used, e.g., 2.0s instead of 2s or 2.0s instead of +// 2.000s +func TestAccCloudTasksQueue_TimeUnitDiff(t *testing.T) { + t.Parallel() + testID := acctest.RandString(t, 10) + cloudTaskName := fmt.Sprintf("tf-test-%s", testID) + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudtasksQueueTimeUnitDiff(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" { @@ -186,3 +209,20 @@ func testAccCloudtasksQueueMaxRetry0s(cloudTaskName string) string { } `, cloudTaskName) } + +func testAccCloudtasksQueueTimeUnitDiff(cloudTaskName string) string { + return fmt.Sprintf(` +resource "google_cloud_tasks_queue" "default" { + name = "%s" + location = "us-central1" + + retry_config { + max_attempts = -1 + max_backoff = "5.000s" + max_doublings = 16 + max_retry_duration = "1.0s" + min_backoff = "0.10s" + } +} +`, cloudTaskName) +} diff --git a/google/services/cloudtasks/resource_cloud_tasks_queue.go b/google/services/cloudtasks/resource_cloud_tasks_queue.go index 560edccb418..2c8a70d6bd3 100644 --- a/google/services/cloudtasks/resource_cloud_tasks_queue.go +++ b/google/services/cloudtasks/resource_cloud_tasks_queue.go @@ -30,12 +30,12 @@ import ( transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" ) -func suppressOmittedMaxDuration(_, old, new string, _ *schema.ResourceData) bool { +func suppressOmittedMaxDuration(k, old, new string, d *schema.ResourceData) bool { if old == "" && new == "0s" { log.Printf("[INFO] max retry is 0s and api omitted field, suppressing diff") return true } - return false + return tpgresource.DurationDiffSuppress(k, old, new, d) } func ResourceCloudTasksQueue() *schema.Resource { @@ -175,9 +175,10 @@ the default. -1 indicates unlimited attempts.`, }, "max_backoff": { - Type: schema.TypeString, - Computed: true, - Optional: true, + Type: schema.TypeString, + Computed: true, + Optional: true, + DiffSuppressFunc: tpgresource.DurationDiffSuppress, Description: `A task will be scheduled for retry between minBackoff and maxBackoff duration after it fails, if the queue's RetryConfig specifies that the task should be retried.`, @@ -206,9 +207,10 @@ made and the task will be deleted. If zero, then the task age is unlimited.`, }, "min_backoff": { - Type: schema.TypeString, - Computed: true, - Optional: true, + Type: schema.TypeString, + Computed: true, + Optional: true, + DiffSuppressFunc: tpgresource.DurationDiffSuppress, Description: `A task will be scheduled for retry between minBackoff and maxBackoff duration after it fails, if the queue's RetryConfig specifies that the task should be retried.`,