Terraform GCPt:值与主题名称中的正则表达式不匹配

Terraform GCPt: Value does not match the regular expression in topic name

我为我的提醒创建了一个通知渠道:

resource "google_monitoring_notification_channel" "slack_notification_channel" {
  display_name = "${var.project_name_prefix}-notification-channel"
  type         = "pubsub"
  labels = {
    topic = "${var.pubsub_topic_name}"
  }
}

Public 和订阅者:

resource "google_pubsub_topic" "pubsub_topic" {
  name = "${var.pubsub_topic_name}"
}

resource "google_pubsub_subscription" "pubsub_subscription" {
  name  = "${var.project_name_prefix}-subscription"
  topic = "${var.pubsub_topic_name}"

  ack_deadline_seconds = 10

  push_config {
    push_endpoint = "${var.push_endpoint_link}"

    attributes = {
      x-goog-version = "v1"
    }
  }
}

主题名称:“develop-alerts-topic”。 terraform 输出问题(在手册中我创建主题很简单):

googleapi: Error 400: Field notification_channel.labels[topic] had an invalid value of "develop-alerts-topic": Value does not match the regular expression "projects/[^/]+/topics/[^/]+".

你能帮我理解为什么我会出错(但所有元素都已创建)吗??

您必须重复使用您的主题定义

resource "google_pubsub_topic" "pubsub_topic" {
  name = "${var.pubsub_topic_name}"
}

在您的订阅定义中,像这样

resource "google_pubsub_subscription" "pubsub_subscription" {
  name  = "${var.project_name_prefix}-subscription"
  # Reuse the definition of your topic. and get the name
  topic = google_pubsub_topic.pubsub_topic.name

  ack_deadline_seconds = 10

  push_config {
    push_endpoint = "${var.push_endpoint_link}"

    attributes = {
      x-goog-version = "v1"
    }
  }
}

你在the documentation

中有一个例子