terraform-google-modules/terraform-google-pubsub

Use schema already created in a new topic

Closed this issue · 5 comments

It's impossible to use a schema already created in a new topic, and that can be done in the GCP console. For example, I have this topic

module "pubsub-1" {
  source              = "git@gitlab.com:XXXXXX/terraform-google-pubsub"
  project_id          = var.project_id
  topic_labels        = local.labels

  topic = "test-topic"
  schema = {
    name       = "test-schema"
    type       = "AVRO"
    encoding   = "JSON"
    definition = "{\n  \"type\" : \"record\",\n  \"name\" : \"Avro\",\n  \"fields\" : [\n    {\n      \"name\" : \"StringField\",\n      \"type\" : \"string\"\n    },\n    {\n      \"name\" : \"IntField\",\n      \"type\" : \"int\"\n    }\n  ]\n}\n"
  }
}

But now if I want to create another topic (similar than this code) with the same schema I try to use the schema created with module "pubsub-1" and there isn't a way to call and old schema, or create exactly the same but only changing the name. The response in this last case doing terraform apply is:
Error: Error creating Schema: googleapi: Error 409: Resource already exists in the project (resource=projects/xxxxx/schemas/test-schema).

It cloud be interesting if there is a way to call by their id or their name another schema already created, via terraform or not. I think schemas are a property that must be shared with different topics, and I find it very inefficient to create a lot of schemas for every topic that I need.

Sorry btw if I'm not using the right terms.

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

Any updates here?

Yes, I'm running into same issue. Was thinking schemas needed to be bootstrapped in some way. But sounds like existing schema cannot be associated with new topic?

OK I push a PR to enable this, I didn't look yet at test.

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days