Skip to content

Commit

Permalink
pubsub: fix permadiff with configuring an empty retry_policy. (#11834) (
Browse files Browse the repository at this point in the history
#19784)

[upstream:2c219b6d3cf2720fde86ff8b1d65abca8752f7d8]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 8, 2024
1 parent 45e717a commit 00a5231
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/11834.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
pubsub: fix permadiff with configuring an empty `retry_policy`.
```
14 changes: 8 additions & 6 deletions google/services/pubsub/resource_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func resourcePubsubSubscriptionCreate(d *schema.ResourceData, meta interface{})
retryPolicyProp, err := expandPubsubSubscriptionRetryPolicy(d.Get("retry_policy"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("retry_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(retryPolicyProp)) && (ok || !reflect.DeepEqual(v, retryPolicyProp)) {
} else if v, ok := d.GetOkExists("retry_policy"); ok || !reflect.DeepEqual(v, retryPolicyProp) {
obj["retryPolicy"] = retryPolicyProp
}
enableMessageOrderingProp, err := expandPubsubSubscriptionEnableMessageOrdering(d.Get("enable_message_ordering"), d, config)
Expand Down Expand Up @@ -914,7 +914,7 @@ func resourcePubsubSubscriptionUpdate(d *schema.ResourceData, meta interface{})
retryPolicyProp, err := expandPubsubSubscriptionRetryPolicy(d.Get("retry_policy"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("retry_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, retryPolicyProp)) {
} else if v, ok := d.GetOkExists("retry_policy"); ok || !reflect.DeepEqual(v, retryPolicyProp) {
obj["retryPolicy"] = retryPolicyProp
}
enableExactlyOnceDeliveryProp, err := expandPubsubSubscriptionEnableExactlyOnceDelivery(d.Get("enable_exactly_once_delivery"), d, config)
Expand Down Expand Up @@ -1434,9 +1434,6 @@ func flattenPubsubSubscriptionRetryPolicy(v interface{}, d *schema.ResourceData,
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["minimum_backoff"] =
flattenPubsubSubscriptionRetryPolicyMinimumBackoff(original["minimumBackoff"], d, config)
Expand Down Expand Up @@ -1927,9 +1924,14 @@ func expandPubsubSubscriptionDeadLetterPolicyMaxDeliveryAttempts(v interface{},

func expandPubsubSubscriptionRetryPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
if len(l) == 0 {
return nil, nil
}

if l[0] == nil {
transformed := make(map[string]interface{})
return transformed, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})
Expand Down
40 changes: 40 additions & 0 deletions google/services/pubsub/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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()

Expand Down Expand Up @@ -496,6 +520,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" { }
Expand Down

0 comments on commit 00a5231

Please sign in to comment.