Our next-gen architecture is built to help you make sense of your ever-growing data Watch a 4-min demo video!

Back to All Integrations

Terraform Modules for GCP Pub/Sub Terraform Modules for GCP Pub/Sub

Last Updated: Aug. 14, 2022

Terraform simplifies the way we deploy our infrastructure and allows us to maintain it as code.

Using our Terraform Modules, you can easily install and manage Coralogix integrations with GCP services as modules in your infrastructure code.

Our modules are open source and available on our Github and in the Terraform Registry.


This module will be installing our function app that gets messages from your Pub/Sub topic and sends logs to Coralogix.

For more information about the Function itself, dynamic applicationName and subsystemName and multiline support visit our Pub/Sub guide.

To use the module, first, add the provider configure block to your Terraform project:

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = ">= 4.31.0"

provider "google" {
  project = "your-project-id"
  region  = "your-region"

Then simply add this declaration to your Terraform project:

module "pubsub" {
  source = "coralogix/google/coralogix//modules/pubsub"

  coralogix_region = "Europe"
  private_key      = "2f55c873-c0cf-4523-82d4-c3b68ee6cb46"
  application_name = "Pub/Sub"
  subsystem_name   = "logs"
  topic           = "test-topic-name"

Important variables to change:

  • coralogix_region – The Coralogix location region, possible options are [Europe, Europe2, India, Singapore, US]
  • private_key – The Coralogix private key which is used to validate your authenticity (can be retrieved from the coralogix dashboard in Dataflow -> API Keys -> Send Your Data key)
  • application_name – The received logs applicationName.
  • subsystem_name – The received logs subsystemName.
  • topic – Your GCP Pub/Sub topic name.

Configuring a sink

When configuring a GCP logs router sink to catch logs from different resources andthem send to a pub/sub topic be sure to EXCLUDE the function created above from the sink.

NOTE- not following the next step will result in an infinite loop in your GCP function, RESULTING IN HIGH GCP COST; please proceed with caution.

resource "google_logging_project_sink" "logs-sink" {
  name        = "logs-sink"
  destination = "pubsub.googleapis.com/projects/<my-project-name>/topics/<my-pubsub-topic-name>"

  exclusions {
    name        = "pub-sub-func"
    description = "Exclude logs from the coralogix pub-sub function"
    filter      = "resource.labels.function_name=\"${module.pubsub.function}\""

  unique_writer_identity = true

Note: replace <my-project-name> and <my-pubsub-topic-name> with your relevant values.

We also have a Terraform Provider to help manage your Coralogix resources such as rules and alerts. Learn more about the Coralogix Terraform Provider and how to install it here.

If you have any questions, feel free to reach out to our team via our in-app chat!

On this page