繁体   English   中英

从 terraform 创建的 pubsub 模式定义错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM