Skip to content

Commit 8298f82

Browse files
authored
Merge pull request GoogleCloudPlatform#4477 from okrause/gcnv-integration
Allow alternative services for private-service-access
2 parents ab97505 + 5a3efa6 commit 8298f82

4 files changed

Lines changed: 71 additions & 21 deletions

File tree

community/modules/network/private-service-access/README.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22

33
This module configures [private service access][psa] for the VPC specified by
44
the `network_id` variable. It can be used by the
5-
[Cloud SQL Federation module][sql].
5+
[Cloud SQL Federation module][sql] or to connect [Google Cloud NetApp Volumes][gcnv].
66

77
It will automatically perform the following steps, as described in the
88
[Private Service Access][psa-creation] creation page:
99

1010
* Create an IP Allocation with the prefix_length specified by the
11-
`ip_alloc_prefix_length` variable.
11+
`ip_alloc_prefix_length` variable. Let Google pick the base address automatically, or specify it by using the `address` variable.
1212
* Create a private connection that establishes a [VPC Network Peering][vpcnp]
13-
connection between your VPC network and the service producer's network
13+
connection between your VPC network and the service producer's network.
14+
* When connecting to Google Cloud NetApp Volumes, it imports and exports custom routes.
15+
16+
### deletion_policy
17+
Some services like CloudSQL or NetApp Volumes delete some internal backend resources lazily. This may take up to a few hours. Deleting the PSA peering while the backend resources still exist will fail. Set `deletion_policy = "ABANDON"` to enable error-free deletion for such PSA connections. See [deletion_policy][deletion_policy].
1418

1519
[sql]: https://github.com/GoogleCloudPlatform/hpc-toolkit/tree/main/community/modules/database/slurm-cloudsql-federation
1620
[psa]: https://cloud.google.com/vpc/docs/configure-private-services-access
1721
[psa-creation]: https://cloud.google.com/vpc/docs/configure-private-services-access#procedure
1822
[vpcnp]: https://cloud.google.com/vpc/docs/vpc-peering
23+
[gcnv]: https://cloud.google.com/netapp/volumes/docs/discover/overview
24+
[deletion_policy]: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_networking_connection.html#deletion_policy-1
1925

2026
### Example
2127

28+
Connecting services which use a service networking PSA connection:
29+
2230
```yaml
2331
- source: modules/network/vpc
2432
id: network
@@ -31,6 +39,21 @@ It will automatically perform the following steps, as described in the
3139
use: [network]
3240
```
3341
42+
Connecting [Google Cloud NetApp Volumes](https://cloud.google.com/netapp/volumes/docs/discover/overview) for using it as a shared filesystem:
43+
44+
```yaml
45+
- source: modules/network/vpc
46+
id: network
47+
48+
- source: community/modules/network/private-service-access
49+
id: ps_connect
50+
use: [network]
51+
settings:
52+
prefix_length: 24
53+
service_name: "netapp.servicenetworking.goog"
54+
deletion_policy: "ABANDON"
55+
```
56+
3457
## License
3558
3659
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
@@ -53,16 +76,14 @@ limitations under the License.
5376
| Name | Version |
5477
|------|---------|
5578
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.2 |
56-
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 3.83 |
57-
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 3.83 |
79+
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 6.40 |
5880
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 |
5981
6082
## Providers
6183
6284
| Name | Version |
6385
|------|---------|
64-
| <a name="provider_google"></a> [google](#provider\_google) | >= 3.83 |
65-
| <a name="provider_google-beta"></a> [google-beta](#provider\_google-beta) | >= 3.83 |
86+
| <a name="provider_google"></a> [google](#provider\_google) | >= 6.40 |
6687
| <a name="provider_random"></a> [random](#provider\_random) | ~> 3.0 |
6788
6889
## Modules
@@ -73,19 +94,22 @@ No modules.
7394
7495
| Name | Type |
7596
|------|------|
76-
| [google-beta_google_compute_global_address.private_ip_alloc](https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/google_compute_global_address) | resource |
97+
| [google_compute_global_address.private_ip_alloc](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_global_address) | resource |
98+
| [google_compute_network_peering_routes_config.private_vpc_peering_routes_gcnv](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network_peering_routes_config) | resource |
7799
| [google_service_networking_connection.private_vpc_connection](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_networking_connection) | resource |
78100
| [random_id.resource_name_suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
79101
80102
## Inputs
81103
82104
| Name | Description | Type | Default | Required |
83105
|------|-------------|------|---------|:--------:|
84-
| <a name="input_address"></a> [address](#input\_address) | The IP address or beginning of the address range allocated for the private service access. | `string` | `null` | no |
106+
| <a name="input_address"></a> [address](#input\_address) | The IP address or beginning of the address range allocated for the Private Service Access. | `string` | `null` | no |
107+
| <a name="input_deletion_policy"></a> [deletion\_policy](#input\_deletion\_policy) | The policy to apply when deleting the Private Service Access. Leave empty or use ABANDON. | `string` | `null` | no |
85108
| <a name="input_labels"></a> [labels](#input\_labels) | Labels to add to supporting resources. Key-value pairs. | `map(string)` | n/a | yes |
86-
| <a name="input_network_id"></a> [network\_id](#input\_network\_id) | The ID of the GCE VPC network to configure private service Access.:<br/>`projects/<project_id>/global/networks/<network_name>`" | `string` | n/a | yes |
87-
| <a name="input_prefix_length"></a> [prefix\_length](#input\_prefix\_length) | The prefix length of the IP range allocated for the private service access. | `number` | `16` | no |
109+
| <a name="input_network_id"></a> [network\_id](#input\_network\_id) | The ID of the GCE VPC network to configure Private Service Access:<br/>`projects/<project_id>/global/networks/<network_name>`" | `string` | n/a | yes |
110+
| <a name="input_prefix_length"></a> [prefix\_length](#input\_prefix\_length) | The prefix length of the IP range allocated for the Private Service Access. | `number` | `16` | no |
88111
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | ID of project in which Private Service Access will be created. | `string` | n/a | yes |
112+
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | The name of the service to connect. Defaults to 'servicenetworking.googleapis.com'. | `string` | `"servicenetworking.googleapis.com"` | no |
89113

90114
## Outputs
91115

community/modules/network/private-service-access/main.tf

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ locals {
1919
labels = merge(var.labels, { ghpc_module = "private-service-access", ghpc_role = "network" })
2020
}
2121

22+
locals {
23+
split_network_id = split("/", var.network_id)
24+
network_name = local.split_network_id[4]
25+
network_project = local.split_network_id[1]
26+
}
27+
2228
resource "random_id" "resource_name_suffix" {
2329
byte_length = 4
2430
}
2531

2632
resource "google_compute_global_address" "private_ip_alloc" {
27-
provider = google-beta
33+
provider = google
2834
name = "global-psconnect-ip-${random_id.resource_name_suffix.hex}"
2935
project = var.project_id
3036
purpose = "VPC_PEERING"
@@ -37,6 +43,18 @@ resource "google_compute_global_address" "private_ip_alloc" {
3743

3844
resource "google_service_networking_connection" "private_vpc_connection" {
3945
network = var.network_id
40-
service = "servicenetworking.googleapis.com"
46+
service = var.service_name
4147
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
48+
deletion_policy = var.deletion_policy
49+
}
50+
51+
# Google Cloud NetApp Volumes need enablement of custom_route import and export
52+
resource "google_compute_network_peering_routes_config" "private_vpc_peering_routes_gcnv" {
53+
count = var.service_name == "netapp.servicenetworking.goog" ? 1 : 0
54+
project = local.network_project
55+
network = local.network_name
56+
peering = google_service_networking_connection.private_vpc_connection.peering
57+
58+
export_custom_routes = true
59+
import_custom_routes = true
4260
}

community/modules/network/private-service-access/variables.tf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# limitations under the License.
1414

1515
variable "address" {
16-
description = "The IP address or beginning of the address range allocated for the private service access."
16+
description = "The IP address or beginning of the address range allocated for the Private Service Access."
1717
type = string
1818
default = null
1919
}
2020

2121
variable "network_id" {
2222
description = <<-EOT
23-
The ID of the GCE VPC network to configure private service Access.:
23+
The ID of the GCE VPC network to configure Private Service Access:
2424
`projects/<project_id>/global/networks/<network_name>`"
2525
EOT
2626
type = string
@@ -36,7 +36,7 @@ variable "labels" {
3636
}
3737

3838
variable "prefix_length" {
39-
description = "The prefix length of the IP range allocated for the private service access."
39+
description = "The prefix length of the IP range allocated for the Private Service Access."
4040
type = number
4141
default = 16
4242
}
@@ -45,3 +45,15 @@ variable "project_id" {
4545
description = "ID of project in which Private Service Access will be created."
4646
type = string
4747
}
48+
49+
variable "service_name" {
50+
description = "The name of the service to connect. Defaults to 'servicenetworking.googleapis.com'."
51+
type = string
52+
default = "servicenetworking.googleapis.com"
53+
}
54+
55+
variable "deletion_policy" {
56+
description = "The policy to apply when deleting the Private Service Access. Leave empty or use ABANDON."
57+
type = string
58+
default = null
59+
}

community/modules/network/private-service-access/versions.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ terraform {
1818
required_providers {
1919
google = {
2020
source = "hashicorp/google"
21-
version = ">= 3.83"
22-
}
23-
google-beta = {
24-
source = "hashicorp/google-beta"
25-
version = ">= 3.83"
21+
version = ">= 6.40"
2622
}
2723
random = {
2824
source = "hashicorp/random"

0 commit comments

Comments
 (0)