简体   繁体   English

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

[英]Error in pubsub schema definition creating from terraform

I am creating GCP pubsub schema with terraform.我正在使用 terraform 创建 GCP pubsub 模式。

When I am creating pubsub schema manually I am directly copy paste schema in the provided field and didn't get any error.当我手动创建 pubsub 模式时,我直接在提供的字段中复制粘贴模式并且没有收到任何错误。

But when I am creating schema from terraform I have to replace newline with "\n".但是当我从 terraform 创建模式时,我必须用“\n”替换换行符。 Is there any solution so that I don't have put "\n" in place of newline explicit.是否有任何解决方案,这样我就不会用“\n”代替显式换行符。

My terraform code for pubsub schema我的 pubsub 模式代码 terraform

resource "google_pubsub_schema" "schema" {
  name = var.schema_name
  type = var.schema_type
  definition = var.schema_definition
}

Not working: Format provided by the product team, getting the error from terraform不工作:产品团队提供的格式,从 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;
}
}

Working: new change format replace newline with "\n":工作:新的更改格式用“\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

I need a solution so that I don't have to put "\n" in place of newline explicit.我需要一个解决方案,这样我就不必用“\n”代替显式换行符。

this is an example of how you can use这是一个如何使用的示例

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


Late to the show, but put the schema in a file like "messageProto.schema.json" Then in the resource use template literal at definition:节目迟到了,但将模式放在“messageProto.schema.json”之类的文件中然后在资源中使用模板文字定义:

   resource "google_pubsub_schema" "schema" {
      name = var.schema_name
      type = var.schema_type
      definition = "${file("./messageProto.schema.json")}"
    }

By this the json will be a one-liner string while you can keep the indentation and structure of the schema.这样 json 将是一个单行字符串,同时您可以保留模式的缩进和结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 架构定义无效:创建 PubSub 订阅时无法解析架构 - Invalid schema definition: Could not parse schema when creating PubSub subscription 尝试解析从 Google Cloud PubSub 检索到的协议缓冲区架构时出现“错误:非法令牌‘字符串’” - "Error: Illegal token 'string'" when trying to parse protocol buffer schema retrieved from Google Cloud PubSub 重复列类型的 PubSub 订阅错误 - Avro 架构 - PubSub Subscription error with REPEATED Column Type - Avro Schema TIMESTAMP 数据类型的 Pubsub 订阅错误:架构类型不兼容 - Pubsub Subscription error for TIMESTAMP data type: Incompatible schema type Terraform 创建原则时出错 - Terraform error while creating principles 使用 API 密钥从外部 IP 地址检索 PubSub Schema - Retrieve PubSub Schema from external IP address with API Key 创建对主题的 pubsub 订阅失败,出现错误:用户无权执行此操作 - Creating pubsub subscription to topic failed with error: User not authorized to perform this action 使用 Terraform 在 Azure 上创建 Liquid Map 时出错 - Error creating Liquid Map on Azure with Terraform 使用 terraform 在 aws_vpc 中创建 su.net 时出错 - Error creating subnet in aws_vpc with terraform 通过 Terraform 创建的 AWS Glue 中的架构错误无效 - Invalid Schema error in AWS Glue created via Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM