Skip to content

Commit 1abce4f

Browse files
feat: Implement private services connection module with examples and tests (#692)
Co-authored-by: krprabhat-eng <krprabhat@google.com>
1 parent 5f8760d commit 1abce4f

30 files changed

Lines changed: 340 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Then perform the following commands on the root folder:
125125
| network\_firewall\_policy\_enforcement\_order | Set the order that Firewall Rules and Firewall Policies are evaluated. Valid values are `BEFORE_CLASSIC_FIREWALL` and `AFTER_CLASSIC_FIREWALL`. (default null or equivalent to `AFTER_CLASSIC_FIREWALL`) | `string` | `null` | no |
126126
| network\_name | The name of the network being created | `string` | n/a | yes |
127127
| network\_profile | "A full or partial URL of the network profile to apply to this network.<br>This field can be set only at resource creation time. For example, the<br>following are valid URLs:<br> * https://www.googleapis.com/compute/beta/projects/{projectId}/global/networkProfiles/{network_profile_name}<br> * projects/{projectId}/global/networkProfiles/{network\_profile\_name} | `string` | `null` | no |
128+
| private\_service\_access\_config | Configuration for Private Service Access (PSA) connection. | <pre>object({<br> enable_private_services_connection = bool<br> address_name = string<br> prefix_length = number<br> })</pre> | <pre>{<br> "address_name": "private-ip-address",<br> "enable_private_services_connection": false,<br> "prefix_length": 16<br>}</pre> | no |
128129
| project\_id | The ID of the project where this VPC will be created | `string` | n/a | yes |
129130
| routes | List of routes being created in this VPC. | <pre>list(object({<br> name = string<br> description = optional(string)<br> tags = optional(list(string), [])<br> destination_range = string<br> next_hop_gateway = optional(string)<br> next_hop_internet = optional(bool, false)<br> next_hop_ip = optional(string)<br> next_hop_instance = optional(string)<br> next_hop_instance_zone = optional(string)<br> next_hop_vpn_tunnel = optional(string)<br> next_hop_ilb = optional(string)<br> priority = optional(number, 1000)<br> }))</pre> | `[]` | no |
130131
| routing\_mode | The network routing mode (default 'GLOBAL') | `string` | `"GLOBAL"` | no |

examples/network_connectivity_center/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ module "network_connectivity_center_star" {
107107
# VPC Spoke #
108108
################################
109109
module "vpc_spoke_vpc" {
110-
source = "terraform-google-modules/network/google"
110+
source = "terraform-google-modules/network/google"
111+
version = "~> 18.0"
112+
111113
project_id = var.project_id
112114
network_name = var.vpc_spoke_vpc_name
113115
routing_mode = "GLOBAL"
@@ -137,6 +139,7 @@ module "vpc_spoke_vpc" {
137139
# Simulates an on-prem network that will be connected over VPN
138140
module "vpn_spoke_remote_vpc" {
139141
source = "terraform-google-modules/network/google"
142+
version = "~> 18.0.0"
140143
project_id = var.project_id
141144
network_name = var.vpn_spoke_remote_vpc_name
142145
routing_mode = "GLOBAL"
@@ -162,6 +165,7 @@ module "vpn_spoke_remote_vpc" {
162165

163166
module "vpn_spoke_local_vpc" {
164167
source = "terraform-google-modules/network/google"
168+
version = "~> 18.0.0"
165169
project_id = var.project_id
166170
network_name = var.vpn_spoke_local_vpc_name
167171
routing_mode = "GLOBAL"
@@ -260,6 +264,7 @@ resource "random_shuffle" "zone" {
260264

261265
module "router_appliance_spoke_vpc" {
262266
source = "terraform-google-modules/network/google"
267+
version = "~> 18.0.0"
263268
project_id = var.project_id
264269
network_name = var.router_appliance_vpc_name
265270
routing_mode = "GLOBAL"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "vpc" {
18+
source = "../.."
19+
project_id = var.project_id
20+
network_name = "example-psa-vpc"
21+
22+
private_service_access_config = {
23+
enable_private_services_connection = true
24+
address_name = "custom-psa-address"
25+
prefix_length = 16
26+
}
27+
28+
subnets = [
29+
{
30+
subnet_name = "psa-subnet"
31+
subnet_ip = "10.0.0.0/24"
32+
subnet_region = "us-central1"
33+
}
34+
]
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The ID of the project where the network will be created."
19+
type = string
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_version = ">= 1.3"
19+
20+
required_providers {
21+
google = {
22+
source = "hashicorp/google"
23+
version = ">= 6.18, < 8"
24+
}
25+
google-beta = {
26+
source = "hashicorp/google-beta"
27+
version = ">= 6.18, < 8"
28+
}
29+
random = {
30+
source = "hashicorp/random"
31+
version = ">= 3.4"
32+
}
33+
}
34+
}

examples/routes/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# [START vpc_static_route_create]
2424
module "google_compute_route" {
2525
source = "../../modules/routes" #adding local path
26-
project_id = var.project_id # Replace this with your project ID in quotes
26+
project_id = var.project_id # Replace this with your project ID in quotes
2727
network_name = "default"
2828

2929
routes = [

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@ module "firewall_rules" {
9090
ingress_rules = var.ingress_rules
9191
egress_rules = var.egress_rules
9292
}
93+
94+
module "private_service_access" {
95+
source = "./modules/private-service-access"
96+
count = var.private_service_access_config.enable_private_services_connection ? 1 : 0
97+
98+
project_id = var.project_id
99+
network_id = module.vpc.network_id
100+
address_name = var.private_service_access_config.address_name
101+
prefix_length = var.private_service_access_config.prefix_length
102+
}

metadata.display.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ spec:
9494
title: Network Profile
9595
regexValidation: ^(?:https://www\\.googleapis\\.com/compute/[a-zA-Z0-9._-]+/)?projects/(?:(?:[a-z0-9.-]+:)?[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?)/global/networkProfiles/[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?$
9696
validation: "The full or partial URL of the network profile. Examples: 'https://www.googleapis.com/compute/v1/projects/my-project/global/networkProfiles/my-profile' or 'projects/my-project/global/networkProfiles/my-profile'."
97+
private_service_access_config:
98+
name: private_service_access_config
99+
title: Private Service Access Config
97100
project_id:
98101
name: project_id
99102
title: Project Id

metadata.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ spec:
4545
location: modules/network-firewall-policy
4646
- name: network-peering
4747
location: modules/network-peering
48+
- name: private-service-access
49+
location: modules/private-service-access
4850
- name: private-service-connect
4951
location: modules/private-service-connect
5052
- name: private-service-connect-endpoints-for-published-services
@@ -96,6 +98,8 @@ spec:
9698
location: examples/network_service_tiers
9799
- name: packet_mirroring
98100
location: examples/packet_mirroring
101+
- name: private-service-access
102+
location: examples/private-service-access
99103
- name: private_service_connect
100104
location: examples/private_service_connect
101105
- name: private_service_connect_endpoints_for_published_services
@@ -322,6 +326,18 @@ spec:
322326
- name: bgp_inter_region_cost
323327
description: Specifies the BGP inter-region cost mode. Valid values are `DEFAULT` or `ADD_COST_TO_MED`.
324328
varType: string
329+
- name: private_service_access_config
330+
description: Configuration for Private Service Access (PSA) connection.
331+
varType: |-
332+
object({
333+
enable_private_services_connection = bool
334+
address_name = string
335+
prefix_length = number
336+
})
337+
defaultValue:
338+
address_name: private-ip-address
339+
enable_private_services_connection: false
340+
prefix_length: 16
325341
outputs:
326342
- name: network
327343
description: The created network

modules/fabric-net-firewall/metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ spec:
6464
location: examples/network_service_tiers
6565
- name: packet_mirroring
6666
location: examples/packet_mirroring
67+
- name: private-service-access
68+
location: examples/private-service-access
6769
- name: private_service_connect
6870
location: examples/private_service_connect
6971
- name: private_service_connect_endpoints_for_published_services

0 commit comments

Comments
 (0)