Error in pubsub schema definition creating from terraform

Viewed 358

I am creating GCP pubsub schema with terraform.

When I am creating pubsub schema manually I am directly copy paste schema in the provided field and didn't get any error.

But when I am creating schema from terraform I have to replace newline with "\n". Is there any solution so that I don't have put "\n" in place of newline explicit.

My terraform code for pubsub schema

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

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 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.

1 Answers

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


Related