Managing Google Cloud Storage (GCS) Log Sources with Terraform (Beta)

Manage GCS log sources as code in Terraform

Overview

Managing Google Cloud Storage (GCS) log sources with Terraform is in open beta starting with Panther version 1.121, and is available to all customers. Please share any bug reports and feature requests with your Panther support team.

You can define your Google Cloud Storage (GCS) log source in Terraform using the Panther Terraform provider. This allows you to manage your GCS log sources as infrastructure as code, enabling version control and automated deployments.

Other methods to create a GCS log source include using the Panther API directly and manual creation in the Panther Console.

How to define your Panther GCS log source in Terraform

The following sections outline how to define your GCS log source in HashiCorp Configuration Language (HCL).

Prerequisites

Step 1: Choose an authentication method

Select an authentication method for accessing your GCS bucket:

  • Service Account: Uses a Google Cloud service account with a JSON key file

  • Workload Identity Federation: Uses Google Cloud Workload Identity Federation with AWS

The authentication method you select will determine the variables you define in Step 2, below.

Step 2: Define variables

Define a variables.tf file with the variables shown in the code block below.

Step 3: Provide values for the defined variables

Add a *.tfvars file that assigns values to the variables you defined in Step 2. Note that to complete this section, you will need the API URL and token outlined in the Prerequisites section.

  • Your panther_api_url value should be your root API URL. This is either:

Authentication method-specific variables

In your variables.tf file, include the values in the Additional variables column below for the authentication method you chose in Step 1.

The credentials_type field must match the type of credentials provided in the credentials field.

Authentication method
credentials_type value
Additional variables

Service account authentication

service_account

credentials (JSON keyfile content)

Workload Identity Federation authentication

wif

credentials (credential configuration file content), project_id

Step 4: Define the Terraform provider

Add the Panther Terraform provider.

Step 5: Define Panther GCS log source

The following HCL configuration defines the GCS log source in Panther.

Prefix-based log type mapping

Unlike HTTP or S3 sources that use a simple array of log types, GCS sources use prefix_log_types to map different prefixes within the bucket to specific log types:

  • prefix: The GCS object prefix to match (e.g., "audit-logs/", "application-logs/")

  • excluded_prefixes: Optional array of prefixes to exclude within the main prefix

  • log_types: Array of log type schemas to apply to objects matching this prefix

This allows a single GCS bucket to contain multiple types of logs organized by prefix, with different schemas applied to each.

Complete example

For a complete working example with GCP infrastructure setup, see the Panther auxiliary repository.

Last updated

Was this helpful?