Skip to content

AckeeCZ/terraform-gcp-pubsub

Repository files navigation

PubSub Terraform Module

This module help us to keep our configuration standard. We had issues with forgetting correct SA permissions on DLQ. Having everything in a module can keep the issue away.

Usage

Everything could be defined in topics variable:

module "pubsub" {
  source  = "../"
  project = var.project
  topics = {
    "topic-a" : {}
    "topic-b" : {
      dlq : true
      users : [
        "user:test@example.com",
      ]
    }
    "topic-c" : {
      black_hole : true
    }
    "topic-d" : {
      dlq : true
      custom_dlq_postfix: "-dlq"
    }
  }
}

topics map items can have define following keys:

  • allow_dlq_users_to_push_into_dlq_topic [boolean] - once enabled, users from dlq_users can also push to dlq topics
  • black_hole [boolean] -- add subscription with fairly short 600s retention
  • dlq [boolean] -- add dead letter queue to the topic
  • custom_dlq_postfix [string] -- change dlq subscription postfix from -error to -${custom_dlq_postfix}
  • custom_dlq_name [string] -- custom name for dlq topic & subscription
  • max_delivery_attempts [number] -- check documentation
  • retry_policy [map(string)] -- check documentation
  • bigquery_config [map(string)] -- check documentation
  • enable_message_ordering [boolean] -- check documentation
  • custom_subscriptions [map(map(any))] -- accepts same arguments as topic, serves for custom subscription in case one is not enough
  • users [list(string)] -- list of users (with type, e.g: serviceAccount:..., ...), beware that any service account used as user has to be created before module usage
  • dlq_users [list(string)] -- list of users of DLQ subscription (with type, e.g: serviceAccount:..., ...), beware that any service account used as user has to be created before module usage
  • push_config [map(string)] -- check documentation
  • schema_definition [string] -- check documentation
  • schema_type [string] -- check documentation

Further examples are at example folder.

Requirements

Name Version
terraform >= 0.13

Providers

Name Version
google n/a

Modules

No modules.

Resources

Name Type
google_pubsub_subscription.black_hole resource
google_pubsub_subscription.default resource
google_pubsub_subscription.error_queue resource
google_pubsub_subscription_iam_member.dlq_user_subscribers resource
google_pubsub_subscription_iam_member.internal_subscribers resource
google_pubsub_subscription_iam_member.internal_subscribers_to_source_subscriptions resource
google_pubsub_subscription_iam_member.user_subscribers resource
google_pubsub_topic.default resource
google_pubsub_topic.dlq resource
google_pubsub_topic_iam_member.dlq_user_publishers resource
google_pubsub_topic_iam_member.internal_publishers resource
google_pubsub_topic_iam_member.user_publishers resource
google_project.project data source

Inputs

Name Description Type Default Required
project GCP project ID string n/a yes
topics Map of maps of topics to be created with default subscription map {} no

Outputs

Name Description
black_hole_subscriptions n/a
dlq_subscriptions n/a
dlq_topics n/a
subscriptions n/a
topics n/a