Skip to content

Commit

Permalink
cloud_tasks_queue: supress permadiffs on backoff settings (#8359)
Browse files Browse the repository at this point in the history
Add `tpgresource.DurationDiffSuppress` to min / max backoff
Fixes https://github.com/hashicorp/terraform-provider-google/issues/15166x
  • Loading branch information
wyardley authored and shuyama1 committed Aug 3, 2023
1 parent 97046a7 commit 0e609cd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mmv1/products/cloudtasks/Queue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ properties:
maxBackoff duration after it fails, if the queue's RetryConfig
specifies that the task should be retried.
default_from_api: true
diff_suppress_func: 'tpgresource.DurationDiffSuppress'
- !ruby/object:Api::Type::String
name: 'maxBackoff'
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.
default_from_api: true
diff_suppress_func: 'tpgresource.DurationDiffSuppress'
- !ruby/object:Api::Type::Integer
name: 'maxDoublings'
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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 @@ -185,3 +208,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)
}

0 comments on commit 0e609cd

Please sign in to comment.