Add asset_feeds to resman modules (#3658)

* Add asset_feeds to resman modules

* Add examples and update readmes

* Extend pubsub_topic context to project and folder modules

* Use pubsub_topic context for pubsub_destination

* Update readmes and add project-factory asset_feed example

* Update context tests

* Update schemas
This commit is contained in:
Julio Castillo
2026-01-20 15:37:35 +01:00
committed by GitHub
parent 558e552b5e
commit d9e1b924a1
43 changed files with 1935 additions and 126 deletions

View File

@@ -17,6 +17,7 @@ This module allows the creation and management of folders, including support for
- [KMS Autokey](#kms-autokey)
- [Custom Security Health Analytics Modules](#custom-security-health-analytics-modules)
- [Custom Security Health Analytics Modules Factory](#custom-security-health-analytics-modules-factory)
- [Cloud Asset Inventory Feeds](#cloud-asset-inventory-feeds)
- [Tags](#tags)
- [Files](#files)
- [Variables](#variables)
@@ -568,6 +569,39 @@ cloudkmKeyRotationPeriod:
- "cloudkms.googleapis.com/CryptoKey"
```
## Cloud Asset Inventory Feeds
Cloud Asset Inventory feeds allow you to monitor asset changes in real-time by publishing notifications to a Pub/Sub topic. Feeds configured at the folder level will monitor all resources within the folder and its subfolders.
```hcl
module "pubsub" {
source = "./fabric/modules/pubsub"
project_id = var.project_id
name = "folder-asset-feed"
}
module "folder" {
source = "./fabric/modules/folder"
parent = var.folder_id
name = "Monitored Folder"
asset_feeds = {
compute-instances = {
billing_project = var.project_id
feed_output_config = {
pubsub_destination = {
topic = module.pubsub.id
}
}
content_type = "RESOURCE"
asset_types = [
"compute.googleapis.com/Instance"
]
}
}
}
# tftest modules=2 resources=3 inventory=feeds.yaml
```
## Tags
Refer to the [Creating and managing tags](https://cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing) documentation for details on usage.
@@ -604,6 +638,7 @@ module "folder" {
| name | description | resources |
|---|---|---|
| [assets.tf](./assets.tf) | None | <code>google_cloud_asset_folder_feed</code> |
| [iam.tf](./iam.tf) | IAM bindings. | <code>google_folder_iam_binding</code> · <code>google_folder_iam_member</code> |
| [logging.tf](./logging.tf) | Log sinks and supporting resources. | <code>google_bigquery_dataset_iam_member</code> · <code>google_folder_iam_audit_config</code> · <code>google_logging_folder_exclusion</code> · <code>google_logging_folder_settings</code> · <code>google_logging_folder_sink</code> · <code>google_project_iam_member</code> · <code>google_pubsub_topic_iam_member</code> · <code>google_storage_bucket_iam_member</code> |
| [main.tf](./main.tf) | Module-level locals and resources. | <code>google_assured_workloads_workload</code> · <code>google_compute_firewall_policy_association</code> · <code>google_essential_contacts_contact</code> · <code>google_folder</code> · <code>google_kms_autokey_config</code> |
@@ -624,31 +659,32 @@ module "folder" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [assured_workload_config](variables.tf#L17) | Create AssuredWorkloads folder instead of regular folder when value is provided. Incompatible with folder_create=false. | <code title="object&#40;&#123;&#10; compliance_regime &#61; string&#10; display_name &#61; string&#10; location &#61; string&#10; organization &#61; string&#10; enable_sovereign_controls &#61; optional&#40;bool&#41;&#10; labels &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; partner &#61; optional&#40;string&#41;&#10; partner_permissions &#61; optional&#40;object&#40;&#123;&#10; assured_workloads_monitoring &#61; optional&#40;bool&#41;&#10; data_logs_viewer &#61; optional&#40;bool&#41;&#10; service_access_approver &#61; optional&#40;bool&#41;&#10; &#125;&#41;&#41;&#10; violation_notifications_enabled &#61; optional&#40;bool&#41;&#10;&#10;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [autokey_config](variables.tf#L70) | Enable autokey support for this folder's children. Project accepts either project id or number. | <code title="object&#40;&#123;&#10; project &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [contacts](variables.tf#L79) | List of essential contacts for this resource. Must be in the form EMAIL -> [NOTIFICATION_TYPES]. Valid notification types are ALL, SUSPENSION, SECURITY, TECHNICAL, BILLING, LEGAL, PRODUCT_UPDATES. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [context](variables.tf#L98) | Context-specific interpolations. | <code title="object&#40;&#123;&#10; condition_vars &#61; optional&#40;map&#40;map&#40;string&#41;&#41;, &#123;&#125;&#41;&#10; custom_roles &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; email_addresses &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; folder_ids &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; iam_principals &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; project_ids &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; project_numbers &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; tag_values &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>&#123;&#125;</code> |
| [deletion_protection](variables.tf#L114) | Deletion protection setting for this folder. | <code>bool</code> | | <code>false</code> |
| [factories_config](variables.tf#L120) | Paths to data files and folders that enable factory functionality. | <code title="object&#40;&#123;&#10; org_policies &#61; optional&#40;string&#41;&#10; pam_entitlements &#61; optional&#40;string&#41;&#10; scc_sha_custom_modules &#61; optional&#40;string&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>&#123;&#125;</code> |
| [firewall_policy](variables.tf#L131) | Hierarchical firewall policy to associate to this folder. | <code title="object&#40;&#123;&#10; name &#61; string&#10; policy &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [folder_create](variables.tf#L140) | Create folder. When set to false, uses id to reference an existing folder. | <code>bool</code> | | <code>true</code> |
| [asset_feeds](variables.tf#L18) | Cloud Asset Inventory feeds. | <code title="map&#40;object&#40;&#123;&#10; billing_project &#61; string&#10; content_type &#61; optional&#40;string&#41;&#10; asset_types &#61; optional&#40;list&#40;string&#41;&#41;&#10; asset_names &#61; optional&#40;list&#40;string&#41;&#41;&#10; feed_output_config &#61; object&#40;&#123;&#10; pubsub_destination &#61; object&#40;&#123;&#10; topic &#61; string&#10; &#125;&#41;&#10; &#125;&#41;&#10; condition &#61; optional&#40;object&#40;&#123;&#10; expression &#61; string&#10; title &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string&#41;&#10; location &#61; optional&#40;string&#41;&#10; &#125;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [assured_workload_config](variables.tf#L51) | Create AssuredWorkloads folder instead of regular folder when value is provided. Incompatible with folder_create=false. | <code title="object&#40;&#123;&#10; compliance_regime &#61; string&#10; display_name &#61; string&#10; location &#61; string&#10; organization &#61; string&#10; enable_sovereign_controls &#61; optional&#40;bool&#41;&#10; labels &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; partner &#61; optional&#40;string&#41;&#10; partner_permissions &#61; optional&#40;object&#40;&#123;&#10; assured_workloads_monitoring &#61; optional&#40;bool&#41;&#10; data_logs_viewer &#61; optional&#40;bool&#41;&#10; service_access_approver &#61; optional&#40;bool&#41;&#10; &#125;&#41;&#41;&#10; violation_notifications_enabled &#61; optional&#40;bool&#41;&#10;&#10;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [autokey_config](variables.tf#L104) | Enable autokey support for this folder's children. Project accepts either project id or number. | <code title="object&#40;&#123;&#10; project &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [contacts](variables.tf#L113) | List of essential contacts for this resource. Must be in the form EMAIL -> [NOTIFICATION_TYPES]. Valid notification types are ALL, SUSPENSION, SECURITY, TECHNICAL, BILLING, LEGAL, PRODUCT_UPDATES. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [context](variables.tf#L132) | Context-specific interpolations. | <code title="object&#40;&#123;&#10; bigquery_datasets &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; condition_vars &#61; optional&#40;map&#40;map&#40;string&#41;&#41;, &#123;&#125;&#41;&#10; custom_roles &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; email_addresses &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; folder_ids &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; iam_principals &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; log_buckets &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; project_ids &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; project_numbers &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; pubsub_topics &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; storage_buckets &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; tag_values &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>&#123;&#125;</code> |
| [deletion_protection](variables.tf#L152) | Deletion protection setting for this folder. | <code>bool</code> | | <code>false</code> |
| [factories_config](variables.tf#L158) | Paths to data files and folders that enable factory functionality. | <code title="object&#40;&#123;&#10; org_policies &#61; optional&#40;string&#41;&#10; pam_entitlements &#61; optional&#40;string&#41;&#10; scc_sha_custom_modules &#61; optional&#40;string&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>&#123;&#125;</code> |
| [firewall_policy](variables.tf#L169) | Hierarchical firewall policy to associate to this folder. | <code title="object&#40;&#123;&#10; name &#61; string&#10; policy &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [folder_create](variables.tf#L178) | Create folder. When set to false, uses id to reference an existing folder. | <code>bool</code> | | <code>true</code> |
| [iam](variables-iam.tf#L17) | IAM bindings in {ROLE => [MEMBERS]} format. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [iam_bindings](variables-iam.tf#L24) | Authoritative IAM bindings in {KEY => {role = ROLE, members = [], condition = {}}}. Keys are arbitrary. | <code title="map&#40;object&#40;&#123;&#10; members &#61; list&#40;string&#41;&#10; role &#61; string&#10; condition &#61; optional&#40;object&#40;&#123;&#10; expression &#61; string&#10; title &#61; string&#10; description &#61; optional&#40;string&#41;&#10; &#125;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [iam_bindings_additive](variables-iam.tf#L39) | Individual additive IAM bindings. Keys are arbitrary. | <code title="map&#40;object&#40;&#123;&#10; member &#61; string&#10; role &#61; string&#10; condition &#61; optional&#40;object&#40;&#123;&#10; expression &#61; string&#10; title &#61; string&#10; description &#61; optional&#40;string&#41;&#10; &#125;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [iam_by_principals](variables-iam.tf#L61) | Authoritative IAM binding in {PRINCIPAL => [ROLES]} format. Principals need to be statically defined to avoid errors. Merged internally with the `iam` variable. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [iam_by_principals_additive](variables-iam.tf#L54) | Additive IAM binding in {PRINCIPAL => [ROLES]} format. Principals need to be statically defined to avoid errors. Merged internally with the `iam_bindings_additive` variable. | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [iam_by_principals_conditional](variables-iam.tf#L68) | Authoritative IAM binding in {PRINCIPAL => {roles = [roles], condition = {cond}}} format. Principals need to be statically defined to avoid errors. Condition is required. | <code title="map&#40;object&#40;&#123;&#10; roles &#61; list&#40;string&#41;&#10; condition &#61; object&#40;&#123;&#10; expression &#61; string&#10; title &#61; string&#10; description &#61; optional&#40;string&#41;&#10; &#125;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [id](variables.tf#L150) | Folder ID in case you use folder_create=false. | <code>string</code> | | <code>null</code> |
| [id](variables.tf#L188) | Folder ID in case you use folder_create=false. | <code>string</code> | | <code>null</code> |
| [logging_data_access](variables-logging.tf#L17) | Control activation of data access logs. The special 'allServices' key denotes configuration for all services. | <code title="map&#40;object&#40;&#123;&#10; ADMIN_READ &#61; optional&#40;object&#40;&#123; exempted_members &#61; optional&#40;list&#40;string&#41;, &#91;&#93;&#41; &#125;&#41;&#41;,&#10; DATA_READ &#61; optional&#40;object&#40;&#123; exempted_members &#61; optional&#40;list&#40;string&#41;, &#91;&#93;&#41; &#125;&#41;&#41;,&#10; DATA_WRITE &#61; optional&#40;object&#40;&#123; exempted_members &#61; optional&#40;list&#40;string&#41;, &#91;&#93;&#41; &#125;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [logging_exclusions](variables-logging.tf#L28) | Logging exclusions for this folder in the form {NAME -> FILTER}. | <code>map&#40;string&#41;</code> | | <code>&#123;&#125;</code> |
| [logging_settings](variables-logging.tf#L35) | Default settings for logging resources. | <code title="object&#40;&#123;&#10; disable_default_sink &#61; optional&#40;bool&#41;&#10; storage_location &#61; optional&#40;string&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [logging_sinks](variables-logging.tf#L45) | Logging sinks to create for the folder. | <code title="map&#40;object&#40;&#123;&#10; bq_partitioned_table &#61; optional&#40;bool, false&#41;&#10; description &#61; optional&#40;string&#41;&#10; destination &#61; string&#10; disabled &#61; optional&#40;bool, false&#41;&#10; exclusions &#61; optional&#40;map&#40;string&#41;, &#123;&#125;&#41;&#10; filter &#61; optional&#40;string&#41;&#10; iam &#61; optional&#40;bool, true&#41;&#10; include_children &#61; optional&#40;bool, true&#41;&#10; intercept_children &#61; optional&#40;bool, false&#41;&#10; type &#61; string&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [name](variables.tf#L156) | Folder name. | <code>string</code> | | <code>null</code> |
| [org_policies](variables.tf#L162) | Organization policies applied to this folder keyed by policy name. | <code title="map&#40;object&#40;&#123;&#10; inherit_from_parent &#61; optional&#40;bool&#41; &#35; for list policies only.&#10; reset &#61; optional&#40;bool&#41;&#10; rules &#61; optional&#40;list&#40;object&#40;&#123;&#10; allow &#61; optional&#40;object&#40;&#123;&#10; all &#61; optional&#40;bool&#41;&#10; values &#61; optional&#40;list&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#10; deny &#61; optional&#40;object&#40;&#123;&#10; all &#61; optional&#40;bool&#41;&#10; values &#61; optional&#40;list&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#10; enforce &#61; optional&#40;bool&#41; &#35; for boolean policies only.&#10; condition &#61; optional&#40;object&#40;&#123;&#10; description &#61; optional&#40;string&#41;&#10; expression &#61; optional&#40;string&#41;&#10; location &#61; optional&#40;string&#41;&#10; title &#61; optional&#40;string&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10; parameters &#61; optional&#40;string&#41;&#10; &#125;&#41;&#41;, &#91;&#93;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [name](variables.tf#L194) | Folder name. | <code>string</code> | | <code>null</code> |
| [org_policies](variables.tf#L200) | Organization policies applied to this folder keyed by policy name. | <code title="map&#40;object&#40;&#123;&#10; inherit_from_parent &#61; optional&#40;bool&#41; &#35; for list policies only.&#10; reset &#61; optional&#40;bool&#41;&#10; rules &#61; optional&#40;list&#40;object&#40;&#123;&#10; allow &#61; optional&#40;object&#40;&#123;&#10; all &#61; optional&#40;bool&#41;&#10; values &#61; optional&#40;list&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#10; deny &#61; optional&#40;object&#40;&#123;&#10; all &#61; optional&#40;bool&#41;&#10; values &#61; optional&#40;list&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#10; enforce &#61; optional&#40;bool&#41; &#35; for boolean policies only.&#10; condition &#61; optional&#40;object&#40;&#123;&#10; description &#61; optional&#40;string&#41;&#10; expression &#61; optional&#40;string&#41;&#10; location &#61; optional&#40;string&#41;&#10; title &#61; optional&#40;string&#41;&#10; &#125;&#41;, &#123;&#125;&#41;&#10; parameters &#61; optional&#40;string&#41;&#10; &#125;&#41;&#41;, &#91;&#93;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [pam_entitlements](variables-pam.tf#L17) | Privileged Access Manager entitlements for this resource, keyed by entitlement ID. | <code title="map&#40;object&#40;&#123;&#10; max_request_duration &#61; string&#10; eligible_users &#61; list&#40;string&#41;&#10; privileged_access &#61; list&#40;object&#40;&#123;&#10; role &#61; string&#10; condition &#61; optional&#40;string&#41;&#10; &#125;&#41;&#41;&#10; requester_justification_config &#61; optional&#40;object&#40;&#123;&#10; not_mandatory &#61; optional&#40;bool, true&#41;&#10; unstructured &#61; optional&#40;bool, false&#41;&#10; &#125;&#41;, &#123; not_mandatory &#61; false, unstructured &#61; true &#125;&#41;&#10; manual_approvals &#61; optional&#40;object&#40;&#123;&#10; require_approver_justification &#61; bool&#10; steps &#61; list&#40;object&#40;&#123;&#10; approvers &#61; list&#40;string&#41;&#10; approvals_needed &#61; optional&#40;number, 1&#41;&#10; approver_email_recipients &#61; optional&#40;list&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#10; &#125;&#41;&#41;&#10; additional_notification_targets &#61; optional&#40;object&#40;&#123;&#10; admin_email_recipients &#61; optional&#40;list&#40;string&#41;&#41;&#10; requester_email_recipients &#61; optional&#40;list&#40;string&#41;&#41;&#10; &#125;&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [parent](variables.tf#L190) | Parent in folders/folder_id or organizations/org_id format. | <code>string</code> | | <code>null</code> |
| [parent](variables.tf#L228) | Parent in folders/folder_id or organizations/org_id format. | <code>string</code> | | <code>null</code> |
| [scc_sha_custom_modules](variables-scc.tf#L17) | SCC custom modules keyed by module name. | <code title="map&#40;object&#40;&#123;&#10; description &#61; optional&#40;string&#41;&#10; severity &#61; string&#10; recommendation &#61; string&#10; predicate &#61; object&#40;&#123;&#10; expression &#61; string&#10; &#125;&#41;&#10; resource_selector &#61; object&#40;&#123;&#10; resource_types &#61; list&#40;string&#41;&#10; &#125;&#41;&#10; enablement_state &#61; optional&#40;string, &#34;ENABLED&#34;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [tag_bindings](variables.tf#L204) | Tag bindings for this folder, in key => tag value id format. | <code>map&#40;string&#41;</code> | | <code>null</code> |
| [tag_bindings](variables.tf#L242) | Tag bindings for this folder, in key => tag value id format. | <code>map&#40;string&#41;</code> | | <code>null</code> |
## Outputs

46
modules/folder/assets.tf Normal file
View File

@@ -0,0 +1,46 @@
/**
* Copyright 2026 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.
*/
resource "google_cloud_asset_folder_feed" "default" {
for_each = var.asset_feeds
billing_project = each.value.billing_project
folder = local.folder_id
feed_id = each.key
content_type = each.value.content_type
asset_types = each.value.asset_types
asset_names = each.value.asset_names
feed_output_config {
pubsub_destination {
topic = lookup(
local.ctx.pubsub_topics,
each.value.feed_output_config.pubsub_destination.topic,
each.value.feed_output_config.pubsub_destination.topic
)
}
}
dynamic "condition" {
for_each = each.value.condition == null ? [] : [each.value.condition]
content {
expression = condition.value.expression
title = condition.value.title
description = condition.value.description
location = condition.value.location
}
}
}

View File

@@ -19,18 +19,39 @@
locals {
logging_sinks = {
for k, v in var.logging_sinks :
# rewrite destination and type when type="project"
k => merge(v, v.type != "project" ? {} : {
destination = "projects/${v.destination}"
type = "logging"
})
# expand destination contexts
k => merge(v,
v.type != "bigquery" ? {} : {
destination = lookup(
local.ctx.bigquery_datasets, v.destination, v.destination
)
},
v.type != "logging" ? {} : {
destination = lookup(
local.ctx.log_buckets, v.destination, v.destination
)
},
v.type != "project" ? {} : {
api = "logging"
destination = "projects/${lookup(local.ctx.project_ids, v.destination, v.destination)}"
},
v.type != "pubsub" ? {} : {
destination = lookup(
local.ctx.pubsub_topics, v.destination, v.destination
)
},
v.type != "storage" ? {} : {
destination = lookup(
local.ctx.storage_buckets, v.destination, v.destination
)
}
)
}
sink_bindings = {
for type in ["bigquery", "logging", "project", "pubsub", "storage"] :
type => {
for name, sink in var.logging_sinks :
name => sink
if sink.iam == true && sink.type == type
for name, sink in local.logging_sinks :
name => sink if sink.iam && sink.type == type
}
}
}
@@ -63,7 +84,7 @@ resource "google_logging_folder_sink" "sink" {
name = each.key
description = coalesce(each.value.description, "${each.key} (Terraform-managed).")
folder = local.folder_id
destination = "${each.value.type}.googleapis.com/${each.value.destination}"
destination = "${lookup(each.value, "api", each.value.type)}.googleapis.com/${each.value.destination}"
filter = each.value.filter
include_children = each.value.include_children
intercept_children = each.value.intercept_children

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,6 +14,40 @@
* limitations under the License.
*/
variable "asset_feeds" {
description = "Cloud Asset Inventory feeds."
type = map(object({
billing_project = string
content_type = optional(string)
asset_types = optional(list(string))
asset_names = optional(list(string))
feed_output_config = object({
pubsub_destination = object({
topic = string
})
})
condition = optional(object({
expression = string
title = optional(string)
description = optional(string)
location = optional(string)
}))
}))
default = {}
nullable = false
validation {
condition = alltrue([
for k, v in var.asset_feeds :
v.content_type == null || contains(
["RESOURCE", "IAM_POLICY", "ORG_POLICY", "ACCESS_POLICY", "OS_INVENTORY", "RELATIONSHIP"],
v.content_type
)
])
error_message = "Content type must be one of RESOURCE, IAM_POLICY, ORG_POLICY, ACCESS_POLICY, OS_INVENTORY, RELATIONSHIP."
}
}
variable "assured_workload_config" {
description = "Create AssuredWorkloads folder instead of regular folder when value is provided. Incompatible with folder_create=false."
type = object({
@@ -98,14 +132,18 @@ variable "contacts" {
variable "context" {
description = "Context-specific interpolations."
type = object({
condition_vars = optional(map(map(string)), {})
custom_roles = optional(map(string), {})
email_addresses = optional(map(string), {})
folder_ids = optional(map(string), {})
iam_principals = optional(map(string), {})
project_ids = optional(map(string), {})
project_numbers = optional(map(string), {})
tag_values = optional(map(string), {})
bigquery_datasets = optional(map(string), {})
condition_vars = optional(map(map(string)), {})
custom_roles = optional(map(string), {})
email_addresses = optional(map(string), {})
folder_ids = optional(map(string), {})
iam_principals = optional(map(string), {})
log_buckets = optional(map(string), {})
project_ids = optional(map(string), {})
project_numbers = optional(map(string), {})
pubsub_topics = optional(map(string), {})
storage_buckets = optional(map(string), {})
tag_values = optional(map(string), {})
})
default = {}
nullable = false