Reputation: 662
Currently, I have a pub-sub topic, for which I have to create multiple subscribers which access messages published on that topic. l am using terraform scripts to create the subscription. This script is used to create a single subscriber for a topic. How can I modify the script to include multiple subscriber?
resource "google_pubsub_subscription" "example-1" {
name = "example-1"
topic = "{{topic-id}}"
labels = {
application = var.app_name
business_unit = var.business_unit
contact_email = var.contact_email
name = var.app_name
owner = var.owner
}
message_retention_duration = "1200s"
retain_acked_messages = true
filter = "attributes.KEY = \"value\""
ack_deadline_seconds = 20
retry_policy {
minimum_backoff = "180s"
}
enable_message_ordering = true
}
Upvotes: -1
Views: 742
Reputation: 238259
You can use count. For example to create 3 subscriptions:
resource "google_pubsub_subscription" "example" {
count = 3
name = "example-${each.key}"
topic = "{{topic-id}}"
labels = {
application = var.app_name
business_unit = var.business_unit
contact_email = var.contact_email
name = var.app_name
owner = var.owner
}
message_retention_duration = "1200s"
retain_acked_messages = true
filter = "attributes.KEY = \"value\""
ack_deadline_seconds = 20
retry_policy {
minimum_backoff = "180s"
}
enable_message_ordering = true
}
}
Upvotes: 1