This document covers how to configure your GCP via Terraform to make cloud logs available for promtail to consume.
To choose what logs need to exported from Google Cloud, we use log filters. Log filters are normal GCP logging queries except the goal is export logs from specific set Google cloud resources
e.g: Export Google APP Engine logs
resource.type="gae_app" AND
severity>=ERRORe.g: Export Google HTTP Loadbalancer logs
resource.type="http_load_balancer" AND
httpRequest.status>=500You can read more about these log filters in GCP logging
- Terraform >= 0.14.5
- GCP Service account credentials with following roles/permissions
- "roles/pubsub.editor"
- "roles/logging.configWriter"
terraform initterraform planterraform applyTerraform will prompt for following variables.
- credentials_file - ServiceAccount credentials file with permissions mentioned in the prerequisite.
- zone - GCP zone (e.g:
us-central1-b) - region - GCP region (e.g:
us-central1) - project - GCP Project ID
- logname - Logname is the name we use to create pubsub topics, log router and pubsub subscription.
you can pass these variables via CLI.
e.g:
terraform apply \
-var="credentials_file=./permissions.json" \
-var="zone=us-central1-b" \
-var="region=us-central1" \
-var="project=grafanalabs-dev" \
-var="logname=cloud-logs"These variables can be passed in multiple ways. For complete reference refer terraform doc