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 <preteluca@gmail.com>
This commit is contained in:
committed by
GitHub
parent
4cf46f2dd9
commit
9540b8d1ae
@@ -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. | <code>object({…})</code> | ✓ | |
|
||||
| [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. | <code>object({…})</code> | ✓ | |
|
||||
| [context](variables.tf#L17) | Context-specific interpolations. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [data_defaults](variables.tf#L47) | Optional default values used when corresponding project or folder data from files are missing. | <code>object({…})</code> | | <code>{}</code> |
|
||||
| [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`. | <code>object({…})</code> | | <code>{}</code> |
|
||||
|
||||
@@ -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}"))
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user