-
Notifications
You must be signed in to change notification settings - Fork 67
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
Allow enabling usage logs on GCS storage buckets & enable for LEAP #3407
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
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 |
---|---|---|
|
@@ -11,6 +11,14 @@ resource "google_storage_bucket" "user_buckets" { | |
// Set these values explicitly so they don't "change outside terraform" | ||
labels = {} | ||
|
||
dynamic "logging" { | ||
for_each = each.value.usage_logs ? [1] : [] | ||
|
||
content { | ||
log_bucket = google_storage_bucket.usage_logs_bucket.name | ||
} | ||
} | ||
|
||
dynamic "lifecycle_rule" { | ||
for_each = each.value.delete_after != null ? [1] : [] | ||
|
||
|
@@ -26,6 +34,40 @@ resource "google_storage_bucket" "user_buckets" { | |
} | ||
} | ||
|
||
# Create GCS bucket that can store *usage* logs (access logs). | ||
# Helpful to see what data is *actually* being used. | ||
# https://cloud.google.com/storage/docs/access-logs | ||
# | ||
# We create this bucket unconditionally, because it costs nothing. | ||
# It only costs if we actually enable this logging, which is done in | ||
# per-bucket config. | ||
# | ||
# We only keep them for 30 days so they don't end up costing a | ||
# ton of money | ||
resource "google_storage_bucket" "usage_logs_bucket" { | ||
name = "${var.prefix}-gcs-usages-logs" | ||
location = var.region | ||
project = var.project_id | ||
|
||
labels = {} | ||
|
||
lifecycle_rule { | ||
condition { | ||
age = "30d" | ||
} | ||
action { | ||
type = "Delete" | ||
} | ||
} | ||
} | ||
|
||
# Provide access to GCS infrastructure to write usage logs to this bucket | ||
resource "google_storage_bucket_iam_member" "usage_logs_bucket_access" { | ||
bucket = google_storage_bucket.logging_bucket.name | ||
member = "group:[email protected]" | ||
role = "roles/storage.objectCreator" | ||
} | ||
|
||
locals { | ||
# Nested for loop, thanks to https://www.daveperrett.com/articles/2021/08/19/nested-for-each-with-terraform/ | ||
bucket_admin_permissions = distinct(flatten([ | ||
|
@@ -95,3 +137,14 @@ output "buckets" { | |
the full name of all GCS buckets created conveniently. | ||
EOT | ||
} | ||
|
||
output "usage_log_bucket" { | ||
value = google_storage_bucket.usage_logs_bucket.name | ||
description = <<-EOT | ||
Name of GCS bucket containing GCS usage logs (when enabled). | ||
|
||
https://cloud.google.com/storage/docs/access-logs has more information | ||
on GCS usage logs. It has to be enabled on a per-bucket basis - see | ||
the documentation for the `user_buckets` variable for more information. | ||
EOT | ||
} |
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 |
---|---|---|
|
@@ -30,29 +30,35 @@ filestore_capacity_gb = 2048 | |
user_buckets = { | ||
"scratch-staging" : { | ||
"delete_after" : 7, | ||
"extra_admin_members" : [] | ||
"extra_admin_members" : [], | ||
"usage_logs" : true, | ||
}, | ||
"scratch" : { | ||
"delete_after" : 7, | ||
"extra_admin_members" : [] | ||
"extra_admin_members" : [], | ||
"usage_logs" : true, | ||
} | ||
# For https://github.com/2i2c-org/infrastructure/issues/1230#issuecomment-1278183441 | ||
"persistent" : { | ||
"delete_after" : null, | ||
"extra_admin_members" : ["group:[email protected]"] | ||
"extra_admin_members" : ["group:[email protected]"], | ||
"usage_logs" : true, | ||
}, | ||
"persistent-staging" : { | ||
"delete_after" : null, | ||
"extra_admin_members" : ["group:[email protected]"] | ||
"extra_admin_members" : ["group:[email protected]"], | ||
"usage_logs" : true, | ||
} | ||
# For https://github.com/2i2c-org/infrastructure/issues/1230#issuecomment-1278183441 | ||
"persistent-ro" : { | ||
"delete_after" : null, | ||
"extra_admin_members" : ["group:[email protected]"], | ||
"usage_logs" : true, | ||
}, | ||
"persistent-ro-staging" : { | ||
"delete_after" : null, | ||
"extra_admin_members" : ["group:[email protected]"], | ||
"usage_logs" : true, | ||
} | ||
} | ||
|
||
|
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
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.
I think clarifying responsibility as done here as part of introducing this feature is super important - nice!!!