Allow configuring project key format in project factory (#3154)

* Configurable project key in project-factory module

* Configurable project key in project-factory module

* add tests
This commit is contained in:
Ludovico Magnocavallo
2025-06-11 13:18:03 +02:00
committed by GitHub
parent 468c0ab49a
commit 7d008be2cb
18 changed files with 518 additions and 14 deletions

View File

@@ -0,0 +1,21 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../schemas/folder.schema.json
name: Team A
parent: teams
# iam_by_principals:
# "group:team-a-admins@example.com":
# - roles/viewer

View File

@@ -0,0 +1,22 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../schemas/folder.schema.json
name: Development
tag_bindings:
environment: environment/development
# iam_by_principals:
# "group:team-a-admins@example.com":
# - roles/editor

View File

@@ -0,0 +1,19 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../schemas/folder.schema.json
name: Production
tag_bindings:
environment: environment/production

View File

@@ -0,0 +1,21 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../schemas/folder.schema.json
name: Team B
parent: teams
# iam_by_principals:
# "group:team-b-admins@example.com":
# - roles/viewer

View File

@@ -0,0 +1,22 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../schemas/folder.schema.json
name: Development
tag_bindings:
environment: environment/development
# iam_by_principals:
# "group:team-b-admins@example.com":
# - roles/editor

View File

@@ -0,0 +1,19 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../schemas/folder.schema.json
name: Production
tag_bindings:
environment: environment/production

View File

@@ -0,0 +1,21 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../../../modules/project-factory/schemas/project.schema.json
parent: team-b/dev
shared_vpc_service_config:
host_project: dev-spoke-0
network_users:
- gcp-devops

View File

@@ -0,0 +1,21 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../../../modules/project-factory/schemas/project.schema.json
parent: team-b/prod
shared_vpc_service_config:
host_project: prod-spoke-0
network_users:
- gcp-devops

View File

@@ -0,0 +1,21 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../../../../modules/project-factory/schemas/project.schema.json
parent: team-a/dev
shared_vpc_service_config:
host_project: dev-spoke-0
network_users:
- gcp-devops

View File

@@ -0,0 +1,21 @@
# Copyright 2024 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.
# yaml-language-server: $schema=../../../../../../../modules/project-factory/schemas/project.schema.json
parent: team-a/prod
shared_vpc_service_config:
host_project: prod-spoke-0
network_users:
- gcp-devops

View File

@@ -0,0 +1,40 @@
data_defaults = {
billing_account = "1245-5678-9012"
parent = "folders/1234"
storage_location = "EU"
contacts = {
"admin-default@example.org" = ["ALL"]
}
tag_bindings = {
name1 = "default-id1"
name2 = "default-id2"
}
services = [
"default-service.googleapis.com"
]
}
data_overrides = {
prefix = "test-pf"
}
factories_config = {
folders_data_path = "key_ignores_path/hierarchy"
projects_data_path = "key_ignores_path/projects"
projects_config = {
key_ignores_path = true
}
context = {
folder_ids = {
default = "folders/5678901234"
teams = "folders/5678901234"
}
iam_principals = {
gcp-devops = "group:gcp-devops@example.org"
}
tag_values = {
"org-policies/drs-allow-all" = "tagValues/123456"
}
vpc_host_projects = {
dev-spoke-0 = "test-pf-dev-net-spoke-0"
}
}
}

View File

@@ -0,0 +1,238 @@
# Copyright 2025 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.
values:
module.hierarchy-folder-lvl-1["team-a"].google_folder.folder[0]:
deletion_protection: false
display_name: Team A
parent: folders/5678901234
tags: null
timeouts: null
module.hierarchy-folder-lvl-1["team-b"].google_folder.folder[0]:
deletion_protection: false
display_name: Team B
parent: folders/5678901234
tags: null
timeouts: null
module.hierarchy-folder-lvl-2["team-a/dev"].google_folder.folder[0]:
deletion_protection: false
display_name: Development
tags: null
timeouts: null
module.hierarchy-folder-lvl-2["team-a/dev"].google_tags_tag_binding.binding["environment"]:
tag_value: environment/development
timeouts: null
module.hierarchy-folder-lvl-2["team-a/prod"].google_folder.folder[0]:
deletion_protection: false
display_name: Production
tags: null
timeouts: null
module.hierarchy-folder-lvl-2["team-a/prod"].google_tags_tag_binding.binding["environment"]:
tag_value: environment/production
timeouts: null
module.hierarchy-folder-lvl-2["team-b/dev"].google_folder.folder[0]:
deletion_protection: false
display_name: Development
tags: null
timeouts: null
module.hierarchy-folder-lvl-2["team-b/dev"].google_tags_tag_binding.binding["environment"]:
tag_value: environment/development
timeouts: null
module.hierarchy-folder-lvl-2["team-b/prod"].google_folder.folder[0]:
deletion_protection: false
display_name: Production
tags: null
timeouts: null
module.hierarchy-folder-lvl-2["team-b/prod"].google_tags_tag_binding.binding["environment"]:
tag_value: environment/production
timeouts: null
module.projects-iam["dev-ta-0"].google_compute_shared_vpc_service_project.shared_vpc_service[0]:
deletion_policy: null
host_project: test-pf-dev-net-spoke-0
service_project: test-pf-dev-ta-0
timeouts: null
module.projects-iam["dev-ta-0"].google_project_iam_member.shared_vpc_host_iam["group:gcp-devops@example.org"]:
condition: []
member: group:gcp-devops@example.org
project: test-pf-dev-net-spoke-0
role: roles/compute.networkUser
module.projects-iam["dev-tb-0"].google_compute_shared_vpc_service_project.shared_vpc_service[0]:
deletion_policy: null
host_project: test-pf-dev-net-spoke-0
service_project: test-pf-dev-tb-0
timeouts: null
module.projects-iam["dev-tb-0"].google_project_iam_member.shared_vpc_host_iam["group:gcp-devops@example.org"]:
condition: []
member: group:gcp-devops@example.org
project: test-pf-dev-net-spoke-0
role: roles/compute.networkUser
module.projects-iam["prod-ta-0"].google_compute_shared_vpc_service_project.shared_vpc_service[0]:
deletion_policy: null
host_project: prod-spoke-0
service_project: test-pf-prod-ta-0
timeouts: null
module.projects-iam["prod-ta-0"].google_project_iam_member.shared_vpc_host_iam["group:gcp-devops@example.org"]:
condition: []
member: group:gcp-devops@example.org
project: prod-spoke-0
role: roles/compute.networkUser
module.projects-iam["prod-tb-0"].google_compute_shared_vpc_service_project.shared_vpc_service[0]:
deletion_policy: null
host_project: prod-spoke-0
service_project: test-pf-prod-tb-0
timeouts: null
module.projects-iam["prod-tb-0"].google_project_iam_member.shared_vpc_host_iam["group:gcp-devops@example.org"]:
condition: []
member: group:gcp-devops@example.org
project: prod-spoke-0
role: roles/compute.networkUser
module.projects["dev-ta-0"].google_essential_contacts_contact.contact["admin-default@example.org"]:
email: admin-default@example.org
language_tag: en
notification_category_subscriptions:
- ALL
parent: projects/test-pf-dev-ta-0
timeouts: null
module.projects["dev-ta-0"].google_project.project[0]:
auto_create_network: false
billing_account: 1245-5678-9012
deletion_policy: DELETE
effective_labels:
goog-terraform-provisioned: 'true'
labels: null
name: test-pf-dev-ta-0
project_id: test-pf-dev-ta-0
tags: null
terraform_labels:
goog-terraform-provisioned: 'true'
timeouts: null
module.projects["dev-ta-0"].google_project_service.project_services["default-service.googleapis.com"]:
disable_dependent_services: false
disable_on_destroy: false
project: test-pf-dev-ta-0
service: default-service.googleapis.com
timeouts: null
module.projects["dev-ta-0"].google_tags_tag_binding.binding["name1"]:
tag_value: default-id1
timeouts: null
module.projects["dev-ta-0"].google_tags_tag_binding.binding["name2"]:
tag_value: default-id2
timeouts: null
module.projects["dev-tb-0"].google_essential_contacts_contact.contact["admin-default@example.org"]:
email: admin-default@example.org
language_tag: en
notification_category_subscriptions:
- ALL
parent: projects/test-pf-dev-tb-0
timeouts: null
module.projects["dev-tb-0"].google_project.project[0]:
auto_create_network: false
billing_account: 1245-5678-9012
deletion_policy: DELETE
effective_labels:
goog-terraform-provisioned: 'true'
labels: null
name: test-pf-dev-tb-0
project_id: test-pf-dev-tb-0
tags: null
terraform_labels:
goog-terraform-provisioned: 'true'
timeouts: null
module.projects["dev-tb-0"].google_project_service.project_services["default-service.googleapis.com"]:
disable_dependent_services: false
disable_on_destroy: false
project: test-pf-dev-tb-0
service: default-service.googleapis.com
timeouts: null
module.projects["dev-tb-0"].google_tags_tag_binding.binding["name1"]:
tag_value: default-id1
timeouts: null
module.projects["dev-tb-0"].google_tags_tag_binding.binding["name2"]:
tag_value: default-id2
timeouts: null
module.projects["prod-ta-0"].google_essential_contacts_contact.contact["admin-default@example.org"]:
email: admin-default@example.org
language_tag: en
notification_category_subscriptions:
- ALL
parent: projects/test-pf-prod-ta-0
timeouts: null
module.projects["prod-ta-0"].google_project.project[0]:
auto_create_network: false
billing_account: 1245-5678-9012
deletion_policy: DELETE
effective_labels:
goog-terraform-provisioned: 'true'
labels: null
name: test-pf-prod-ta-0
project_id: test-pf-prod-ta-0
tags: null
terraform_labels:
goog-terraform-provisioned: 'true'
timeouts: null
module.projects["prod-ta-0"].google_project_service.project_services["default-service.googleapis.com"]:
disable_dependent_services: false
disable_on_destroy: false
project: test-pf-prod-ta-0
service: default-service.googleapis.com
timeouts: null
module.projects["prod-ta-0"].google_tags_tag_binding.binding["name1"]:
tag_value: default-id1
timeouts: null
module.projects["prod-ta-0"].google_tags_tag_binding.binding["name2"]:
tag_value: default-id2
timeouts: null
module.projects["prod-tb-0"].google_essential_contacts_contact.contact["admin-default@example.org"]:
email: admin-default@example.org
language_tag: en
notification_category_subscriptions:
- ALL
parent: projects/test-pf-prod-tb-0
timeouts: null
module.projects["prod-tb-0"].google_project.project[0]:
auto_create_network: false
billing_account: 1245-5678-9012
deletion_policy: DELETE
effective_labels:
goog-terraform-provisioned: 'true'
labels: null
name: test-pf-prod-tb-0
project_id: test-pf-prod-tb-0
tags: null
terraform_labels:
goog-terraform-provisioned: 'true'
timeouts: null
module.projects["prod-tb-0"].google_project_service.project_services["default-service.googleapis.com"]:
disable_dependent_services: false
disable_on_destroy: false
project: test-pf-prod-tb-0
service: default-service.googleapis.com
timeouts: null
module.projects["prod-tb-0"].google_tags_tag_binding.binding["name1"]:
tag_value: default-id1
timeouts: null
module.projects["prod-tb-0"].google_tags_tag_binding.binding["name2"]:
tag_value: default-id2
timeouts: null
counts:
google_compute_shared_vpc_service_project: 4
google_essential_contacts_contact: 4
google_folder: 6
google_project: 4
google_project_iam_member: 4
google_project_service: 4
google_tags_tag_binding: 12
modules: 14
resources: 38

View File

@@ -24,3 +24,6 @@ tests:
data_overrides_defaults:
extra_dirs:
- ../../tests/modules/project_factory/data/data_overrides_defaults/projects
key_ignores_path:
extra_dirs:
- ../../tests/modules/project_factory/data/key_ignores_path