Merge branch 'master' into sql-multi-region

This commit is contained in:
lcaggio 2022-04-15 09:26:57 +02:00 committed by GitHub
commit 47563fdab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 144 additions and 74 deletions

View File

@ -7,7 +7,9 @@ All notable changes to this project will be documented in this file.
- SQL Server AlwaysOn availability groups example
- 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 prefix to project factory SA bindings
- **incompatible change** `subnets_l7ilb` variable is deprecated in the `net-vpc` module, instead `subnets_proxy_only` variable [should be used](https://cloud.google.com/load-balancing/docs/proxy-only-subnets#proxy_only_subnet_create)
- Add support for [Private Service Connect](https://cloud.google.com/vpc/docs/private-service-connect#psc-subnets) and [Proxy-only](https://cloud.google.com/load-balancing/docs/proxy-only-subnets) subnets to `net-vpc` module
**FAST**

View File

@ -82,29 +82,29 @@ module "organization" {
)
# sample subset of useful organization policies, edit to suit requirements
policy_boolean = {
"constraints/cloudfunctions.requireVPCConnector" = true
"constraints/compute.disableGuestAttributesAccess" = true
"constraints/compute.disableInternetNetworkEndpointGroup" = true
"constraints/compute.disableNestedVirtualization" = true
"constraints/compute.disableSerialPortAccess" = true
"constraints/compute.requireOsLogin" = true
"constraints/compute.restrictXpnProjectLienRemoval" = true
"constraints/compute.skipDefaultNetworkCreation" = true
"constraints/compute.setNewProjectDefaultToZonalDNSOnly" = true
# "constraints/cloudfunctions.requireVPCConnector" = true
# "constraints/compute.disableGuestAttributesAccess" = true
# "constraints/compute.disableInternetNetworkEndpointGroup" = true
# "constraints/compute.disableNestedVirtualization" = true
# "constraints/compute.disableSerialPortAccess" = true
"constraints/compute.requireOsLogin" = true
# "constraints/compute.restrictXpnProjectLienRemoval" = true
"constraints/compute.skipDefaultNetworkCreation" = true
# "constraints/compute.setNewProjectDefaultToZonalDNSOnly" = true
"constraints/iam.automaticIamGrantsForDefaultServiceAccounts" = true
"constraints/iam.disableServiceAccountKeyCreation" = true
"constraints/iam.disableServiceAccountKeyUpload" = true
"constraints/sql.restrictPublicIp" = true
"constraints/sql.restrictAuthorizedNetworks" = true
"constraints/storage.uniformBucketLevelAccess" = true
# "constraints/iam.disableServiceAccountKeyUpload" = true
"constraints/sql.restrictPublicIp" = true
"constraints/sql.restrictAuthorizedNetworks" = true
"constraints/storage.uniformBucketLevelAccess" = true
}
policy_list = {
"constraints/cloudfunctions.allowedIngressSettings" = merge(
local.list_allow, { values = ["is:ALLOW_INTERNAL_ONLY"] }
)
"constraints/cloudfunctions.allowedVpcConnectorEgressSettings" = merge(
local.list_allow, { values = ["is:PRIVATE_RANGES_ONLY"] }
)
# "constraints/cloudfunctions.allowedIngressSettings" = merge(
# local.list_allow, { values = ["is:ALLOW_INTERNAL_ONLY"] }
# )
# "constraints/cloudfunctions.allowedVpcConnectorEgressSettings" = merge(
# local.list_allow, { values = ["is:PRIVATE_RANGES_ONLY"] }
# )
"constraints/compute.restrictLoadBalancerCreationForTypes" = merge(
local.list_allow, { values = ["in:INTERNAL"] }
)
@ -119,9 +119,9 @@ module "organization" {
"constraints/run.allowedIngress" = merge(
local.list_allow, { values = ["is:internal"] }
)
"constraints/run.allowedVPCEgress" = merge(
local.list_allow, { values = ["is:private-ranges-only"] }
)
# "constraints/run.allowedVPCEgress" = merge(
# local.list_allow, { values = ["is:private-ranges-only"] }
# )
# "constraints/compute.restrictCloudNATUsage" = local.list_deny
# "constraints/compute.restrictDedicatedInterconnectUsage" = local.list_deny
# "constraints/compute.restrictPartnerInterconnectUsage" = local.list_deny

View File

@ -52,7 +52,7 @@ module "dev-spoke-vpc" {
data_folder = "${var.data_dir}/subnets/dev"
delete_default_routes_on_create = true
psa_config = try(var.psa_ranges.dev, null)
subnets_l7ilb = local.l7ilb_subnets.dev
subnets_proxy_only = local.l7ilb_subnets.dev
# Set explicit routes for googleapis; send everything else to NVAs
routes = {
private-googleapis = {

View File

@ -52,7 +52,7 @@ module "prod-spoke-vpc" {
data_folder = "${var.data_dir}/subnets/prod"
delete_default_routes_on_create = true
psa_config = try(var.psa_ranges.prod, null)
subnets_l7ilb = local.l7ilb_subnets.prod
subnets_proxy_only = local.l7ilb_subnets.prod
# Set explicit routes for googleapis; send everything else to NVAs
routes = {
private-googleapis = {

View File

@ -46,13 +46,13 @@ module "dev-spoke-project" {
}
module "dev-spoke-vpc" {
source = "../../../modules/net-vpc"
project_id = module.dev-spoke-project.project_id
name = "dev-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/dev"
psa_config = try(var.psa_ranges.dev, null)
subnets_l7ilb = local.l7ilb_subnets.dev
source = "../../../modules/net-vpc"
project_id = module.dev-spoke-project.project_id
name = "dev-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/dev"
psa_config = try(var.psa_ranges.dev, null)
subnets_proxy_only = local.l7ilb_subnets.dev
# set explicit routes for googleapis in case the default route is deleted
routes = {
private-googleapis = {

View File

@ -46,13 +46,13 @@ module "prod-spoke-project" {
}
module "prod-spoke-vpc" {
source = "../../../modules/net-vpc"
project_id = module.prod-spoke-project.project_id
name = "prod-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/prod"
psa_config = try(var.psa_ranges.prod, null)
subnets_l7ilb = local.l7ilb_subnets.prod
source = "../../../modules/net-vpc"
project_id = module.prod-spoke-project.project_id
name = "prod-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/prod"
psa_config = try(var.psa_ranges.prod, null)
subnets_proxy_only = local.l7ilb_subnets.prod
# set explicit routes for googleapis in case the default route is deleted
routes = {
private-googleapis = {

View File

@ -46,13 +46,13 @@ module "dev-spoke-project" {
}
module "dev-spoke-vpc" {
source = "../../../modules/net-vpc"
project_id = module.dev-spoke-project.project_id
name = "dev-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/dev"
psa_config = try(var.psa_ranges.dev, null)
subnets_l7ilb = local.l7ilb_subnets.dev
source = "../../../modules/net-vpc"
project_id = module.dev-spoke-project.project_id
name = "dev-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/dev"
psa_config = try(var.psa_ranges.dev, null)
subnets_proxy_only = local.l7ilb_subnets.dev
# set explicit routes for googleapis in case the default route is deleted
routes = {
private-googleapis = {

View File

@ -46,13 +46,13 @@ module "prod-spoke-project" {
}
module "prod-spoke-vpc" {
source = "../../../modules/net-vpc"
project_id = module.prod-spoke-project.project_id
name = "prod-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/prod"
psa_config = try(var.psa_ranges.prod, null)
subnets_l7ilb = local.l7ilb_subnets.prod
source = "../../../modules/net-vpc"
project_id = module.prod-spoke-project.project_id
name = "prod-spoke-0"
mtu = 1500
data_folder = "${var.data_dir}/subnets/prod"
psa_config = try(var.psa_ranges.prod, null)
subnets_proxy_only = local.l7ilb_subnets.prod
# set explicit routes for googleapis in case the default route is deleted
routes = {
private-googleapis = {

View File

@ -171,6 +171,38 @@ module "vpc" {
# tftest modules=1 resources=5
```
### Subnets for Private Service Connect, Proxy-only subnets
Along with common private subnets module supports creation more service specific subnets for the following purposes:
- [Proxy-only subnets](https://cloud.google.com/load-balancing/docs/proxy-only-subnets) for Regional HTTPS Internal HTTPS Load Balancers
- [Private Service Connect](https://cloud.google.com/vpc/docs/private-service-connect#psc-subnets) subnets
```hcl
module "vpc" {
source = "./modules/net-vpc"
project_id = "my-project"
name = "my-network"
subnets_proxy_only = [
{
ip_cidr_range = "10.0.1.0/24"
name = "regional-proxy"
region = "europe-west1"
active = true
}
]
subnets_psc = [
{
ip_cidr_range = "10.0.3.0/24"
name = "psc"
region = "europe-west1"
}
]
}
# tftest modules=1 resources=3
```
### DNS Policies
```hcl
@ -257,8 +289,9 @@ flow_logs: # enable, set to empty map to use defaults
| [subnet_flow_logs](variables.tf#L163) | Optional map of boolean to control flow logs (default is disabled), keyed by subnet 'region/name'. | <code>map&#40;bool&#41;</code> | | <code>&#123;&#125;</code> |
| [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_proxy_only](variables.tf#L186) | List of proxy-only subnets for Regional HTTPS or Internal HTTPS 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#L197) | 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#L207) | Create VPC. When set to false, uses a data source to reference existing VPC. | <code>bool</code> | | <code>true</code> |
## Outputs
@ -274,7 +307,8 @@ flow_logs: # enable, set to empty map to use defaults
| [subnet_secondary_ranges](outputs.tf#L85) | Map of subnet secondary ranges keyed by name. | |
| [subnet_self_links](outputs.tf#L96) | Map of subnet self links keyed by name. | |
| [subnets](outputs.tf#L102) | Subnet resources. | |
| [subnets_l7ilb](outputs.tf#L107) | L7 ILB subnet resources. | |
| [subnets_proxy_only](outputs.tf#L107) | L7 ILB or L7 Regional LB subnet resources. | |
| [subnets_psc](outputs.tf#L112) | Private Service Connect subnet resources. | |
<!-- END TFDOC -->
The key format is `subnet_region/subnet_name`. For example `europe-west1/my_subnet`.

View File

@ -104,7 +104,12 @@ output "subnets" {
value = { for k, v in google_compute_subnetwork.subnetwork : k => v }
}
output "subnets_l7ilb" {
description = "L7 ILB subnet resources."
value = { for k, v in google_compute_subnetwork.l7ilb : k => v }
output "subnets_proxy_only" {
description = "L7 ILB or L7 Regional LB subnet resources."
value = { for k, v in google_compute_subnetwork.proxy_only : k => v }
}
output "subnets_psc" {
description = "Private Service Connect subnet resources."
value = { for k, v in google_compute_subnetwork.psc : k => v }
}

View File

@ -85,8 +85,12 @@ locals {
{ for subnet in var.subnets : "${subnet.region}/${subnet.name}" => subnet },
local._factory_subnets
)
subnets_l7ilb = {
for subnet in var.subnets_l7ilb :
subnets_proxy_only = {
for subnet in var.subnets_proxy_only :
"${subnet.region}/${subnet.name}" => subnet
}
subnets_psc = {
for subnet in var.subnets_psc :
"${subnet.region}/${subnet.name}" => subnet
}
}
@ -123,22 +127,36 @@ resource "google_compute_subnetwork" "subnetwork" {
}
}
resource "google_compute_subnetwork" "l7ilb" {
provider = google-beta
for_each = local.subnets_l7ilb
resource "google_compute_subnetwork" "proxy_only" {
for_each = local.subnets_proxy_only
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 = "INTERNAL_HTTPS_LOAD_BALANCER"
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."
"Terraform-managed proxy-only subnet for Regional HTTPS or Internal HTTPS LB."
)
}
resource "google_compute_subnetwork" "psc" {
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 subnet for Private Service Connect (PSC NAT)."
)
}

View File

@ -183,8 +183,8 @@ variable "subnets" {
default = []
}
variable "subnets_l7ilb" {
description = "List of subnets for private HTTPS load balancer."
variable "subnets_proxy_only" {
description = "List of proxy-only subnets for Regional HTTPS or Internal HTTPS 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
@ -194,6 +194,16 @@ variable "subnets_l7ilb" {
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

View File

@ -39,12 +39,13 @@ locals {
dataproc = "service-%s@dataproc-accounts"
gae-flex = "service-%s@gae-api-prod"
# TODO: deprecate gcf
gcf = "service-%s@gcf-admin-robot"
pubsub = "service-%s@gcp-sa-pubsub"
secretmanager = "service-%s@gcp-sa-secretmanager"
sql = "service-%s@gcp-sa-cloud-sql"
storage = "service-%s@gs-project-accounts"
sqladmin = "service-%s@gcp-sa-cloud-sql"
gcf = "service-%s@gcf-admin-robot"
monitoring-notifications = "service-%s@gcp-sa-monitoring-notification"
pubsub = "service-%s@gcp-sa-pubsub"
secretmanager = "service-%s@gcp-sa-secretmanager"
sql = "service-%s@gcp-sa-cloud-sql"
sqladmin = "service-%s@gcp-sa-cloud-sql"
storage = "service-%s@gs-project-accounts"
}
service_accounts_default = {
compute = "${local.project.number}-compute@developer.gserviceaccount.com"