Skip to content

Commit

Permalink
cloud_tasks_queue: supress permadiffs on backoff settings (#8359) (#1…
Browse files Browse the repository at this point in the history
…5237)

Add `tpgresource.DurationDiffSuppress` to min / max backoff
Fixes https://github.com/hashicorp/terraform-provider-google/issues/15166x

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 20, 2023
1 parent 1fc111c commit 179fb23
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/8359.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloud_tasks: suppressed time-unit permadiffs on `google_cloud_tasks_queue` min and max backoff settings
```
40 changes: 40 additions & 0 deletions google/resource_cloud_tasks_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
18 changes: 10 additions & 8 deletions google/services/cloudtasks/resource_cloud_tasks_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.`,
Expand Down Expand Up @@ -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.`,
Expand Down

0 comments on commit 179fb23

Please sign in to comment.