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

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

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?

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
}

答案1

得分: 1

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

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
}
}
英文:

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
}
}

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:

确定