hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.25k stars 1.7k forks source link

Resource for Cloud Logging saved queries? #18023

Open michaelbannister opened 2 months ago

michaelbannister commented 2 months ago

Community Note

Description

I'm not sure if this is a recently-added feature but in Cloud Logging when you save a query you have the option to "share with project". This corresponds to setting {{visibility: SHARED}} in the SavedQuery resource

I'm in a platform team – we have 100+ engineering teams with GCP projects we've provisioned for them, and it'd be useful for us to provision some standard shared queries into their projects through our Terraform configuration.

It probably wouldn't make sense to provision a non-shared query through Terraform, so you might set that by default.

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_logging_project_saved_query" "app_errors" {
  display_name = "Kubernetes Job logs"
  description = "Only Job logs from your Kubernetes namespace"
  logging_query {
    filter = <<EOF
resource.type=k8s_container
-resource.labels.container_name="istio-proxy"
-resource.labels.container_name=istio-validation"
EOF
  }
  summary_fields = [
    "labels/\"k8s-pod/job-name\"" # awkward quoting here
  ]
}

References

No response

michaelbannister commented 2 months ago

(could add a log_analytics_query option later when that's out of preview – ref)