github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/tools/gcplog/README.md (about)

     1  # Cloud provisioning for GCP logs
     2  
     3  This document covers how to configure your GCP via Terraform to make cloud logs available for `promtail` to consume.
     4  
     5  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
     6  
     7  e.g: Export Google APP Engine logs
     8  ```bash
     9  resource.type="gae_app" AND
    10  severity>=ERROR
    11  ```
    12  
    13  e.g: Export Google HTTP Loadbalancer logs
    14  ```bash
    15  resource.type="http_load_balancer" AND
    16  httpRequest.status>=500
    17  ```
    18  You can read more about these log filters in [GCP logging](https://cloud.google.com/logging/docs/view/query-library)
    19  
    20  ## Prerequisite
    21  - Terraform >= 0.14.5
    22  - GCP Service account credentials with following roles/permissions
    23    - "roles/pubsub.editor"
    24    - "roles/logging.configWriter"
    25  
    26  ## Usage
    27  
    28  ```bash
    29  terraform init
    30  ```
    31  
    32  ```bash
    33  terraform plan
    34  ```
    35  
    36  ```bash
    37  terraform apply
    38  ```
    39  
    40  Terraform will prompt for following variables.
    41  
    42  1. credentials_file - ServiceAccount credentials file with permissions mentioned in the prerequisite.
    43  2. zone - GCP zone (e.g: `us-central1-b`)
    44  3. region - GCP region (e.g: `us-central1`)
    45  4. project - GCP Project ID
    46  5. name - name we use to create pubsub topics, log router and pubsub subscription.
    47  6. inclusion_filter - To include cloud resources to export.
    48  7. exclusions - Ignore these logs while exporting.
    49  
    50  you can pass these variables via CLI.
    51  
    52  e.g:
    53  ```bash
    54  terraform apply \
    55  -var="credentials_file=./permissions.json" \
    56  -var="zone=us-central1-b" \
    57  -var="region=us-central1" \
    58  -var="project=grafanalabs-dev" \
    59  -var="logname=cloud-logs"
    60  ```
    61  
    62  These variables can be passed in multiple ways. For complete reference refer terraform [doc](https://www.terraform.io/docs/configuration/variables.html#assigning-values-to-root-module-variables)