diff --git a/modules/project/outputs.tf b/modules/project/outputs.tf index 035d415aca..4bd28aa0e4 100644 --- a/modules/project/outputs.tf +++ b/modules/project/outputs.tf @@ -58,6 +58,7 @@ output "project_id" { google_project_organization_policy.list, google_project_service.project_services, google_compute_shared_vpc_host_project.shared_vpc_host, + google_compute_shared_vpc_service_project.shared_vpc_service, google_compute_shared_vpc_service_project.service_projects, google_project_iam_member.shared_vpc_host_robots, google_kms_crypto_key_iam_member.service_identity_cmek, diff --git a/tests/modules/project/fixture/main.tf b/tests/modules/project/fixture/main.tf index b9d97016c7..a9867e5d9b 100644 --- a/tests/modules/project/fixture/main.tf +++ b/tests/modules/project/fixture/main.tf @@ -39,3 +39,28 @@ module "test" { shared_vpc_host_config = var.shared_vpc_host_config } +module "test-svpc-service" { + source = "../../../../modules/project" + count = var._test_service_project ? 1 : 0 + name = "test-svc" + billing_account = var.billing_account + auto_create_network = false + parent = var.parent + services = var.services + shared_vpc_service_config = { + attach = true + host_project = module.test.project_id + service_identity_iam = { + "roles/compute.networkUser" = [ + "cloudservices", "container-engine" + ] + "roles/vpcaccess.user" = [ + "cloudrun" + ] + "roles/container.hostServiceAgentUser" = [ + "container-engine" + ] + } + } +} + diff --git a/tests/modules/project/fixture/variables.tf b/tests/modules/project/fixture/variables.tf index 43196e3f0d..2a4d95d1e7 100644 --- a/tests/modules/project/fixture/variables.tf +++ b/tests/modules/project/fixture/variables.tf @@ -14,6 +14,11 @@ * limitations under the License. */ +variable "_test_service_project" { + type = bool + default = false +} + variable "name" { type = string default = "my-project" diff --git a/tests/modules/project/test_plan_svpc.py b/tests/modules/project/test_plan_svpc.py new file mode 100644 index 0000000000..bd22131d97 --- /dev/null +++ b/tests/modules/project/test_plan_svpc.py @@ -0,0 +1,26 @@ +# Copyright 2022 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. + +import os + +def test_svpc(_plan_runner): + "Test Shared VPC service project attachment." + fixture_path = os.path.join(os.path.dirname(__file__), 'fixture') + plan = _plan_runner(fixture_path=fixture_path, _test_service_project='true') + modules = [m for m in plan.root_module['child_modules']] + resources = [r for r in modules[0]['resources'] if r['address'] == 'module.test.google_compute_shared_vpc_host_project.shared_vpc_host[0]'] + assert len(resources) == 1 + print(modules[1]['resources']) + resources = [r for r in modules[1]['resources'] if r['address'] == 'module.test-svpc-service[0].google_compute_shared_vpc_service_project.shared_vpc_service[0]'] + assert len(resources) == 1