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

Add enableMessageOrdering to Pub/Sub Subscription #7039

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/3872.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
pubsub: Added `enable_message_ordering` support to `google_pubsub_subscription`
```
34 changes: 34 additions & 0 deletions google/resource_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ If this parameter is 0, a default value of 5 is used.`,
},
},
},
"enable_message_ordering": {
Type: schema.TypeBool,
Optional: true,
Description: `If 'true', messages published with the same orderingKey in PubsubMessage will be delivered to
the subscribers in the order in which they are received by the Pub/Sub system. Otherwise, they
may be delivered in any order.`,
},
"expiration_policy": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -359,6 +366,12 @@ func resourcePubsubSubscriptionCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("dead_letter_policy"); ok || !reflect.DeepEqual(v, deadLetterPolicyProp) {
obj["deadLetterPolicy"] = deadLetterPolicyProp
}
enableMessageOrderingProp, err := expandPubsubSubscriptionEnableMessageOrdering(d.Get("enable_message_ordering"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_message_ordering"); !isEmptyValue(reflect.ValueOf(enableMessageOrderingProp)) && (ok || !reflect.DeepEqual(v, enableMessageOrderingProp)) {
obj["enableMessageOrdering"] = enableMessageOrderingProp
}

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

return nil
}
Expand Down Expand Up @@ -548,6 +564,12 @@ func resourcePubsubSubscriptionUpdate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("dead_letter_policy"); ok || !reflect.DeepEqual(v, deadLetterPolicyProp) {
obj["deadLetterPolicy"] = deadLetterPolicyProp
}
enableMessageOrderingProp, err := expandPubsubSubscriptionEnableMessageOrdering(d.Get("enable_message_ordering"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enable_message_ordering"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableMessageOrderingProp)) {
obj["enableMessageOrdering"] = enableMessageOrderingProp
}

obj, err = resourcePubsubSubscriptionUpdateEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -589,6 +611,10 @@ func resourcePubsubSubscriptionUpdate(d *schema.ResourceData, meta interface{})
if d.HasChange("dead_letter_policy") {
updateMask = append(updateMask, "deadLetterPolicy")
}

if d.HasChange("enable_message_ordering") {
updateMask = append(updateMask, "enableMessageOrdering")
}
// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -796,6 +822,10 @@ func flattenPubsubSubscriptionDeadLetterPolicyMaxDeliveryAttempts(v interface{},
return v // let terraform core handle it otherwise
}

func flattenPubsubSubscriptionEnableMessageOrdering(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 @@ -991,6 +1021,10 @@ func expandPubsubSubscriptionDeadLetterPolicyMaxDeliveryAttempts(v interface{},
return v, nil
}

func expandPubsubSubscriptionEnableMessageOrdering(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
2 changes: 2 additions & 0 deletions google/resource_pubsub_subscription_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ resource "google_pubsub_subscription" "example" {
expiration_policy {
ttl = "300000.5s"
}

enable_message_ordering = false
}
`, context)
}
Expand Down
1 change: 1 addition & 0 deletions google/resource_pubsub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ resource "google_pubsub_subscription" "foo" {
expiration_policy {
ttl = ""
}
enable_message_ordering = false
}
`, topic, subscription)
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/pubsub_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ resource "google_pubsub_subscription" "example" {
expiration_policy {
ttl = "300000.5s"
}

enable_message_ordering = false
}
```
## Example Usage - Pubsub Subscription Different Project
Expand Down Expand Up @@ -228,6 +230,12 @@ The following arguments are supported:
permission to Acknowledge() messages on this subscription.
Structure is documented below.

* `enable_message_ordering` -
(Optional)
If `true`, messages published with the same orderingKey in PubsubMessage will be delivered to
the subscribers in the order in which they are received by the Pub/Sub system. Otherwise, they
may be delivered in any order.

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

Expand Down