Skip to content

Commit

Permalink
Add enable_exactly_once_delivery to google_pubsub_subscription (#…
Browse files Browse the repository at this point in the history
…5849) (#11384)

Co-authored-by: upodroid <cy@borg.dev>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: upodroid <cy@borg.dev>
  • Loading branch information
modular-magician and upodroid authored Mar 31, 2022
1 parent 4e68e70 commit 528e0f8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/5849.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
pubsub: added `enable_exactly_once_delivery` to `google_pubsub_subscription`
```
33 changes: 32 additions & 1 deletion google/resource_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ If this parameter is 0, a default value of 5 is used.`,
},
},
},
"enable_exactly_once_delivery": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `If 'true', Pub/Sub provides the following guarantees for the delivery
of a message with a given value of messageId on this Subscriptions':
- The message sent to a subscriber is guaranteed not to be resent before the message's acknowledgement deadline expires.
- An acknowledged message will not be resent to a subscriber.
Note that subscribers may still receive multiple copies of a message when 'enable_exactly_once_delivery'
is true if the message was published multiple times by a publisher client. These copies are considered distinct by Pub/Sub and have distinct messageId values`,
},
"enable_message_ordering": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -194,7 +208,7 @@ you can't modify the filter.`,
Optional: true,
Description: `How long to retain unacknowledged messages in the subscription's
backlog, from the moment a message is published. If
retainAckedMessages is true, then this also configures the retention
retain_acked_messages is true, then this also configures the retention
of acknowledged messages, and thus configures how far back in time a
subscriptions.seek can be done. Defaults to 7 days. Cannot be more
than 7 days ('"604800s"') or less than 10 minutes ('"600s"').
Expand Down Expand Up @@ -408,6 +422,12 @@ func resourcePubsubSubscriptionCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("enable_message_ordering"); !isEmptyValue(reflect.ValueOf(enableMessageOrderingProp)) && (ok || !reflect.DeepEqual(v, enableMessageOrderingProp)) {
obj["enableMessageOrdering"] = enableMessageOrderingProp
}
enableExactlyOnceDeliveryProp, err := expandPubsubSubscriptionEnableExactlyOnceDelivery(d.Get("enable_exactly_once_delivery"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_exactly_once_delivery"); !isEmptyValue(reflect.ValueOf(enableExactlyOnceDeliveryProp)) && (ok || !reflect.DeepEqual(v, enableExactlyOnceDeliveryProp)) {
obj["enableExactlyOnceDelivery"] = enableExactlyOnceDeliveryProp
}

obj, err = resourcePubsubSubscriptionEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -560,6 +580,9 @@ func resourcePubsubSubscriptionRead(d *schema.ResourceData, meta interface{}) er
if err := d.Set("enable_message_ordering", flattenPubsubSubscriptionEnableMessageOrdering(res["enableMessageOrdering"], d, config)); err != nil {
return fmt.Errorf("Error reading Subscription: %s", err)
}
if err := d.Set("enable_exactly_once_delivery", flattenPubsubSubscriptionEnableExactlyOnceDelivery(res["enableExactlyOnceDelivery"], d, config)); err != nil {
return fmt.Errorf("Error reading Subscription: %s", err)
}

return nil
}
Expand Down Expand Up @@ -925,6 +948,10 @@ func flattenPubsubSubscriptionEnableMessageOrdering(v interface{}, d *schema.Res
return v
}

func flattenPubsubSubscriptionEnableExactlyOnceDelivery(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func expandPubsubSubscriptionName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return replaceVars(d, config, "projects/{{project}}/subscriptions/{{name}}")
}
Expand Down Expand Up @@ -1160,6 +1187,10 @@ func expandPubsubSubscriptionEnableMessageOrdering(v interface{}, d TerraformRes
return v, nil
}

func expandPubsubSubscriptionEnableExactlyOnceDelivery(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func resourcePubsubSubscriptionEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
delete(obj, "name")
return obj, nil
Expand Down
11 changes: 6 additions & 5 deletions google/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAccPubsubSubscription_basic(t *testing.T) {
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPubsubSubscription_basic(topic, subscription, "bar", 20),
Config: testAccPubsubSubscription_basic(topic, subscription, "bar", 20, false),
},
{
ResourceName: "google_pubsub_subscription.foo",
Expand All @@ -68,7 +68,7 @@ func TestAccPubsubSubscription_update(t *testing.T) {
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "bar", 20),
Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "bar", 20, false),
},
{
ResourceName: "google_pubsub_subscription.foo",
Expand All @@ -77,7 +77,7 @@ func TestAccPubsubSubscription_update(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "baz", 30),
Config: testAccPubsubSubscription_basic(topic, subscriptionShort, "baz", 30, true),
},
{
ResourceName: "google_pubsub_subscription.foo",
Expand Down Expand Up @@ -209,7 +209,7 @@ resource "google_pubsub_subscription" "foo" {
`, saAccount, topicFoo, subscription)
}

func testAccPubsubSubscription_basic(topic, subscription, label string, deadline int) string {
func testAccPubsubSubscription_basic(topic, subscription, label string, deadline int, exactlyOnceDelivery bool) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
name = "%s"
Expand All @@ -226,8 +226,9 @@ resource "google_pubsub_subscription" "foo" {
minimum_backoff = "60.0s"
}
ack_deadline_seconds = %d
enable_exactly_once_delivery = %t
}
`, topic, subscription, label, deadline)
`, topic, subscription, label, deadline, exactlyOnceDelivery)
}

func testAccPubsubSubscription_topicOnly(topic string) string {
Expand Down
11 changes: 10 additions & 1 deletion website/docs/r/pubsub_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ The following arguments are supported:
(Optional)
How long to retain unacknowledged messages in the subscription's
backlog, from the moment a message is published. If
retainAckedMessages is true, then this also configures the retention
retain_acked_messages is true, then this also configures the retention
of acknowledged messages, and thus configures how far back in time a
subscriptions.seek can be done. Defaults to 7 days. Cannot be more
than 7 days (`"604800s"`) or less than 10 minutes (`"600s"`).
Expand Down Expand Up @@ -254,6 +254,15 @@ The following arguments are supported:
the subscribers in the order in which they are received by the Pub/Sub system. Otherwise, they
may be delivered in any order.

* `enable_exactly_once_delivery` -
(Optional)
If `true`, Pub/Sub provides the following guarantees for the delivery
of a message with a given value of messageId on this Subscriptions':
- The message sent to a subscriber is guaranteed not to be resent before the message's acknowledgement deadline expires.
- An acknowledged message will not be resent to a subscriber.
Note that subscribers may still receive multiple copies of a message when `enable_exactly_once_delivery`
is true if the message was published multiple times by a publisher client. These copies are considered distinct by Pub/Sub and have distinct messageId values

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down

0 comments on commit 528e0f8

Please sign in to comment.