-
Notifications
You must be signed in to change notification settings - Fork 0
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 sink billing account #129
base: test-pr-sink
Are you sure you want to change the base?
Changes from 19 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 |
---|---|---|
|
@@ -62,6 +62,12 @@ locals { | |
lbk = try(module.destination_logbucket[0].destination_uri, "") | ||
} | ||
|
||
destination_resource_uri = { | ||
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. I can be wrong, but I believe that A possible approach to avoid that could be something like that: filtered_destination_resource_uri = {
for key, value in destination_resource_uri :
key => value
if value != ""
} 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. yes, the values need to be filtered before usage 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. It should be called |
||
pub = try(module.destination_pubsub[0].destination_name, "") | ||
sto = try(module.destination_storage[0].destination_name, "") | ||
lbk = try(module.destination_logbucket[0].destination_name, "") | ||
} | ||
|
||
logging_tgt_prefix = { | ||
pub = "tp-logs-" | ||
sto = try("bkt-logs-${var.logging_destination_project_id}-", "bkt-logs-") | ||
|
@@ -90,6 +96,27 @@ 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.destination_resource_uri : {} | ||
|
||
destination_uri = local.destination_resource_uri[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 | ||
} | ||
|
||
resource "time_sleep" "wait_sa_iam_membership" { | ||
create_duration = "30s" | ||
depends_on = [ | ||
module.log_export_billing | ||
] | ||
} | ||
|
||
#-------------------------# | ||
# Send logs to Log Bucket # | ||
#-------------------------# | ||
|
@@ -124,6 +151,24 @@ 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" { | ||
count = var.enable_billing_account_sink == true && var.logbucket_options != null ? 1 : 0 | ||
|
||
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["_lbk"].writer_identity | ||
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. is the value the local var keys do not have
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. |
||
|
||
depends_on = [ | ||
time_sleep.wait_sa_iam_membership | ||
] | ||
} | ||
|
||
#----------------------# | ||
# Send logs to Storage # | ||
#----------------------# | ||
|
@@ -158,6 +203,21 @@ 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" { | ||
count = var.enable_billing_account_sink == true && var.storage_options != null ? 1 : 0 | ||
|
||
bucket = module.destination_storage[0].resource_name | ||
role = "roles/storage.objectCreator" | ||
member = module.log_export_billing["_sto"].writer_identity | ||
|
||
depends_on = [ | ||
google_project_iam_member.logbucket_sink_member_billing | ||
] | ||
} | ||
|
||
|
||
#----------------------# | ||
# Send logs to Pub\Sub # | ||
|
@@ -185,3 +245,19 @@ 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" { | ||
count = var.enable_billing_account_sink == true && var.pubsub_options != null ? 1 : 0 | ||
|
||
project = var.logging_destination_project_id | ||
topic = module.destination_pubsub[0].resource_name | ||
role = "roles/pubsub.publisher" | ||
member = module.log_export_billing["_pub"].writer_identity | ||
|
||
depends_on = [ | ||
google_storage_bucket_iam_member.storage_sink_member_billing | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,11 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
output "enable_billing_account_sink" { | ||
description = "If true, a log router sink will be created for the billing account. The billing_account variable cannot be null." | ||
value = var.enable_billing_account_sink | ||
} | ||
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. this output should be removed since it is an input for the module |
||
|
||
output "storage_destination_name" { | ||
description = "The resource name for the destination Storage." | ||
value = try(module.destination_storage[0].resource_name, "") | ||
|
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'm not sure if we want to do that, but a possibility would be to add this variable into the .tfvars example file too.
That way it would be more clear for the user about how to enable the billing account sink.
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 variable should not exist at the env/shared level, only in the module, and the foundation should always set it to true when calling the module