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 expiration policy to pubsub subscription resource #1703

Merged
merged 2 commits into from
May 3, 2019
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
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
20 changes: 20 additions & 0 deletions products/pubsub/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,23 @@ objects:
messages are not expunged from the subscription's backlog, even if
they are acknowledged, until they fall out of the
messageRetentionDuration window.
- !ruby/object:Api::Type::NestedObject
name: 'expirationPolicy'
description: |
A policy that specifies the conditions for this subscription's expiration.
A subscription is considered active as long as any connected subscriber
is successfully consuming messages from the subscription or is issuing
operations on the subscription. If expirationPolicy is not set, a default
policy with ttl of 31 days will be used. The minimum allowed value for
expirationPolicy.ttl is 1 day.
properties:
- !ruby/object:Api::Type::String
name: 'ttl'
description: |
Specifies the "time-to-live" duration for an associated resource. The
resource expires if it is not active for a period of ttl. The definition
of "activity" depends on the type of the associated resource. The minimum
and maximum allowed values for ttl depend on the type of the associated
resource, as well. If ttl is not set, the associated resource never expires.
A duration in seconds with up to nine fractional digits, terminated by 's'.
Example - "3.5s".
7 changes: 6 additions & 1 deletion products/pubsub/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_expand: templates/terraform/custom_expand/computed_subscription_topic.erb
ackDeadlineSeconds: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
expirationPolicy: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
expirationPolicy.ttl: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: 'comparePubsubSubscriptionExpirationPolicy'
custom_code: !ruby/object:Provider::Terraform::CustomCode
extra_schema_entry: templates/terraform/extra_schema_entry/pubsub_subscription_path.erb
constants: templates/terraform/constants/subscription.go.erb
decoder: templates/terraform/decoders/pubsub_subscription.erb
extra_schema_entry: templates/terraform/extra_schema_entry/pubsub_subscription_path.erb
update_encoder: templates/terraform/update_encoder/pubsub_subscription.erb


Expand Down
26 changes: 26 additions & 0 deletions templates/terraform/constants/subscription.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%- # the license inside this block applies to this file
# Copyright 2019 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>

func comparePubsubSubscriptionExpirationPolicy(_, old, new string, _ *schema.ResourceData) bool {
trimmedNew := strings.TrimLeft(new, "0")
trimmedOld := strings.TrimLeft(old, "0")
if strings.Contains(trimmedNew, ".") {
trimmedNew = strings.TrimRight(strings.TrimSuffix(trimmedNew, "s"), "0") + "s"
}
if strings.Contains(trimmedOld, ".") {
trimmedOld = strings.TrimRight(strings.TrimSuffix(trimmedOld, "s"), "0") + "s"
}
return trimmedNew == trimmedOld
}
4 changes: 4 additions & 0 deletions templates/terraform/examples/pubsub_subscription_pull.tf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ resource "google_pubsub_subscription" "<%= ctx[:primary_resource_id] %>" {
retain_acked_messages = true

ack_deadline_seconds = 20

expiration_policy {
ttl = "300000.5s"
}
}