[英]Invalid schema definition: Could not parse schema when creating PubSub subscription
[英]Error in pubsub schema definition creating from terraform
我正在使用 terraform 創建 GCP pubsub 模式。
當我手動創建 pubsub 模式時,我直接在提供的字段中復制粘貼模式並且沒有收到任何錯誤。
但是當我從 terraform 創建模式時,我必須用“\n”替換換行符。 是否有任何解決方案,這樣我就不會用“\n”代替顯式換行符。
我的 pubsub 模式代碼 terraform
resource "google_pubsub_schema" "schema" {
name = var.schema_name
type = var.schema_type
definition = var.schema_definition
}
不工作:產品團隊提供的格式,從 terraform 獲取錯誤
syntax = "proto3";
package com.sntl.proto;
message UsageMessageProto {
string tenantEnvId = 1;
string correlationId = 2;
UsageDataProto data = 3;
message UsageDataProto {
string identity = 1;
string sessionId = 2;
uint32 clientVersion = 3;
uint64 timeStamp = 4;
string authId = 5;
uint64 usageCountMultiplier = 6;
uint64 hardlimit = 7;
string machineId = 8;
string serviceId = 9;
uint64 vendorId = 10;
string logComment = 11;
}
}
工作:新的更改格式用“\n”替換換行符:
\n syntax = \"proto3\"; \n package com.sntl.proto; \n message UsageMessageProto { \n string tenantEnvId = 1; \n string correlationId = 2; \n UsageDataProto data = 3; \n message UsageDataProto { \n string identity = 1; \n string sessionId = 2; \n uint32 clientVersion = 3; \n uint64 timeStamp = 4; \n string authId = 5; \n uint64 usageCountMultiplier = 6; \n uint64 hardlimit = 7; \n string machineId = 8; \n string serviceId = 9; \n uint64 vendorId = 10; \n string logComment = 11;\n}\n}\n
我需要一個解決方案,這樣我就不必用“\n”代替顯式換行符。
這是一個如何使用的示例
resource "google_pubsub_schema" "test_schema" {
name = "test-schema"
project = var.google_project_id
type = "PROTOCOL_BUFFER"
definition = "syntax = 'proto3'; message TestSchema { string one = 1; string two = 2; string three = 3; }"
}
resource "google_pubsub_topic" "test_schema_topic" {
name = "test-schema-topic"
project = var.google_project_id
depends_on = [google_pubsub_schema.test_schema]
labels = {
"name" : "test"
"setup" : "terraform"
}
schema_settings {
schema = "projects/${var.google_project_id}/schemas/${google_pubsub_schema.test_schema.name}"
encoding = "JSON"
}
}
resource "google_pubsub_subscription" "test_schema_sub" {
project = var.google_project_id
name = "test-schema-sub"
topic = google_pubsub_topic.test_schema_topic.name
depends_on = [google_pubsub_topic.test_schema_topic]
}
節目遲到了,但將模式放在“messageProto.schema.json”之類的文件中然后在資源中使用模板文字定義:
resource "google_pubsub_schema" "schema" {
name = var.schema_name
type = var.schema_type
definition = "${file("./messageProto.schema.json")}"
}
這樣 json 將是一個單行字符串,同時您可以保留模式的縮進和結構。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.