Skip to content

Commit

Permalink
feat: Add support for expiration_policy (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyknows authored Jul 17, 2020
1 parent 4e452b5 commit feca6f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
]

Expand Down
14 changes: 14 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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]
}

0 comments on commit feca6f5

Please sign in to comment.