Skip to content

Commit

Permalink
Shared vpc service fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
apichick committed Aug 2, 2022
1 parent 0655f68 commit 35a88d4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/project/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions tests/modules/project/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
}

5 changes: 5 additions & 0 deletions tests/modules/project/fixture/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
* limitations under the License.
*/

variable "_test_service_project" {
type = bool
default = false
}

variable "name" {
type = string
default = "my-project"
Expand Down
26 changes: 26 additions & 0 deletions tests/modules/project/test_plan_svpc.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 35a88d4

Please sign in to comment.