-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform script to automate GCP provisioning for gcplog #3206
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,8 @@ coverage.txt | |
|
||
# emacs | ||
.#* | ||
|
||
# terraform | ||
.terraform* | ||
*.tfstate* | ||
*.tfvars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Cloud provisioning for GCP logs | ||
|
||
This document covers how to configure your GCP via Terraform to make cloud logs available for `promtail` to consume. | ||
|
||
## Prerequisite | ||
- Terraform >= 0.14.5 | ||
- GCP Service account credentials with following roles/permissions | ||
- "roles/pubsub.editor" | ||
- "roles/logging.configWriter" | ||
|
||
## Usage | ||
|
||
```bash | ||
terraform init | ||
``` | ||
|
||
```bash | ||
terraform plan | ||
``` | ||
|
||
```bash | ||
terraform apply | ||
``` | ||
|
||
Terraform will prompt for following variables. | ||
|
||
1. credentials_file - ServiceAccount credentials file with permissions mentioned in the prerequisite. | ||
2. zone - GCP zone (e.g: `us-central1-b`) | ||
3. region - GCP region (e.g: `us-central1`) | ||
4. project - GCP Project ID | ||
5. 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: | ||
```bash | ||
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](https://www.terraform.io/docs/configuration/variables.html#assigning-values-to-root-module-variables) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "3.5.0" | ||
} | ||
} | ||
} | ||
|
||
variable "credentials_file" {} | ||
variable "zone" {} | ||
variable "region" {} | ||
variable "project" {} | ||
variable "logname" { | ||
default = "cloud-logs" | ||
} | ||
|
||
provider "google" { | ||
credentials = file(var.credentials_file) | ||
project = var.project | ||
zone = var.zone | ||
region= var.region | ||
|
||
} | ||
|
||
resource "google_pubsub_topic" "cloud-logs" { | ||
name= var.logname | ||
} | ||
|
||
resource "google_logging_project_sink" "cloud-logs" { | ||
name = var.logname | ||
destination = "pubsub.googleapis.com/projects/personal-226821/topics/${var.logname}" | ||
filter = "resource.type = gcs_bucket AND severity >= WARNING" | ||
unique_writer_identity = true | ||
} | ||
|
||
resource "google_pubsub_subscription" "coud-logs" { | ||
name = var.logname | ||
topic = google_pubsub_topic.cloud-logs.name | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently, filter is hardcoded. I will add it as variable in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add to the doc a small section about this filter, the langage , what it does, and let's suggest a sane default ? What do you think would be a good default for someone that wants to get visibility into his cloud ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a sane default. Perhaps we can link to GCP's filter documentation in the README, but I don't think we need to add much tooling here to change it -- this can serve as a template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with filter doc and sane defaults.
httpLoadBalancer
? so I added that. wdyt?