Reputation: 109
I create a notification channel for my alerts:
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 and subscriber:
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"
}
}
}
Name of the topic: "develop-alerts-topic". Problem with terraform output (In manual I create topic easy):
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/[^/]+".
Could you please help me understand the problem why I get an error (but all elements created)??
Upvotes: 0
Views: 1204
Reputation: 75715
You have to reuse your topic definition
resource "google_pubsub_topic" "pubsub_topic" {
name = "${var.pubsub_topic_name}"
}
In your subscription defintition, like this
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"
}
}
}
You have an example in the documentation
Upvotes: 1