Google Cloud (Stackdriver) Logging Billing Account Sink

This page shows how to write Terraform for Cloud (Stackdriver) Logging Billing Account Sink and write them securely.

google_logging_billing_account_sink (Terraform)

The Billing Account Sink in Cloud (Stackdriver) Logging can be configured in Terraform with the resource name google_logging_billing_account_sink. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub

logging_billing_account_sink_test.tf#L6
resource "google_logging_billing_account_sink" "basic" {
  name            = "my-sink"
  description     = "what it is"
  billing_account = "00AA00-000AAA-00AA0A" # fake

  destination = "storage.googleapis.com/fake"
logging_billing_account_sink_test.tf#L6
resource "google_logging_billing_account_sink" "basic" {
  name            = "my-sink"
  description     = "what it is"
  billing_account = "00AA00-000AAA-00AA0A" # fake

  destination = "storage.googleapis.com/fake"
main.tf#L1
resource "google_logging_billing_account_sink" "sink" {
  count           = length(var.sink)
  billing_account = element(var.billing_account, lookup(var.sink[count.index], "billing_account_id"))
  destination     = element(var.destination, lookup(var.sink[count.index], "destination_id"))
  name            = lookup(var.sink[count.index], "name")
  filter          = lookup(var.sink[count.index], "filter")
main.tf#L7
resource "google_logging_billing_account_sink" "this" {
  billing_account = var.billing_account
  destination     = var.destination
  filter          = var.filter
  name            = var.name

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The billing account exported to the sink.

A description of this sink. The maximum length of the description is 8000 characters.

The destination of the sink (or, in other words, where logs are written to). Can be a Cloud Storage bucket, a PubSub topic, or a BigQuery dataset. Examples: "storage.googleapis.com/[GCS_BUCKET]" "bigquery.googleapis.com/projects/[PROJECT_ID]/datasets/[DATASET]" "pubsub.googleapis.com/projects/[PROJECT_ID]/topics/[TOPIC_ID]" The writer associated with the sink must have access to write to the above resource.

If set to True, then this sink is disabled and it does not export any log entries.

The filter to apply when exporting logs. Only log entries that match the filter are exported.

  • id optional computed - string
  • name required - string

The name of the logging sink.

The identity associated with this sink. This identity must be granted write access to the configured destination.

  • bigquery_options list block

    Whether to use BigQuery's partition tables. By default, Logging creates dated tables based on the log entries' timestamps, e.g. syslog_20170523. With partitioned tables the date suffix is no longer present and special query syntax has to be used instead. In both cases, tables are sharded based on UTC timezone.

  • exclusions list block

    A description of this exclusion.

    If set to True, then this exclusion is disabled and it does not exclude any log entries

    An advanced logs filter that matches the log entries to be excluded. By using the sample function, you can exclude less than 100% of the matching log entries

    A client-assigned identifier, such as "load-balancer-exclusion". Identifiers are limited to 100 characters and can include only letters, digits, underscores, hyphens, and periods. First character has to be alphanumeric.

Explanation in Terraform Registry

Frequently asked questions

What is Google Cloud (Stackdriver) Logging Billing Account Sink?

Google Cloud (Stackdriver) Logging Billing Account Sink is a resource for Cloud (Stackdriver) Logging of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud (Stackdriver) Logging Billing Account Sink?

For Terraform, the gilyas/infracost, infracost/infracost and mikamakusa/terraform source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.