forked from terraform-google-modules/terraform-google-pubsub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
81 lines (72 loc) · 2.49 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Copyright 2018 Google LLC
*
* 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.
*/
locals {
default_ack_deadline_seconds = 10
}
resource "google_pubsub_topic" "topic" {
count = var.create_topic ? 1 : 0
project = var.project_id
name = var.topic
labels = var.topic_labels
dynamic "message_storage_policy" {
for_each = var.message_storage_policy
content {
allowed_persistence_regions = message_storage_policy.key == "allowed_persistence_regions" ? message_storage_policy.value : null
}
}
}
resource "google_pubsub_subscription" "push_subscriptions" {
count = var.create_topic ? length(var.push_subscriptions) : 0
name = var.push_subscriptions[count.index].name
topic = google_pubsub_topic.topic.0.name
project = var.project_id
ack_deadline_seconds = lookup(
var.push_subscriptions[count.index],
"ack_deadline_seconds",
local.default_ack_deadline_seconds,
)
message_retention_duration = lookup(
var.push_subscriptions[count.index],
"message_retention_duration",
null,
)
push_config {
push_endpoint = var.push_subscriptions[count.index]["push_endpoint"]
// FIXME: This should be programmable, but nested map isn't supported at this time.
// https://github.com/hashicorp/terraform/issues/2114
attributes = {
x-goog-version = lookup(var.push_subscriptions[count.index], "x-goog-version", "v1")
}
}
depends_on = [google_pubsub_topic.topic]
}
resource "google_pubsub_subscription" "pull_subscriptions" {
count = var.create_topic ? length(var.pull_subscriptions) : 0
name = var.pull_subscriptions[count.index].name
topic = google_pubsub_topic.topic.0.name
project = var.project_id
ack_deadline_seconds = lookup(
var.pull_subscriptions[count.index],
"ack_deadline_seconds",
local.default_ack_deadline_seconds,
)
message_retention_duration = lookup(
var.pull_subscriptions[count.index],
"message_retention_duration",
null,
)
depends_on = [google_pubsub_topic.topic]
}