Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloud_tasks_queue: supress permadiffs on backoff settings #8359

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}