Add ability to reuse existing projects in project factory (#3051)

This commit is contained in:
Luca Prete
2025-04-21 10:57:53 +02:00
committed by GitHub
parent 3985808ded
commit 89d1b5aa8b
10 changed files with 148 additions and 18 deletions

File diff suppressed because one or more lines are too long

View File

@@ -23,6 +23,7 @@ locals {
billing_account = var.billing_account
prefix = var.prefix
parent = var.parent_id
project_reuse = var.project_reuse
}
}
projects = local._projects_output
@@ -43,4 +44,5 @@ module "projects" {
iam_by_principals = each.value.iam_by_principals
iam_by_principals_additive = each.value.iam_by_principals_additive
org_policies = each.value.org_policies
project_reuse = each.value.project_reuse
}

View File

@@ -39,10 +39,18 @@ locals {
quotas = null
})
)
labels = {}
metric_scopes = []
parent = null
prefix = null
labels = {}
metric_scopes = []
parent = null
prefix = null
project_reuse = merge({
use_data_source = true
project_attributes = null
}, try(local._projects_config.data_defaults.project_reuse, {
use_data_source = true
project_attributes = null
})
)
service_encryption_key_ids = {}
services = []
shared_vpc_service_config = merge({
@@ -196,6 +204,17 @@ locals {
local.__projects_config.data_defaults.prefix
), null
)
project_reuse = ( # type: object({...})
try(v.project_reuse, null) != null
? merge(
{
use_data_source = true
project_attributes = null
},
v.project_reuse
)
: local.__projects_config.data_defaults.project_reuse
)
service_encryption_key_ids = coalesce( # type: map(list(string))
local.__projects_config.data_overrides.service_encryption_key_ids,
try(v.service_encryption_key_ids, null),

View File

@@ -35,6 +35,36 @@
"parent": {
"type": "string"
},
"project_reuse": {
"type": "object",
"additionalProperties": false,
"properties": {
"use_data_source": {
"type": "boolean"
},
"project_attributes": {
"type": "object",
"required": [
"name",
"number"
],
"properties": {
"name": {
"type": "string"
},
"number": {
"type": "number"
},
"services_enabled": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"billing_account": {
"type": "string"
},
@@ -1476,4 +1506,4 @@
}
}
}
}
}

View File

@@ -380,3 +380,23 @@ variable "prefix" {
description = "Prefix used for projects."
type = string
}
variable "project_reuse" {
description = "Reuse existing project if not null. If name and number are not passed in, a data source is used."
type = object({
use_data_source = optional(bool, true)
project_attributes = optional(object({
name = string
number = number
services_enabled = optional(list(string), [])
}))
})
default = null
validation {
condition = (
try(var.project_reuse.use_data_source, null) != false ||
try(var.project_reuse.project_attributes, null) != null
)
error_message = "Reuse datasource can be disabled only if project attributes are set."
}
}