如何在GCP中使用Terraform脚本为单个主题创建多个订阅。

huangapple go评论94阅读模式
英文:

How to create multiple subscriptions for a single topic in a GCP using terraform scripts

问题

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
}

英文:

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?

  1. resource "google_pubsub_subscription" "example-1" {
  2. name = "example-1"
  3. topic = "{{topic-id}}"
  4. labels = {
  5. application = var.app_name
  6. business_unit = var.business_unit
  7. contact_email = var.contact_email
  8. name = var.app_name
  9. owner = var.owner
  10. }
  11. message_retention_duration = "1200s"
  12. retain_acked_messages = true
  13. filter = "attributes.KEY = \"value\""
  14. ack_deadline_seconds = 20
  15. retry_policy {
  16. minimum_backoff = "180s"
  17. }
  18. enable_message_ordering = true
  19. }

答案1

得分: 1

你可以使用 count。例如,要创建 3 个订阅:

  1. resource "google_pubsub_subscription" "example" {
  2. count = 3
  3. name = "example-${each.key}"
  4. topic = "{{topic-id}}"
  5. labels = {
  6. application = var.app_name
  7. business_unit = var.business_unit
  8. contact_email = var.contact_email
  9. name = var.app_name
  10. owner = var.owner
  11. }
  12. message_retention_duration = "1200s"
  13. retain_acked_messages = true
  14. filter = "attributes.KEY = \"value\""
  15. ack_deadline_seconds = 20
  16. retry_policy {
  17. minimum_backoff = "180s"
  18. }
  19. enable_message_ordering = true
  20. }
  21. }
英文:

You can use count. For example to create 3 subscriptions:

  1. resource "google_pubsub_subscription" "example" {
  2. count = 3
  3. name = "example-${each.key}"
  4. topic = "{{topic-id}}"
  5. labels = {
  6. application = var.app_name
  7. business_unit = var.business_unit
  8. contact_email = var.contact_email
  9. name = var.app_name
  10. owner = var.owner
  11. }
  12. message_retention_duration = "1200s"
  13. retain_acked_messages = true
  14. filter = "attributes.KEY = \"value\""
  15. ack_deadline_seconds = 20
  16. retry_policy {
  17. minimum_backoff = "180s"
  18. }
  19. enable_message_ordering = true
  20. }
  21. }

huangapple
  • 本文由 发表于 2023年2月10日 13:15:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407225.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定