* Allow creation of dynamic tags * Extend project factory and related modules to support dynamic values * Extend folder and organization modules * project and organization readme * Simplify dynamic tag support and remove unnecessary restrictions • Schemas & Validations: Removed the restriction that forbade combining IAM fields with allowed_values_regex on tags. Updated validations in project and organization modules, and simplified all relevant JSON schemas. • Module Tag Bindings: Simplified the tag_value assignment in folder , project , gcs , bigquery-dataset , and kms modules by removing the defensive can(regex(...)) check and calling templatestring directly. • Outputs: Removed the tags_dynamic output from project and organization modules, as the same information is now available in tag_keys . • Project Factory: Updated tag_vars_projects in projects.tf to use the native namespaced_name attribute and filtered manually for dynamic tags. * fix(organization, project): fix linting and tests for dynamic tag support - Align allowed_values_regex and description extraction in _tags_merged locals to use lookup() for consistency with other fields. - Fix spacing in project context variable (alphabetical ordering). - Update organization tags test to include the new cost_center tag key with allowed_values_regex. - Update project tags test to include the new cost_center tag key and reflect the resolved allowed_values_regex on environment. * refactor(gcs): refine tag bindings and fix context test - Add _tag_bindings local to pre-resolve context references, enabling templatestring to receive a direct map reference (required by Terraform). - Use var.context.tag_vars instead of the non-existent local.ctx.tag_vars. - Fix HCL syntax in context.tfvars (escaped inner quotes). - Update context test inventory to reflect 3 tag bindings including a dynamic value resolved via templatestring. * refactor: align modules with tag binding context pattern - Add _tag_bindings local + templatestring dance to cloud-run-v2, compute-vm, folder, kms modules (bigquery-dataset already had it) - Exclude tag_vars from local.ctx in cloud-run-v2, compute-vm, folder, kms, project modules (bigquery-dataset already had it) - Add tag_vars to context variable in cloud-run-v2, compute-vm modules (others already had it) - Update all context tests with dynamic tag binding values using var.context.tag_vars * docs: add module-level tftest.yaml test instructions to GEMINI.md * docs: regenerate READMEs after tag-regex alignment - Regenerate variable tables in 7 module READMEs to reflect line number shifts from prior tag-regex changes - Add tag_vars exclusion to gcs ctx local - Fix whitespace alignment in iam-service-account and project-factory tag_vars blocks - Update tftest resource counts for organization and project - Remove tags_dynamic from organization/project output tables * fix(project-factory): update test inventory for tag_bindings module split - Move tag binding address from folder-2 to folder-2-iam in test inventory (tag_bindings moved from creation to IAM modules) - Update module instance count from 34 to 35 - Regenerate README tables after terraform fmt line shifts - Apply terraform fmt to variables.tf * refactor(project-factory): remove unnecessary depends_on from folder-iam modules Folder IAM modules depend on their own folder creation modules, not on module.projects. The explicit depends_on was leftover from an earlier design. * FAST stages * Address review comments. - FAST Stages: - Added tag_keys to output-files.tf in 0-org-setup to pass org tags via tfvars. - Sorted tag_keys and tag_values in output-files.tf. - Updated project-factory, networking, and security stages to use tag_keys. - Filtered tag_keys for dynamic tags only. - Modules: - Excluded tag_vars from local.ctx in iam-service-account and organization. - Simplified tag_value in iam-service-account. - Tests: - Updated test inventories for 0-org-setup and project-factory. * Fix tf format * Fix tfdoc * docs: add ADR for templatestring vars convention and update status of base path ADR * More tfdoc * Update schemas * Use endswith in context loop * Address review * Update FAST readmes * Update last modules * Terraform fmt * Revert alloydb * Fix whitespace --------- Co-authored-by: Ludovico Magnocavallo <ludo@qix.it>
Google Cloud Logging Buckets Module
This module manages logging buckets for a project, folder, organization or billing account.
Note that some logging buckets are automatically created for a given folder, project, organization, and billing account cannot be deleted. Creating a resource of this type will acquire and update the resource that already exists at the desired location. These buckets cannot be removed so deleting this resource will remove the bucket config from your terraform state but will leave the logging bucket unchanged. The buckets that are currently automatically created are "_Default" and "_Required".
See also the logging_sinks argument within the project, folder and organization modules.
- Custom logging bucket in a project
- Custom logging bucket in a project with Log Analytics
- Change retention period of a folder _Default bucket
- Organization and billing account buckets
- Custom bucket with views
- Variables
- Outputs
Custom logging bucket in a project
module "bucket" {
source = "./fabric/modules/logging-bucket"
parent = var.project_id
name = "mybucket"
}
# tftest modules=1 resources=1 inventory=project.yaml
Custom logging bucket in a project with Log Analytics
module "bucket" {
source = "./fabric/modules/logging-bucket"
parent = var.project_id
name = "mybucket"
log_analytics = {
enable = true
dataset_link_id = "log"
}
}
# tftest modules=1 resources=2 inventory=log_analytics.yaml
Change retention period of a folder _Default bucket
module "folder" {
source = "./fabric/modules/folder"
parent = "folders/657104291943"
name = "my folder"
}
module "bucket-default" {
source = "./fabric/modules/logging-bucket"
parent_type = "folder"
parent = module.folder.id
name = "_Default"
retention = 10
}
# tftest modules=2 resources=2 inventory=retention.yaml
Organization and billing account buckets
module "bucket-organization" {
source = "./fabric/modules/logging-bucket"
parent_type = "organization"
parent = "organizations/012345"
name = "mybucket"
}
module "bucket-billing-account" {
source = "./fabric/modules/logging-bucket"
parent_type = "billing_account"
parent = "012345"
name = "mybucket"
}
# tftest modules=2 resources=2 inventory=org-ba.yaml
Custom bucket with views
Views support our standard IAM interface via the following variables:
iamandiam_by_principalsconfigure authoritative bindings that manage individual roles exclusively, and are internally mergediam_bindingsconfigure authoritative bindings with optional support for conditions, and are not internally merged with the previous two variablesiam_bindings_additiveconfigure additive bindings via individual role/member pairs with optional support conditions
The authoritative and additive approaches can be used together, provided different roles are managed by each. Some care must also be taken with the iam_by_principals variable to ensure that variable keys are static values, so that Terraform is able to compute the dependency graph.
Refer to the project module for examples of the IAM interface. IAM also supports variable interpolation for both roles and principals and for the foreign resources where the service account is the principal, via the respective attributes in the var.context variable. Basic usage is shown in the example below.
module "bucket" {
source = "./fabric/modules/logging-bucket"
parent = var.project_id
name = "mybucket"
context = {
iam_principals = {
myuser = "user:user@example.com"
}
}
views = {
myview = {
filter = "LOG_ID(\"stdout\")"
iam = {
"roles/logging.viewAccessor" = ["$iam_principals:myuser"]
}
}
}
}
# tftest modules=1 resources=3 inventory=views.yaml
Variables
| name | description | type | required | default |
|---|---|---|---|---|
| name | Name of the logging bucket. | string |
✓ | |
| parent | ID of the parent resource containing the bucket in the format 'project_id' 'folders/folder_id', 'organizations/organization_id' or 'billing_account_id'. | string |
✓ | |
| context | Context-specific interpolations. | object({…}) |
{} |
|
| description | Human-readable description for the logging bucket. | string |
null |
|
| kms_key_name | To enable CMEK for a project logging bucket, set this field to a valid name. The associated service account requires cloudkms.cryptoKeyEncrypterDecrypter roles assigned for the key. | string |
null |
|
| location | Location of the bucket. | string |
"global" |
|
| locked | Whether the bucket is locked. Locked buckets may only be deleted if they are empty. This can only be set for project-level buckets. | bool |
null |
|
| log_analytics | Enable and configure Analytics Log. | object({…}) |
{} |
|
| parent_type | Parent object type for the bucket (project, folder, organization, billing_account). | string |
"project" |
|
| retention | Retention time in days for the logging bucket. | number |
30 |
|
| tag_bindings | Tag bindings for this bucket, in key => tag value id format. | map(string) |
{} |
|
| views | Log views for this bucket. | map(object({…})) |
{} |
Outputs
| name | description | sensitive |
|---|---|---|
| id | Fully qualified logging bucket id. | |
| view_ids | The automatic and user-created views in this bucket. |