Skip to content

withriley/storage-insights

TFSec Security Checks terraform-docs auto-release

Storage Insights Reporting Module

A pattern for creating your Google Cloud Storage Insights reports 🤖

This module will create a destination reporting bucket for any number of source storage buckets you pass to it. It will also create a storage insights report config for each source bucket you pass to it. IAM permissions will also be configured for the source and destination buckets.

Usage Instructions ✨

Call this module using the example (below) as a starting point. Pass any additional optional parameters you require.

Caveats ⚠️

All of the source storage buckets passed to this module MUST be in the same project. If you want to configure Storage Insights on buckets from different projects, you will need to call the module for each project. Typically this is not an issue as most organizations will use Google's landing zone which seperates TF code by project.

Example

module "storage_insights" {
  source         = "github.com/withriley/storage-insights"
  project        = "my-project"
  source_buckets = ["bucket1", "bucket2", "bucket3"]
  start_date = {
    day   = 20
    month = 10
    year  = 2023
  }
  end_date = {
    day   = 18
    month = 10
    year  = 2024
  }
}

Resources

Name Type
google_storage_bucket.report_bucket resource
google_storage_bucket_iam_member.admin resource
google_storage_bucket_iam_member.insights resource
google_storage_insights_report_config.config resource
random_id.suffix resource
google_project.project data source
google_storage_bucket.buckets data source

Modules

No modules.

Inputs

Name Description Type Default Required
csv_options The CSV options for the storage insights report.
object({
record_separator = string
delimiter = string
header_required = bool
})
{
"delimiter": ",",
"header_required": false,
"record_separator": "\n"
}
no
end_date The end date for the storage insights report.
object({
day = number
month = number
year = number
})
n/a yes
frequency Frequency for the storage insights report. string "WEEKLY" no
metadata_fields The metadata fields to include in the storage insights report. list(string)
[
"project",
"bucket",
"name",
"location",
"size",
"timeCreated",
"timeDeleted",
"updated",
"storageClass",
"etag",
"retentionExpirationTime",
"crc32c",
"md5Hash",
"generation",
"metageneration",
"contentType",
"contentEncoding",
"timeStorageClassUpdated"
]
no
prefix The prefix to add to the storage insights report config display name. string "Storage Insights Report" no
project The project to deploy the storage insights reports to. string n/a yes
source_buckets A list of the storage buckets you want to configure reports on. list(string) n/a yes
start_date The start date for the storage insights report.
object({
day = number
month = number
year = number
})
n/a yes

Outputs

No outputs.