From ef5178c92901980294a90dbce384baa6b6479547 Mon Sep 17 00:00:00 2001 From: Ludovico Magnocavallo Date: Wed, 22 May 2024 09:56:34 +0200 Subject: [PATCH] add support for shared vpc host to project factory (#2300) --- modules/project-factory/README.md | 4 +++- modules/project-factory/factory-projects.tf | 8 ++++++++ modules/project-factory/main.tf | 1 + tests/modules/project_factory/examples/example.yaml | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/project-factory/README.md b/modules/project-factory/README.md index e9b26188a3..4bf6760f0a 100644 --- a/modules/project-factory/README.md +++ b/modules/project-factory/README.md @@ -205,7 +205,7 @@ module "project-factory" { projects_data_path = "data/projects" } } -# tftest modules=16 resources=55 files=prj-app-1,prj-app-2,prj-app-3,budget-test-100,h-0-0,h-1-0,h-0-1,h-1-1,h-1-1-p0 inventory=example.yaml +# tftest modules=16 resources=56 files=prj-app-1,prj-app-2,prj-app-3,budget-test-100,h-0-0,h-1-0,h-0-1,h-1-1,h-1-1-p0 inventory=example.yaml ``` A simple hierarchy of folders: @@ -326,6 +326,8 @@ iam: - rw "roles/viewer": - ro +shared_vpc_host_config: + enabled: true automation: project: bar-baz-iac-0 service_accounts: diff --git a/modules/project-factory/factory-projects.tf b/modules/project-factory/factory-projects.tf index f03aafaaca..3863e52ae7 100644 --- a/modules/project-factory/factory-projects.tf +++ b/modules/project-factory/factory-projects.tf @@ -87,6 +87,14 @@ locals { try(v.services, null), var.data_defaults.services ) + shared_vpc_host_config = ( + try(v.shared_vpc_host_config, null) != null + ? merge( + { service_projects = [] }, + v.shared_vpc_host_config + ) + : null + ) shared_vpc_service_config = ( try(v.shared_vpc_service_config, null) != null ? merge( diff --git a/modules/project-factory/main.tf b/modules/project-factory/main.tf index 1b42afcc54..d123aa548f 100644 --- a/modules/project-factory/main.tf +++ b/modules/project-factory/main.tf @@ -81,6 +81,7 @@ module "projects" { each.value.services, var.data_merges.services )) + shared_vpc_host_config = each.value.shared_vpc_host_config shared_vpc_service_config = each.value.shared_vpc_service_config tag_bindings = merge( each.value.tag_bindings, diff --git a/tests/modules/project_factory/examples/example.yaml b/tests/modules/project_factory/examples/example.yaml index 592f8e53cb..5ec4c7ee33 100644 --- a/tests/modules/project_factory/examples/example.yaml +++ b/tests/modules/project_factory/examples/example.yaml @@ -115,6 +115,7 @@ values: counts: google_billing_budget: 1 + google_compute_shared_vpc_host_project: 1 google_compute_shared_vpc_service_project: 1 google_compute_subnetwork_iam_member: 3 google_essential_contacts_contact: 4 @@ -132,4 +133,4 @@ counts: google_storage_bucket_iam_binding: 2 google_storage_project_service_account: 4 modules: 16 - resources: 55 + resources: 56