From 2c219b6d3cf2720fde86ff8b1d65abca8752f7d8 Mon Sep 17 00:00:00 2001 From: Avinash Navada Date: Tue, 8 Oct 2024 18:33:53 -0400 Subject: [PATCH] pubsub: fix permadiff with configuring an empty retry_policy. (#11834) --- mmv1/products/pubsub/Subscription.yaml | 2 + .../resource_pubsub_subscription_test.go | 40 +++++++++++++++++++ .../data/example_pubsub_subscription.json | 3 +- ...ample_pubsub_subscription_iam_binding.json | 3 +- ...xample_pubsub_subscription_iam_member.json | 3 +- ...xample_pubsub_subscription_iam_policy.json | 3 +- 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/mmv1/products/pubsub/Subscription.yaml b/mmv1/products/pubsub/Subscription.yaml index 5ed3ea7988db..637be094da13 100644 --- a/mmv1/products/pubsub/Subscription.yaml +++ b/mmv1/products/pubsub/Subscription.yaml @@ -471,6 +471,8 @@ properties: A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s". default_from_api: true diff_suppress_func: 'tpgresource.DurationDiffSuppress' + send_empty_value: true + allow_empty_object: true - name: 'enableMessageOrdering' type: Boolean description: | diff --git a/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go b/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go index af40a3411333..403a732ded4d 100644 --- a/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go +++ b/mmv1/third_party/terraform/services/pubsub/resource_pubsub_subscription_test.go @@ -36,6 +36,30 @@ func TestAccPubsubSubscription_emptyTTL(t *testing.T) { }) } +func TestAccPubsubSubscription_emptyRetryPolicy(t *testing.T) { + t.Parallel() + + topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(t, 10)) + subscription := fmt.Sprintf("tf-test-sub-%s", acctest.RandString(t, 10)) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccPubsubSubscription_emptyRetryPolicy(topic, subscription), + }, + { + ResourceName: "google_pubsub_subscription.foo", + ImportStateId: subscription, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccPubsubSubscription_basic(t *testing.T) { t.Parallel() @@ -494,6 +518,22 @@ resource "google_pubsub_subscription" "foo" { `, topic, subscription) } +func testAccPubsubSubscription_emptyRetryPolicy(topic, subscription string) string { + return fmt.Sprintf(` +resource "google_pubsub_topic" "foo" { + name = "%s" +} + +resource "google_pubsub_subscription" "foo" { + name = "%s" + topic = google_pubsub_topic.foo.id + + retry_policy { + } +} +`, topic, subscription) +} + func testAccPubsubSubscription_push(topicFoo, saAccount, subscription string) string { return fmt.Sprintf(` data "google_project" "project" { } diff --git a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription.json b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription.json index bdc3d1f93e56..2fa16e2aee4f 100644 --- a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription.json +++ b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription.json @@ -48,8 +48,9 @@ "pushConfig": { "pushEndpoint": "https://example.com/push" }, + "retryPolicy": null, "topic": "projects/{{.Provider.project}}/topics/example-pubsub-topic" } } } -] \ No newline at end of file +] diff --git a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_binding.json b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_binding.json index dd012c01a7af..7a753fb0f81a 100644 --- a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_binding.json +++ b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_binding.json @@ -20,6 +20,7 @@ "pushConfig": { "pushEndpoint": "https://example.com/push" }, + "retryPolicy": null, "topic": "projects/{{.Provider.project}}/topics/example-pubsub-topic" } }, @@ -34,4 +35,4 @@ ] } } -] \ No newline at end of file +] diff --git a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_member.json b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_member.json index dd012c01a7af..7a753fb0f81a 100644 --- a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_member.json +++ b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_member.json @@ -20,6 +20,7 @@ "pushConfig": { "pushEndpoint": "https://example.com/push" }, + "retryPolicy": null, "topic": "projects/{{.Provider.project}}/topics/example-pubsub-topic" } }, @@ -34,4 +35,4 @@ ] } } -] \ No newline at end of file +] diff --git a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_policy.json b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_policy.json index dd012c01a7af..7a753fb0f81a 100644 --- a/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_policy.json +++ b/mmv1/third_party/tgc/tests/data/example_pubsub_subscription_iam_policy.json @@ -20,6 +20,7 @@ "pushConfig": { "pushEndpoint": "https://example.com/push" }, + "retryPolicy": null, "topic": "projects/{{.Provider.project}}/topics/example-pubsub-topic" } }, @@ -34,4 +35,4 @@ ] } } -] \ No newline at end of file +]