Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support to proxy-only subnetworks and new IP CIDR allocation #1040

Merged
merged 52 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b5d2118
Development
Samir-Cit Nov 17, 2023
cf38333
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Nov 28, 2023
ad2e3cf
Fix dev
Samir-Cit Nov 28, 2023
24adc68
Non-Production IPs
Samir-Cit Nov 28, 2023
e150c9d
Production IPs
Samir-Cit Nov 28, 2023
989dbe6
Hub IPs
Samir-Cit Nov 28, 2023
e477388
Merge branch 'terraform-google-modules:master' into fix/ip-allocation
Samir-Cit Nov 29, 2023
6cb871a
Replicate IPs to Hub and Spoke
Samir-Cit Nov 29, 2023
4c2cb78
Merge branch 'fix/ip-allocation' of github.com:Samir-Cit/terraform-ex…
Samir-Cit Nov 29, 2023
5567337
Fix other IPs
Samir-Cit Nov 29, 2023
77ea3cc
Fix IP for transitivity
Samir-Cit Nov 29, 2023
b740b10
Fix test IPs
Samir-Cit Nov 29, 2023
e28d1fa
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Nov 30, 2023
2416f77
Fix IP on test
Samir-Cit Nov 30, 2023
2794eb0
Fix IP on test
Samir-Cit Nov 30, 2023
387adb9
Merge branch 'master' into fix/ip-allocation
Samir-Cit Nov 30, 2023
d9a8893
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Dec 4, 2023
64049ca
Add variables to new proxy-only subnets
Samir-Cit Dec 4, 2023
1a9eccb
Using new variables for proxy-only subnet
Samir-Cit Dec 4, 2023
360d4b0
Small fix on proxy-only subnets
Samir-Cit Dec 4, 2023
92471e9
Lint
Samir-Cit Dec 4, 2023
9e85b9a
Fix proxy subnet creation.
Samir-Cit Dec 4, 2023
7b5a19b
Lint
Samir-Cit Dec 4, 2023
e909ada
Fix hub proxy subnet
Samir-Cit Dec 5, 2023
9db58f1
Fix test
Samir-Cit Dec 5, 2023
84c7a46
Fix subnet hub proxy. Remove private access.
Samir-Cit Dec 5, 2023
86d0819
Merge branch 'master' into fix/ip-allocation
Samir-Cit Dec 5, 2023
b9f6633
Merge branch 'master' into fix/ip-allocation
Samir-Cit Dec 6, 2023
bde64d3
Merge branch 'master' into fix/ip-allocation
daniel-cit Dec 10, 2023
d71c642
Merge branch 'master' into fix/ip-allocation
daniel-cit Dec 11, 2023
a5e0529
Replace /16 to /18 on hub
Samir-Cit Dec 11, 2023
ac498c5
Other small fixes
Samir-Cit Dec 11, 2023
351e512
Lint
Samir-Cit Dec 11, 2023
d5ae8aa
Fix subnets creation and proxy-only
Samir-Cit Dec 11, 2023
f4e16df
Merge branch 'fix/ip-allocation' of github.com:Samir-Cit/terraform-ex…
Samir-Cit Dec 11, 2023
642c70f
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Dec 11, 2023
c99cd06
Lint readme
Samir-Cit Dec 11, 2023
79ce9f3
ipv6 default value: INTERNAL
Samir-Cit Dec 12, 2023
049ea7b
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Dec 13, 2023
c58a6ee
Lint
Samir-Cit Dec 13, 2023
53c3836
Remove network test DefaultVerify
Samir-Cit Dec 14, 2023
d26ab6f
Remove shared test DefaultVerify
Samir-Cit Dec 14, 2023
5362ea4
Remove shared test DefaultVerify
Samir-Cit Dec 14, 2023
366476d
Add resource issue on the comment in test files.
Samir-Cit Dec 14, 2023
3e1f654
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Dec 14, 2023
c1f3714
Add resource issue on the comment in test files.
Samir-Cit Dec 15, 2023
414bd3f
Merge branch 'master' into fix/ip-allocation
daniel-cit Dec 16, 2023
041207b
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Dec 18, 2023
ad406d5
Merge branch 'master' into fix/ip-allocation
daniel-cit Dec 20, 2023
98ff156
Merge branch 'master' into fix/ip-allocation
daniel-cit Dec 20, 2023
fae02b2
Retry policy for TagValue error
Samir-Cit Dec 20, 2023
92d7594
Merge remote-tracking branch 'origin/master' into fix/ip-allocation
Samir-Cit Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 0-bootstrap/terraform.example.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default_region = "us-central1"
# gcp_audit_viewer = "[email protected]"
# }
# }
#



/* ----------------------------------------
Expand Down
35 changes: 22 additions & 13 deletions 3-networks-dual-svpc/envs/development/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,48 @@ locals {
/*
* Base network ranges
*/
base_private_service_cidr = "10.16.64.0/21"
base_private_service_cidr = "10.16.8.0/21"
base_subnet_primary_ranges = {
(local.default_region1) = "10.0.64.0/21"
(local.default_region2) = "10.1.64.0/21"
(local.default_region1) = "10.0.64.0/18"
(local.default_region2) = "10.1.64.0/18"
}
base_subnet_proxy_ranges = {
(local.default_region1) = "10.18.2.0/23"
(local.default_region2) = "10.19.2.0/23"
}
base_subnet_secondary_ranges = {
(local.default_region1) = [
{
range_name = "rn-${local.environment_code}-shared-base-${local.default_region1}-gke-pod"
ip_cidr_range = "100.64.64.0/21"
ip_cidr_range = "100.64.64.0/18"
},
{
range_name = "rn-${local.environment_code}-shared-base-${local.default_region1}-gke-svc"
ip_cidr_range = "100.64.72.0/21"
ip_cidr_range = "100.65.64.0/18"
}
]
}
/*
* Restricted network ranges
*/
restricted_private_service_cidr = "10.24.64.0/21"
restricted_private_service_cidr = "10.16.40.0/21"
restricted_subnet_primary_ranges = {
(local.default_region1) = "10.8.64.0/21"
(local.default_region2) = "10.9.64.0/21"
(local.default_region1) = "10.8.64.0/18"
(local.default_region2) = "10.9.64.0/18"
}
restricted_subnet_proxy_ranges = {
(local.default_region1) = "10.26.2.0/23"
(local.default_region2) = "10.27.2.0/23"
}
restricted_subnet_secondary_ranges = {
(local.default_region1) = [
{
range_name = "rn-${local.environment_code}-shared-restricted-${local.default_region1}-gke-pod"
ip_cidr_range = "100.72.64.0/21"
ip_cidr_range = "100.72.64.0/18"
},
{
range_name = "rn-${local.environment_code}-shared-restricted-${local.default_region1}-gke-svc"
ip_cidr_range = "100.72.72.0/21"
ip_cidr_range = "100.73.64.0/18"
}
]
}
Expand All @@ -76,13 +84,14 @@ module "base_env" {
enable_partner_interconnect = false
base_private_service_cidr = local.base_private_service_cidr
base_subnet_primary_ranges = local.base_subnet_primary_ranges
base_subnet_proxy_ranges = local.base_subnet_proxy_ranges
base_subnet_secondary_ranges = local.base_subnet_secondary_ranges
base_private_service_connect_ip = "10.2.64.5"
base_private_service_connect_ip = "10.17.0.2"
restricted_private_service_cidr = local.restricted_private_service_cidr
restricted_subnet_primary_ranges = local.restricted_subnet_primary_ranges
restricted_subnet_proxy_ranges = local.restricted_subnet_proxy_ranges
restricted_subnet_secondary_ranges = local.restricted_subnet_secondary_ranges
restricted_private_service_connect_ip = "10.10.64.5"
restricted_private_service_connect_ip = "10.17.0.6"
remote_state_bucket = var.remote_state_bucket
tfc_org_name = var.tfc_org_name

}
34 changes: 22 additions & 12 deletions 3-networks-dual-svpc/envs/non-production/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,48 @@ locals {
/*
* Base network ranges
*/
base_private_service_cidr = "10.16.128.0/21"
base_private_service_cidr = "10.16.16.0/21"
base_subnet_primary_ranges = {
(local.default_region1) = "10.0.128.0/21"
(local.default_region2) = "10.1.128.0/21"
(local.default_region1) = "10.0.128.0/18"
(local.default_region2) = "10.1.128.0/18"
}
base_subnet_proxy_ranges = {
(local.default_region1) = "10.18.4.0/23"
(local.default_region2) = "10.19.4.0/23"
}
base_subnet_secondary_ranges = {
(local.default_region1) = [
{
range_name = "rn-${local.environment_code}-shared-base-${local.default_region1}-gke-pod"
ip_cidr_range = "100.64.128.0/21"
ip_cidr_range = "100.64.128.0/18"
},
{
range_name = "rn-${local.environment_code}-shared-base-${local.default_region1}-gke-svc"
ip_cidr_range = "100.64.136.0/21"
ip_cidr_range = "100.65.128.0/18"
}
]
}
/*
* Restricted network ranges
*/
restricted_private_service_cidr = "10.24.128.0/21"
restricted_private_service_cidr = "10.16.48.0/21"
restricted_subnet_primary_ranges = {
(local.default_region1) = "10.8.128.0/21"
(local.default_region2) = "10.9.128.0/21"
(local.default_region1) = "10.8.128.0/18"
(local.default_region2) = "10.9.128.0/18"
}
restricted_subnet_proxy_ranges = {
(local.default_region1) = "10.26.4.0/23"
(local.default_region2) = "10.27.4.0/23"
}
restricted_subnet_secondary_ranges = {
(local.default_region1) = [
{
range_name = "rn-${local.environment_code}-shared-restricted-${local.default_region1}-gke-pod"
ip_cidr_range = "100.72.128.0/21"
ip_cidr_range = "100.72.128.0/18"
},
{
range_name = "rn-${local.environment_code}-shared-restricted-${local.default_region1}-gke-svc"
ip_cidr_range = "100.72.136.0/21"
Samir-Cit marked this conversation as resolved.
Show resolved Hide resolved
ip_cidr_range = "100.73.128.0/18"
}
]
}
Expand All @@ -76,12 +84,14 @@ module "base_env" {
enable_partner_interconnect = false
base_private_service_cidr = local.base_private_service_cidr
base_subnet_primary_ranges = local.base_subnet_primary_ranges
base_subnet_proxy_ranges = local.base_subnet_proxy_ranges
base_subnet_secondary_ranges = local.base_subnet_secondary_ranges
base_private_service_connect_ip = "10.2.128.5"
base_private_service_connect_ip = "10.17.0.3"
restricted_private_service_cidr = local.restricted_private_service_cidr
restricted_subnet_proxy_ranges = local.restricted_subnet_proxy_ranges
restricted_subnet_primary_ranges = local.restricted_subnet_primary_ranges
restricted_subnet_secondary_ranges = local.restricted_subnet_secondary_ranges
restricted_private_service_connect_ip = "10.10.128.5"
restricted_private_service_connect_ip = "10.17.0.7"
remote_state_bucket = var.remote_state_bucket
tfc_org_name = var.tfc_org_name
}
34 changes: 22 additions & 12 deletions 3-networks-dual-svpc/envs/production/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,48 @@ locals {
/*
* Base network ranges
*/
base_private_service_cidr = "10.16.192.0/21"
base_private_service_cidr = "10.16.24.0/21"
base_subnet_primary_ranges = {
(local.default_region1) = "10.0.192.0/21"
(local.default_region2) = "10.1.192.0/21"
(local.default_region1) = "10.0.192.0/18"
(local.default_region2) = "10.1.192.0/18"
}
base_subnet_proxy_ranges = {
(local.default_region1) = "10.18.6.0/23"
(local.default_region2) = "10.19.6.0/23"
}
base_subnet_secondary_ranges = {
(local.default_region1) = [
{
range_name = "rn-${local.environment_code}-shared-base-${local.default_region1}-gke-pod"
ip_cidr_range = "100.64.192.0/21"
ip_cidr_range = "100.64.192.0/18"
},
{
range_name = "rn-${local.environment_code}-shared-base-${local.default_region1}-gke-svc"
ip_cidr_range = "100.64.200.0/21"
ip_cidr_range = "100.65.192.0/18"
}
]
}
/*
* Restricted network ranges
*/
restricted_private_service_cidr = "10.24.192.0/21"
restricted_private_service_cidr = "10.16.56.0/21"
restricted_subnet_primary_ranges = {
(local.default_region1) = "10.8.192.0/21"
(local.default_region2) = "10.9.192.0/21"
(local.default_region1) = "10.8.192.0/18"
(local.default_region2) = "10.9.192.0/18"
}
restricted_subnet_proxy_ranges = {
(local.default_region1) = "10.26.6.0/23"
(local.default_region2) = "10.27.6.0/23"
}
restricted_subnet_secondary_ranges = {
(local.default_region1) = [
{
range_name = "rn-${local.environment_code}-shared-restricted-${local.default_region1}-gke-pod"
ip_cidr_range = "100.72.192.0/21"
ip_cidr_range = "100.72.192.0/18"
},
{
range_name = "rn-${local.environment_code}-shared-restricted-${local.default_region1}-gke-svc"
ip_cidr_range = "100.72.200.0/21"
ip_cidr_range = "100.73.192.0/18"
}
]
}
Expand All @@ -76,12 +84,14 @@ module "base_env" {
enable_partner_interconnect = false
base_private_service_cidr = local.base_private_service_cidr
base_subnet_primary_ranges = local.base_subnet_primary_ranges
base_subnet_proxy_ranges = local.base_subnet_proxy_ranges
base_subnet_secondary_ranges = local.base_subnet_secondary_ranges
base_private_service_connect_ip = "10.2.192.5"
base_private_service_connect_ip = "10.17.0.4"
restricted_private_service_cidr = local.restricted_private_service_cidr
restricted_subnet_primary_ranges = local.restricted_subnet_primary_ranges
restricted_subnet_proxy_ranges = local.restricted_subnet_proxy_ranges
restricted_subnet_secondary_ranges = local.restricted_subnet_secondary_ranges
restricted_private_service_connect_ip = "10.10.192.5"
restricted_private_service_connect_ip = "10.17.0.8"
remote_state_bucket = var.remote_state_bucket
tfc_org_name = var.tfc_org_name
}
2 changes: 2 additions & 0 deletions 3-networks-dual-svpc/modules/base_env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| base\_private\_service\_cidr | CIDR range for private service networking. Used for Cloud SQL and other managed services in the Base Shared Vpc. | `string` | n/a | yes |
| base\_private\_service\_connect\_ip | The base subnet internal IP to be used as the private service connect endpoint in the Base Shared VPC | `string` | n/a | yes |
| base\_subnet\_primary\_ranges | The base subnet primary IPTs ranges to the Base Shared Vpc. | `map(string)` | n/a | yes |
| base\_subnet\_proxy\_ranges | The base proxy-only subnet primary IPTs ranges to the Base Shared Vpc. | `map(string)` | n/a | yes |
| base\_subnet\_secondary\_ranges | The base subnet secondary IPTs ranges to the Base Shared Vpc. | `map(list(map(string)))` | n/a | yes |
| base\_vpc\_flow\_logs | aggregation\_interval: Toggles the aggregation interval for collecting flow logs. Increasing the interval time will reduce the amount of generated flow logs for long lasting connections. Possible values are: INTERVAL\_5\_SEC, INTERVAL\_30\_SEC, INTERVAL\_1\_MIN, INTERVAL\_5\_MIN, INTERVAL\_10\_MIN, INTERVAL\_15\_MIN.<br> flow\_sampling: Set the sampling rate of VPC flow logs within the subnetwork where 1.0 means all collected logs are reported and 0.0 means no logs are reported. The value of the field must be in [0, 1].<br> metadata: Configures whether metadata fields should be added to the reported VPC flow logs. Possible values are: EXCLUDE\_ALL\_METADATA, INCLUDE\_ALL\_METADATA, CUSTOM\_METADATA.<br> metadata\_fields: ist of metadata fields that should be added to reported logs. Can only be specified if VPC flow logs for this subnetwork is enabled and "metadata" is set to CUSTOM\_METADATA.<br> filter\_expr: Export filter used to define which VPC flow logs should be logged, as as CEL expression. See https://cloud.google.com/vpc/docs/flow-logs#filtering for details on how to format this field. | <pre>object({<br> aggregation_interval = optional(string, "INTERVAL_5_SEC")<br> flow_sampling = optional(string, "0.5")<br> metadata = optional(string, "INCLUDE_ALL_METADATA")<br> metadata_fields = optional(list(string), [])<br> filter_expr = optional(string, "true")<br> })</pre> | `{}` | no |
| custom\_restricted\_services | List of custom services to be protected by the VPC-SC perimeter. If empty, all supported services (https://cloud.google.com/vpc-service-controls/docs/supported-products) will be protected. | `list(string)` | `[]` | no |
Expand All @@ -24,6 +25,7 @@
| restricted\_private\_service\_cidr | CIDR range for private service networking. Used for Cloud SQL and other managed services in the Restricted Shared Vpc. | `string` | n/a | yes |
| restricted\_private\_service\_connect\_ip | The base subnet internal IP to be used as the private service connect endpoint in the Restricted Shared VPC | `string` | n/a | yes |
| restricted\_subnet\_primary\_ranges | The base subnet primary IPTs ranges to the Restricted Shared Vpc. | `map(string)` | n/a | yes |
| restricted\_subnet\_proxy\_ranges | The base proxy-only subnet primary IPTs ranges to the Restricted Shared Vpc. | `map(string)` | n/a | yes |
| restricted\_subnet\_secondary\_ranges | The base subnet secondary IPTs ranges to the Restricted Shared Vpc | `map(list(map(string)))` | n/a | yes |
| restricted\_vpc\_flow\_logs | aggregation\_interval: Toggles the aggregation interval for collecting flow logs. Increasing the interval time will reduce the amount of generated flow logs for long lasting connections. Possible values are: INTERVAL\_5\_SEC, INTERVAL\_30\_SEC, INTERVAL\_1\_MIN, INTERVAL\_5\_MIN, INTERVAL\_10\_MIN, INTERVAL\_15\_MIN.<br> flow\_sampling: Set the sampling rate of VPC flow logs within the subnetwork where 1.0 means all collected logs are reported and 0.0 means no logs are reported. The value of the field must be in [0, 1].<br> metadata: Configures whether metadata fields should be added to the reported VPC flow logs. Possible values are: EXCLUDE\_ALL\_METADATA, INCLUDE\_ALL\_METADATA, CUSTOM\_METADATA.<br> metadata\_fields: ist of metadata fields that should be added to reported logs. Can only be specified if VPC flow logs for this subnetwork is enabled and "metadata" is set to CUSTOM\_METADATA.<br> filter\_expr: Export filter used to define which VPC flow logs should be logged, as as CEL expression. See https://cloud.google.com/vpc/docs/flow-logs#filtering for details on how to format this field. | <pre>object({<br> aggregation_interval = optional(string, "INTERVAL_5_SEC")<br> flow_sampling = optional(string, "0.5")<br> metadata = optional(string, "INCLUDE_ALL_METADATA")<br> metadata_fields = optional(list(string), [])<br> filter_expr = optional(string, "true")<br> })</pre> | `{}` | no |
| tfc\_org\_name | Name of the TFC organization | `string` | n/a | yes |
Expand Down
37 changes: 37 additions & 0 deletions 3-networks-dual-svpc/modules/base_env/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ module "restricted_shared_vpc" {
subnet_flow_logs_metadata_fields = var.restricted_vpc_flow_logs.metadata_fields
subnet_flow_logs_filter = var.restricted_vpc_flow_logs.filter_expr
description = "Second ${var.env} subnet example."
},
{
subnet_name = "sb-${var.environment_code}-shared-restricted-${var.default_region1}-proxy"
subnet_ip = var.restricted_subnet_proxy_ranges[var.default_region1]
subnet_region = var.default_region1
subnet_flow_logs = false
description = "First ${var.env} proxy-only subnet example."
role = "ACTIVE"
purpose = "REGIONAL_MANAGED_PROXY"
},
{
subnet_name = "sb-${var.environment_code}-shared-restricted-${var.default_region2}-proxy"
subnet_ip = var.restricted_subnet_proxy_ranges[var.default_region2]
subnet_region = var.default_region2
subnet_flow_logs = false
description = "Second ${var.env} proxy-only subnet example."
role = "ACTIVE"
purpose = "REGIONAL_MANAGED_PROXY"
}
]
secondary_ranges = {
Expand Down Expand Up @@ -270,8 +288,27 @@ module "base_shared_vpc" {
subnet_flow_logs_metadata_fields = var.base_vpc_flow_logs.metadata_fields
subnet_flow_logs_filter = var.base_vpc_flow_logs.filter_expr
description = "Second ${var.env} subnet example."
},
{
subnet_name = "sb-${var.environment_code}-shared-base-${var.default_region1}-proxy"
subnet_ip = var.base_subnet_proxy_ranges[var.default_region1]
subnet_region = var.default_region1
subnet_flow_logs = false
description = "First ${var.env} proxy-only subnet example."
role = "ACTIVE"
purpose = "REGIONAL_MANAGED_PROXY"
},
{
subnet_name = "sb-${var.environment_code}-shared-base-${var.default_region2}-proxy"
subnet_ip = var.base_subnet_proxy_ranges[var.default_region2]
subnet_region = var.default_region2
subnet_flow_logs = false
description = "Second ${var.env} proxy-only subnet example."
role = "ACTIVE"
purpose = "REGIONAL_MANAGED_PROXY"
}
]

secondary_ranges = {
"sb-${var.environment_code}-shared-base-${var.default_region1}" = var.base_subnet_secondary_ranges[var.default_region1]
}
Expand Down
10 changes: 10 additions & 0 deletions 3-networks-dual-svpc/modules/base_env/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ variable "base_subnet_primary_ranges" {
description = "The base subnet primary IPTs ranges to the Base Shared Vpc."
}

variable "base_subnet_proxy_ranges" {
type = map(string)
description = "The base proxy-only subnet primary IPTs ranges to the Base Shared Vpc."
}

variable "base_subnet_secondary_ranges" {
type = map(list(map(string)))
description = "The base subnet secondary IPTs ranges to the Base Shared Vpc."
Expand Down Expand Up @@ -109,6 +114,11 @@ variable "restricted_subnet_primary_ranges" {
description = "The base subnet primary IPTs ranges to the Restricted Shared Vpc."
}

variable "restricted_subnet_proxy_ranges" {
type = map(string)
description = "The base proxy-only subnet primary IPTs ranges to the Restricted Shared Vpc."
}

variable "restricted_subnet_secondary_ranges" {
type = map(list(map(string)))
description = "The base subnet secondary IPTs ranges to the Restricted Shared Vpc"
Expand Down
Loading