-
Notifications
You must be signed in to change notification settings - Fork 0
Feat sink billing account #129
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
base: test-pr-sink
Are you sure you want to change the base?
Changes from 17 commits
6d26c13
690f6e7
57ec9f6
85d6844
bebcbb2
f4f2eb8
14a3a99
ee3554c
5530ed9
4775ef3
df8dc0c
47418a3
06ec1c1
5c34cd5
fa23017
46e44cb
648ed1a
f3c7fbc
db9f4e1
ea4e2c0
b6bf537
07df788
e759cf9
b41b322
459fc90
32fb194
8b17343
1fe50db
a8b11b8
bc5c46d
e1274a6
f57a47c
27807fd
be6b808
a950798
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -59,11 +59,13 @@ module "logging_logbucket" { | |||||
|
|
||||||
| | Name | Description | Type | Default | Required | | ||||||
| |------|-------------|------|---------|:--------:| | ||||||
| | billing\_account | Billing Account ID used in case sinks are under billing account level. Format 000000-000000-000000. | `string` | `null` | no | | ||||||
| | enable\_billing\_account\_sink | If true, a log router sink will be created for the billing account. The billing\_account variable cannot be null. | `bool` | `false` | no | | ||||||
| | logbucket\_options | Destination LogBucket options:<br>- name: The name of the log bucket to be created and used for log entries matching the filter.<br>- logging\_sink\_name: The name of the log sink to be created.<br>- logging\_sink\_filter: The filter to apply when exporting logs. Only log entries that match the filter are exported. Default is "" which exports all logs.<br>- location: The location of the log bucket. Default: global.<br>- enable\_analytics: Whether or not Log Analytics is enabled. A Log bucket with Log Analytics enabled can be queried in the Log Analytics page using SQL queries. Cannot be disabled once enabled.<br>- linked\_dataset\_id: The ID of the linked BigQuery dataset. A valid link dataset ID must only have alphanumeric characters and underscores within it and have up to 100 characters.<br>- linked\_dataset\_description: A use-friendly description of the linked BigQuery dataset. The maximum length of the description is 8000 characters.<br>- retention\_days: The number of days data should be retained for the log bucket. Default 30. | <pre>object({<br> name = optional(string, null)<br> logging_sink_name = optional(string, null)<br> logging_sink_filter = optional(string, "")<br> location = optional(string, "global")<br> enable_analytics = optional(bool, true)<br> linked_dataset_id = optional(string, null)<br> linked_dataset_description = optional(string, null)<br> retention_days = optional(number, 30)<br> })</pre> | `null` | no | | ||||||
| | logging\_destination\_project\_id | The ID of the project that will have the resources where the logs will be created. | `string` | n/a | yes | | ||||||
| | logging\_project\_key | (Optional) The key of logging destination project if it is inside resources map. It is mandatory when resource\_type = project and logging\_target\_type = logbucket. | `string` | `""` | no | | ||||||
| | pubsub\_options | Destination Pubsub options:<br>- topic\_name: The name of the pubsub topic to be created and used for log entries matching the filter.<br>- logging\_sink\_name: The name of the log sink to be created.<br>- logging\_sink\_filter: The filter to apply when exporting logs. Only log entries that match the filter are exported. Default is "" which exports all logs.<br>- create\_subscriber: Whether to create a subscription to the topic that was created and used for log entries matching the filter. If 'true', a pull subscription is created along with a service account that is granted roles/pubsub.subscriber and roles/pubsub.viewer to the topic. | <pre>object({<br> topic_name = optional(string, null)<br> logging_sink_name = optional(string, null)<br> logging_sink_filter = optional(string, "")<br> create_subscriber = optional(bool, true)<br> })</pre> | `null` | no | | ||||||
| | resource\_type | Resource type of the resource that will export logs to destination. Must be: project, organization, or folder. | `string` | n/a | yes | | ||||||
| | resource\_type | Resource type of the resource that will export logs to destination. Must be: project, organization or folder. | `string` | n/a | yes | | ||||||
|
||||||
| | resource\_type | Resource type of the resource that will export logs to destination. Must be: project, organization or folder. | `string` | n/a | yes | | |
| | resource\_type | Resource type of the resource that will export logs to destination. Must be: project, organization, or folder. | `string` | n/a | yes | |
serial comma is required as define in the style guide
https://developers.google.com/style/commas#serial-commas
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,20 @@ module "log_export" { | |
| include_children = local.include_children | ||
| } | ||
|
|
||
| module "log_export_billing" { | ||
| source = "terraform-google-modules/log-export/google" | ||
| version = "~> 7.4" | ||
|
|
||
| for_each = var.enable_billing_account_sink ? local.log_exports : {} | ||
|
|
||
| destination_uri = local.destination_uri_map[each.value.type] | ||
| filter = "" | ||
| log_sink_name = "${coalesce(each.value.options.logging_sink_name, local.logging_sink_name_map[each.value.type])}-billing-${random_string.suffix.result}" | ||
| parent_resource_id = var.billing_account | ||
| parent_resource_type = "billing_account" | ||
| unique_writer_identity = true | ||
| } | ||
|
|
||
| #-------------------------# | ||
| # Send logs to Log Bucket # | ||
| #-------------------------# | ||
|
|
@@ -124,6 +138,20 @@ resource "google_project_iam_member" "logbucket_sink_member" { | |
| member = module.log_export["${each.value}_lbk"].writer_identity | ||
| } | ||
|
|
||
| #------------------------------------------------------------------# | ||
| # Log Bucket Service account IAM membership for log_export_billing # | ||
| #------------------------------------------------------------------# | ||
| resource "google_project_iam_member" "logbucket_sink_member_billing" { | ||
| for_each = var.logbucket_options != null ? local.logbucket_sink_member : {} | ||
romanini-ciandt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| project = var.logging_destination_project_id | ||
| role = "roles/logging.bucketWriter" | ||
|
|
||
| # Set permission only on sinks for this destination using | ||
| # module.log_export_billing key "<resource>_<dest>" | ||
| member = module.log_export_billing["${each.value}_lbk"].writer_identity | ||
| } | ||
|
|
||
| #----------------------# | ||
| # Send logs to Storage # | ||
| #----------------------# | ||
|
|
@@ -158,6 +186,17 @@ resource "google_storage_bucket_iam_member" "storage_sink_member" { | |
| member = module.log_export["${each.value}_sto"].writer_identity | ||
| } | ||
|
|
||
| #---------------------------------------------------------------# | ||
| # Storage Service account IAM membership for log_export_billing # | ||
| #---------------------------------------------------------------# | ||
| resource "google_storage_bucket_iam_member" "storage_sink_member_billing" { | ||
| for_each = var.storage_options != null ? var.resources : {} | ||
|
|
||
| bucket = module.destination_storage[0].resource_name | ||
| role = "roles/storage.objectCreator" | ||
| member = module.log_export_billing["${each.value}_sto"].writer_identity | ||
| } | ||
|
|
||
|
|
||
| #----------------------# | ||
| # Send logs to Pub\Sub # | ||
|
|
@@ -185,3 +224,15 @@ resource "google_pubsub_topic_iam_member" "pubsub_sink_member" { | |
| role = "roles/pubsub.publisher" | ||
| member = module.log_export["${each.value}_pub"].writer_identity | ||
| } | ||
|
|
||
| #--------------------------------------------------------------# | ||
| # Pubsub Service account IAM membership for log_export_billing # | ||
| #--------------------------------------------------------------# | ||
| resource "google_pubsub_topic_iam_member" "pubsub_sink_member_billing" { | ||
| for_each = var.pubsub_options != null ? var.resources : {} | ||
|
|
||
| project = var.logging_destination_project_id | ||
| topic = module.destination_pubsub[0].resource_name | ||
| role = "roles/pubsub.publisher" | ||
| member = module.log_export_billing["${each.value}_pub"].writer_identity | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,15 +25,27 @@ variable "resources" { | |
| } | ||
|
|
||
| variable "resource_type" { | ||
| description = "Resource type of the resource that will export logs to destination. Must be: project, organization, or folder." | ||
| description = "Resource type of the resource that will export logs to destination. Must be: project, organization or folder." | ||
|
||
| type = string | ||
|
|
||
| validation { | ||
| condition = contains(["project", "folder", "organization"], var.resource_type) | ||
| error_message = "The resource_type value must be: project, organization, or folder." | ||
| error_message = "The resource_type value must be: project, organization or folder." | ||
|
||
| } | ||
| } | ||
|
|
||
| variable "billing_account" { | ||
| description = "Billing Account ID used in case sinks are under billing account level. Format 000000-000000-000000." | ||
| type = string | ||
| default = null | ||
| } | ||
|
|
||
| variable "enable_billing_account_sink" { | ||
romanini-ciandt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| description = "If true, a log router sink will be created for the billing account. The billing_account variable cannot be null." | ||
| type = bool | ||
| default = false | ||
| } | ||
|
|
||
| variable "logging_project_key" { | ||
| description = "(Optional) The key of logging destination project if it is inside resources map. It is mandatory when resource_type = project and logging_target_type = logbucket." | ||
| type = string | ||
|
|
@@ -123,3 +135,4 @@ EOT | |
| }) | ||
| default = null | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.