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 #15237

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
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