diff --git a/build/ansible b/build/ansible index c568d9f999f9..51392c3ad3f4 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit c568d9f999f99c78d51c0beb95a8d771a1afa8d6 +Subproject commit 51392c3ad3f4a380bd546c58953af156610e629b diff --git a/build/inspec b/build/inspec index 420198e28dc7..af20dd3090b3 160000 --- a/build/inspec +++ b/build/inspec @@ -1 +1 @@ -Subproject commit 420198e28dc74ae4148d8fc3b37c1a258f691053 +Subproject commit af20dd3090b3828b543a99dff627a79d445e6118 diff --git a/build/terraform b/build/terraform index 99a0847cb784..07af08027ed8 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 99a0847cb784c499a5fd4b35d36849530b26973c +Subproject commit 07af08027ed88a90f6ecfdee2ad71c048f005fa6 diff --git a/build/terraform-beta b/build/terraform-beta index 630150595afa..0bce4ac22cf4 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 630150595afab60d82aae4ec4e86c20a0c1fbfed +Subproject commit 0bce4ac22cf4ebf371a0a38d0c69b7b09876a65e diff --git a/build/terraform-mapper b/build/terraform-mapper index b6c460fbdaef..43007d527e20 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit b6c460fbdaef29a233b8aeb3402fd33f5eac296e +Subproject commit 43007d527e20b5357d5767f18cf465bb1ccc0d58 diff --git a/products/pubsub/api.yaml b/products/pubsub/api.yaml index d6e512f73eb2..432e0b143de0 100644 --- a/products/pubsub/api.yaml +++ b/products/pubsub/api.yaml @@ -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". diff --git a/products/pubsub/terraform.yaml b/products/pubsub/terraform.yaml index ede9b3d223f3..2fd93b3d164a 100644 --- a/products/pubsub/terraform.yaml +++ b/products/pubsub/terraform.yaml @@ -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 diff --git a/templates/terraform/constants/subscription.go.erb b/templates/terraform/constants/subscription.go.erb new file mode 100644 index 000000000000..187ca2e22d69 --- /dev/null +++ b/templates/terraform/constants/subscription.go.erb @@ -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 +} diff --git a/templates/terraform/examples/pubsub_subscription_pull.tf.erb b/templates/terraform/examples/pubsub_subscription_pull.tf.erb index 91c1b38fbb6a..b9e6c6590418 100644 --- a/templates/terraform/examples/pubsub_subscription_pull.tf.erb +++ b/templates/terraform/examples/pubsub_subscription_pull.tf.erb @@ -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" + } }