From 9540b8d1ae2cb6b479728ff9d4d7b36a3f3a89af Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Mon, 4 May 2026 15:20:57 +0200 Subject: [PATCH] Allow simple project exclusions in project factory module (#3929) * docs(cloud-function-v2): remove redundant vpc_connector block in examples * project factory exclusions for projects * fix example test --------- Co-authored-by: Luca Prete --- modules/project-factory/README.md | 17 +++++++++++++++-- modules/project-factory/projects.tf | 5 +++++ modules/project-factory/variables.tf | 5 ++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/project-factory/README.md b/modules/project-factory/README.md index 77528cfa1..6d89af6c7 100644 --- a/modules/project-factory/README.md +++ b/modules/project-factory/README.md @@ -469,6 +469,9 @@ module "project-factory" { budgets = { billing_account = var.billing_account_id } + exclusions = { + projects = ["staging/"] + } } notification_channels = { billing-default = { @@ -480,7 +483,7 @@ module "project-factory" { } } } -# tftest files=t0,0,1,2,2.1,2.2,2.3,3,4,5,6,7,8,9,10 inventory=example.yaml +# tftest files=t0,0,1,2,2.1,2.2,2.3,3,4,5,6,7,8,9,10,99 inventory=example.yaml ``` A project template for GKE projects: @@ -611,6 +614,16 @@ workload_identity_pools: # tftest-file id=5 path=data/folders/teams-iac-0.yaml schema=project.schema.json ``` +A project definition ignored via `factories_config.exclusions.projects`. + +```yaml +billing_account: 012345-67890A-BCDEF0 +services: + - container.googleapis.com + - storage.googleapis.com +# tftest-file id=99 path=data/projects/staging/unused-0.yaml schema=project.schema.json +``` + More traditional project definitions via the project factory data: ```yaml @@ -881,7 +894,7 @@ compute.disableSerialPortAccess: | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [factories_config](variables.tf#L170) | Path to folder with YAML resource description data files. | object({…}) | ✓ | | +| [factories_config](variables.tf#L170) | Path to folder with YAML resource description data files. Exclusions match the start of file paths, relative to their containing folder. | object({…}) | ✓ | | | [context](variables.tf#L17) | Context-specific interpolations. | object({…}) | | {} | | [data_defaults](variables.tf#L47) | Optional default values used when corresponding project or folder data from files are missing. | object({…}) | | {} | | [data_merges](variables.tf#L112) | Optional values that will be merged with corresponding data from files. Combines with `data_defaults`, file data, and `data_overrides`. | object({…}) | | {} | diff --git a/modules/project-factory/projects.tf b/modules/project-factory/projects.tf index 6b94138c7..0a7ebb85e 100644 --- a/modules/project-factory/projects.tf +++ b/modules/project-factory/projects.tf @@ -31,7 +31,12 @@ locals { try(local._templates_raw[v.project_template], {}), v ) + # apply exclusions + if alltrue([ + for x in var.factories_config.exclusions.projects : !startswith(k, x) + ]) } + # project data from projects folder _projects_raw = { for f in try(fileset(local.paths.projects, "**/*.yaml"), []) : trimsuffix(f, ".yaml") => yamldecode(file("${local.paths.projects}/${f}")) diff --git a/modules/project-factory/variables.tf b/modules/project-factory/variables.tf index 3b4c59fa6..2a15d8100 100644 --- a/modules/project-factory/variables.tf +++ b/modules/project-factory/variables.tf @@ -168,12 +168,15 @@ variable "data_overrides" { } variable "factories_config" { - description = "Path to folder with YAML resource description data files." + description = "Path to folder with YAML resource description data files. Exclusions match the start of file paths, relative to their containing folder." type = object({ basepath = string budgets = optional(object({ billing_account = optional(string) }), {}) + exclusions = optional(object({ + projects = optional(list(string), []) + }), {}) paths = optional(object({ budgets = optional(string, "budgets") folders = optional(string, "folders")