Add support for Private Service Connect and Reginal Managed Proxy subnets for net-vpc module

This commit is contained in:
Aleksandr Averbukh 2022-04-12 12:57:33 +02:00
parent 7f6a5bf548
commit 6ab121a836
4 changed files with 68 additions and 1 deletions

View File

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- CloudSQ: fixed Terraform change detection when backup is disabled
- Allow multiple CIDR blocks in the ip_range for Apigee Instance
- Add prefix to project factory SA bindings
- Add support for Private Service Connect and Reginal Managed Proxy subnets for `net-vpc` module
**FAST**

View File

@ -258,7 +258,9 @@ flow_logs: # enable, set to empty map to use defaults
| [subnet_private_access](variables.tf#L169) | Optional map of boolean to control private Google access (default is enabled), keyed by subnet 'region/name'. | <code>map&#40;bool&#41;</code> | | <code>&#123;&#125;</code> |
| [subnets](variables.tf#L175) | List of subnets being created. | <code title="list&#40;object&#40;&#123;&#10; name &#61; string&#10; ip_cidr_range &#61; string&#10; region &#61; string&#10; secondary_ip_range &#61; map&#40;string&#41;&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#91;&#93;</code> |
| [subnets_l7ilb](variables.tf#L186) | List of subnets for private HTTPS load balancer. | <code title="list&#40;object&#40;&#123;&#10; active &#61; bool&#10; name &#61; string&#10; ip_cidr_range &#61; string&#10; region &#61; string&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#91;&#93;</code> |
| [vpc_create](variables.tf#L197) | Create VPC. When set to false, uses a data source to reference existing VPC. | <code>bool</code> | | <code>true</code> |
| [subnets_l7rlb](variables.tf#L197) | List of proxy-only subnets for HTTPS regional load balancers. Note: Only one proxy-only subnet for each VPC network in each region can be active. | <code title="list&#40;object&#40;&#123;&#10; active &#61; bool&#10; name &#61; string&#10; ip_cidr_range &#61; string&#10; region &#61; string&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#91;&#93;</code> |
| [subnets_psc](variables.tf#L208) | List of subnets for Private Service Connect service producers. | <code title="list&#40;object&#40;&#123;&#10; name &#61; string&#10; ip_cidr_range &#61; string&#10; region &#61; string&#10;&#125;&#41;&#41;">list&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#91;&#93;</code> |
| [vpc_create](variables.tf#L218) | Create VPC. When set to false, uses a data source to reference existing VPC. | <code>bool</code> | | <code>true</code> |
## Outputs

View File

@ -89,6 +89,14 @@ locals {
for subnet in var.subnets_l7ilb :
"${subnet.region}/${subnet.name}" => subnet
}
subnets_l7rlb = {
for subnet in var.subnets_l7rlb :
"${subnet.region}/${subnet.name}" => subnet
}
subnets_psc = {
for subnet in var.subnets_psc :
"${subnet.region}/${subnet.name}" => subnet
}
}
resource "google_compute_subnetwork" "subnetwork" {
@ -142,6 +150,41 @@ resource "google_compute_subnetwork" "l7ilb" {
)
}
resource "google_compute_subnetwork" "l7rlb" {
provider = google-beta
for_each = local.subnets_l7rlb
project = var.project_id
network = local.network.name
region = each.value.region
name = each.value.name
ip_cidr_range = each.value.ip_cidr_range
purpose = "REGIONAL_MANAGED_PROXY"
role = (
each.value.active || each.value.active == null ? "ACTIVE" : "BACKUP"
)
description = lookup(
local.subnet_descriptions,
"${each.value.region}/${each.value.name}",
"Terraform-managed."
)
}
resource "google_compute_subnetwork" "psc" {
provider = google-beta
for_each = local.subnets_psc
project = var.project_id
network = local.network.name
region = each.value.region
name = each.value.name
ip_cidr_range = each.value.ip_cidr_range
purpose = "PRIVATE_SERVICE_CONNECT"
description = lookup(
local.subnet_descriptions,
"${each.value.region}/${each.value.name}",
"Terraform-managed."
)
}
resource "google_compute_subnetwork_iam_binding" "binding" {
for_each = {
for binding in local.subnet_iam_members :

View File

@ -194,6 +194,27 @@ variable "subnets_l7ilb" {
default = []
}
variable "subnets_l7rlb" {
description = "List of proxy-only subnets for HTTPS regional load balancers. Note: Only one proxy-only subnet for each VPC network in each region can be active."
type = list(object({
active = bool
name = string
ip_cidr_range = string
region = string
}))
default = []
}
variable "subnets_psc" {
description = "List of subnets for Private Service Connect service producers."
type = list(object({
name = string
ip_cidr_range = string
region = string
}))
default = []
}
variable "vpc_create" {
description = "Create VPC. When set to false, uses a data source to reference existing VPC."
type = bool