diff --git a/modules/pubsub/README.md b/modules/pubsub/README.md index d20d1cc42..024f2889e 100644 --- a/modules/pubsub/README.md +++ b/modules/pubsub/README.md @@ -136,7 +136,7 @@ module "pubsub" { | [message_retention_duration](variables.tf#L62) | Minimum duration to retain a message after it is published to the topic. | string | | null | | [push_configs](variables.tf#L78) | Push subscription configurations. | map(object({…})) | | {} | | [regions](variables.tf#L91) | List of regions used to set persistence policy. | list(string) | | [] | -| [schema](variables.tf#L118) | Topic schema. If set, all messages in this topic should follow this schema. | object({…}) | | null | +| [schema](variables.tf#L118) | Topic schema. If set, all messages in this topic should follow this schema. | object({…}) | | null | | [subscription_iam](variables.tf#L97) | IAM bindings for subscriptions in {SUBSCRIPTION => {ROLE => [MEMBERS]}} format. | map(map(list(string))) | | {} | | [subscriptions](variables.tf#L103) | Topic subscriptions. Also define push configs for push subscriptions. If options is set to null subscription defaults will be used. Labels default to topic labels if set to null. | map(object({…})) | | {} | @@ -145,10 +145,11 @@ module "pubsub" { | name | description | sensitive | |---|---|:---:| | [id](outputs.tf#L17) | Topic id. | | -| [schema](outputs.tf#L59) | Schema resource. | | -| [schema_id](outputs.tf#L51) | Schema resource id. | | +| [schema](outputs.tf#L43) | Schema resource. | | +| [schema_id](outputs.tf#L48) | Schema resource id. | | +| [schema_id](outputs.tf#L61) | Schema resource id. | | | [subscription_id](outputs.tf#L25) | Subscription ids. | | | [subscriptions](outputs.tf#L35) | Subscription resources. | | -| [topic](outputs.tf#L43) | Topic resource. | | +| [topic](outputs.tf#L53) | Topic resource. | | diff --git a/modules/pubsub/main.tf b/modules/pubsub/main.tf index b0beb8b7d..aa63e8c02 100644 --- a/modules/pubsub/main.tf +++ b/modules/pubsub/main.tf @@ -37,7 +37,7 @@ locals { resource "google_pubsub_schema" "default" { count = var.schema == null ? 0 : 1 - name = format("%s-%s", var.name, "schema") + name = "{$var.name}-schema" type = var.schema.schema_type definition = var.schema.definition project = var.project_id @@ -57,7 +57,6 @@ resource "google_pubsub_topic" "default" { } } - depends_on = [google_pubsub_schema.default] dynamic "schema_settings" { for_each = var.schema == null ? [] : [""] content { diff --git a/modules/pubsub/outputs.tf b/modules/pubsub/outputs.tf index 971a1f341..9c5a6a6ee 100644 --- a/modules/pubsub/outputs.tf +++ b/modules/pubsub/outputs.tf @@ -40,6 +40,16 @@ output "subscriptions" { ] } +output "schema" { + description = "Schema resource." + value = try(google_pubsub_schema.default[0], null) +} + +output "schema_id" { + description = "Schema resource id." + value = try(google_pubsub_schema.default[0].id, null) +} + output "topic" { description = "Topic resource." value = google_pubsub_topic.default @@ -51,15 +61,5 @@ output "topic" { output "schema_id" { description = "Schema resource id." value = google_pubsub_schema.default[0].id - depends_on = [ - google_pubsub_schema.default - ] } -output "schema" { - description = "Schema resource." - value = google_pubsub_schema.default[0] - depends_on = [ - google_pubsub_schema.default - ] -} diff --git a/modules/pubsub/variables.tf b/modules/pubsub/variables.tf index 503ff6907..c84168eae 100644 --- a/modules/pubsub/variables.tf +++ b/modules/pubsub/variables.tf @@ -94,6 +94,16 @@ variable "regions" { default = [] } +variable "schema" { + description = "Topic schema. If set, all messages in this topic should follow this schema." + type = object({ + definition = string + msg_encoding = optional(string, "ENCODING_UNSPECIFIED") + schema_type = string + }) + default = null +} + variable "subscription_iam" { description = "IAM bindings for subscriptions in {SUBSCRIPTION => {ROLE => [MEMBERS]}} format." type = map(map(list(string))) @@ -114,13 +124,3 @@ variable "subscriptions" { })) default = {} } - -variable "schema" { - description = "Topic schema. If set, all messages in this topic should follow this schema." - type = object({ - schema_type = string - definition = string - msg_encoding = optional(string, "ENCODING_UNSPECIFIED") - }) - default = null -}