From feca6f52d87721b22d4d97e83eb97c0270228159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramon=20R=C3=BCttimann?= Date: Fri, 17 Jul 2020 20:34:07 +0200 Subject: [PATCH] feat: Add support for expiration_policy (#23) --- README.md | 1 + examples/simple/main.tf | 1 + main.tf | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 765b847..e15282b 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ module "pubsub" { ack_deadline_seconds = 20 // optional push_endpoint = "https://example.com" // required x-goog-version = "v1beta1" // optional + expiration_policy = "1209600s" // optional } ] pull_subscriptions = [ diff --git a/examples/simple/main.tf b/examples/simple/main.tf index 5a4e3c1..df44301 100644 --- a/examples/simple/main.tf +++ b/examples/simple/main.tf @@ -38,6 +38,7 @@ module "pubsub" { push_endpoint = "https://${var.project_id}.appspot.com/" x-goog-version = "v1beta1" ack_deadline_seconds = 20 + expiration_policy = "1209600s" // two weeks }, ] diff --git a/main.tf b/main.tf index c70ebac..f9dd2c2 100644 --- a/main.tf +++ b/main.tf @@ -48,6 +48,13 @@ resource "google_pubsub_subscription" "push_subscriptions" { "message_retention_duration", null, ) + dynamic "expiration_policy" { + // check if the 'expiration_policy' key exists, if yes, return a list containing it. + for_each = contains(keys(var.push_subscriptions[count.index]), "expiration_policy") ? [var.push_subscriptions[count.index].expiration_policy] : [] + content { + ttl = expiration_policy.value + } + } push_config { push_endpoint = var.push_subscriptions[count.index]["push_endpoint"] @@ -77,6 +84,13 @@ resource "google_pubsub_subscription" "pull_subscriptions" { "message_retention_duration", null, ) + dynamic "expiration_policy" { + // check if the 'expiration_policy' key exists, if yes, return a list containing it. + for_each = contains(keys(var.pull_subscriptions[count.index]), "expiration_policy") ? [var.pull_subscriptions[count.index].expiration_policy] : [] + content { + ttl = expiration_policy.value + } + } depends_on = [google_pubsub_topic.topic] }