-
Notifications
You must be signed in to change notification settings - Fork 565
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
feat: Add support for configuring pubsub object notifications #48
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
locals { | ||
# [for o in var.list : o.interfaces[0].name] | ||
topics = [for o in var.bucket_configs : o.topic] | ||
} | ||
|
||
# Create the notifications | ||
resource "google_storage_notification" "notifications" { | ||
for_each = var.bucket_configs | ||
|
||
# project_id = var.project_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think you meant to remove this? |
||
bucket = lookup(each.value, "bucket") | ||
payload_format = "JSON_API_V1" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the |
||
topic = lookup(each.value, "topic") | ||
event_types = var.event_types | ||
|
||
depends_on = [module.pubsub-iam-bindings.members] | ||
} | ||
|
||
# Enable IAM | ||
data "google_storage_project_service_account" "gcs_account" { | ||
project = var.project_id | ||
} | ||
|
||
module "pubsub-iam-bindings" { | ||
source = "terraform-google-modules/iam/google//modules/pubsub_topics_iam" | ||
version = "~> 5.0" | ||
|
||
project = var.project_id | ||
|
||
pubsub_topics = local.topics | ||
mode = "additive" | ||
|
||
bindings = { | ||
"roles/pubsub.publisher" = [ | ||
"serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "project_id" { | ||
description = "Bucket project id." | ||
type = string | ||
} | ||
|
||
variable "bucket_configs" { | ||
type = map(object({ | ||
bucket = string | ||
topic = string | ||
})) | ||
description = "Map of buckets to the notification configs they should use." | ||
default = {} | ||
} | ||
|
||
variable "event_types" { | ||
type = list(string) | ||
description = "Event types to configure notifications for. Default all." | ||
default = null | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -138,3 +138,9 @@ variable "lifecycle_rules" { | |||||
description = "List of lifecycle rules to configure. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#lifecycle_rule except condition.matches_storage_class should be a comma delimited string." | ||||||
default = [] | ||||||
} | ||||||
|
||||||
variable "pubsub_topics" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
type = map(string) | ||||||
description = "Map of bucket=>topic to configure pubsub notifications." | ||||||
default = {} | ||||||
} |
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.
nit: I think you meant to remove this?