From b9e7f02dab3380b1d8b0f4050b8d56307b247bba Mon Sep 17 00:00:00 2001 From: "Glenn, Robert" Date: Tue, 16 Feb 2021 19:07:21 -0500 Subject: [PATCH 1/2] introducing variables to allow subnet routes with public IP range to be imported/exported --- modules/network-peering/README.md | 2 ++ modules/network-peering/main.tf | 6 ++++++ modules/network-peering/variables.tf | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/modules/network-peering/README.md b/modules/network-peering/README.md index 2c2c3900..0207e425 100644 --- a/modules/network-peering/README.md +++ b/modules/network-peering/README.md @@ -49,7 +49,9 @@ module "peering-a-c" { | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | export\_local\_custom\_routes | Export custom routes to peer network from local network. | `bool` | `false` | no | +| export\_local\_public\_ip\_subnet\_routes | Export custom routes to peer network from local network. | `bool` | `false` | no | | export\_peer\_custom\_routes | Export custom routes to local network from peer network. | `bool` | `false` | no | +| export\_peer\_public\_ip\_subnet\_routes | Export custom routes to local network from peer network. | `bool` | `false` | no | | local\_network | Resource link of the network to add a peering to. | `string` | n/a | yes | | module\_depends\_on | List of modules or resources this module depends on. | `list(any)` | `[]` | no | | peer\_network | Resource link of the peer network. | `string` | n/a | yes | diff --git a/modules/network-peering/main.tf b/modules/network-peering/main.tf index d352798f..6939333f 100644 --- a/modules/network-peering/main.tf +++ b/modules/network-peering/main.tf @@ -38,6 +38,9 @@ resource "google_compute_network_peering" "local_network_peering" { export_custom_routes = var.export_local_custom_routes import_custom_routes = var.export_peer_custom_routes + export_subnet_routes_with_public_ip = var.export_local_public_ip_subnet_routes + import_subnet_routes_with_public_ip = var.export_peer_public_ip_subnet_routes + depends_on = [null_resource.module_depends_on] } @@ -49,6 +52,9 @@ resource "google_compute_network_peering" "peer_network_peering" { export_custom_routes = var.export_peer_custom_routes import_custom_routes = var.export_local_custom_routes + export_subnet_routes_with_public_ip = var.export_peer_public_ip_subnet_routes + import_subnet_routes_with_public_ip = var.export_local_public_ip_subnet_routes + depends_on = [null_resource.module_depends_on, google_compute_network_peering.local_network_peering] } diff --git a/modules/network-peering/variables.tf b/modules/network-peering/variables.tf index 087d20cb..f3be4fed 100644 --- a/modules/network-peering/variables.tf +++ b/modules/network-peering/variables.tf @@ -42,6 +42,18 @@ variable "export_local_custom_routes" { default = false } +variable "export_peer_public_ip_subnet_routes" { + description = "Export custom routes to local network from peer network." + type = bool + default = false +} + +variable "export_local_public_ip_subnet_routes" { + description = "Export custom routes to peer network from local network." + type = bool + default = false +} + variable "module_depends_on" { description = "List of modules or resources this module depends on." type = list(any) From f96d19c5bee4a36e948f64c90b1e3387133eb317 Mon Sep 17 00:00:00 2001 From: "Glenn, Robert" Date: Thu, 4 Mar 2021 15:02:00 -0500 Subject: [PATCH 2/2] updating to have the Local side of the connection match the provider defaults --- modules/network-peering/README.md | 4 ++-- modules/network-peering/main.tf | 9 +++++---- modules/network-peering/variables.tf | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/network-peering/README.md b/modules/network-peering/README.md index 0207e425..ca95ffe8 100644 --- a/modules/network-peering/README.md +++ b/modules/network-peering/README.md @@ -49,9 +49,9 @@ module "peering-a-c" { | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | export\_local\_custom\_routes | Export custom routes to peer network from local network. | `bool` | `false` | no | -| export\_local\_public\_ip\_subnet\_routes | Export custom routes to peer network from local network. | `bool` | `false` | no | +| export\_local\_subnet\_routes\_with\_public\_ip | Export custom routes to peer network from local network (defaults to true; causes the Local Peering Connection to align with the [provider default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network_peering#export_subnet_routes_with_public_ip), and the Remote Peering Connection to be opposite the provider default). | `bool` | `true` | no | | export\_peer\_custom\_routes | Export custom routes to local network from peer network. | `bool` | `false` | no | -| export\_peer\_public\_ip\_subnet\_routes | Export custom routes to local network from peer network. | `bool` | `false` | no | +| export\_peer\_subnet\_routes\_with\_public\_ip | Export custom routes to local network from peer network (defaults to false; causes the Local Peering Connection to align with the [provider default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network_peering#import_subnet_routes_with_public_ip), and the Remote Peering Connection to be opposite the provider default). | `bool` | `false` | no | | local\_network | Resource link of the network to add a peering to. | `string` | n/a | yes | | module\_depends\_on | List of modules or resources this module depends on. | `list(any)` | `[]` | no | | peer\_network | Resource link of the peer network. | `string` | n/a | yes | diff --git a/modules/network-peering/main.tf b/modules/network-peering/main.tf index 6939333f..7fb49f80 100644 --- a/modules/network-peering/main.tf +++ b/modules/network-peering/main.tf @@ -30,6 +30,7 @@ resource "random_string" "network_peering_suffix" { special = false length = 4 } + resource "google_compute_network_peering" "local_network_peering" { provider = google-beta name = local.local_network_peering_name @@ -38,8 +39,8 @@ resource "google_compute_network_peering" "local_network_peering" { export_custom_routes = var.export_local_custom_routes import_custom_routes = var.export_peer_custom_routes - export_subnet_routes_with_public_ip = var.export_local_public_ip_subnet_routes - import_subnet_routes_with_public_ip = var.export_peer_public_ip_subnet_routes + export_subnet_routes_with_public_ip = var.export_local_subnet_routes_with_public_ip + import_subnet_routes_with_public_ip = var.export_peer_subnet_routes_with_public_ip depends_on = [null_resource.module_depends_on] } @@ -52,8 +53,8 @@ resource "google_compute_network_peering" "peer_network_peering" { export_custom_routes = var.export_peer_custom_routes import_custom_routes = var.export_local_custom_routes - export_subnet_routes_with_public_ip = var.export_peer_public_ip_subnet_routes - import_subnet_routes_with_public_ip = var.export_local_public_ip_subnet_routes + export_subnet_routes_with_public_ip = var.export_peer_subnet_routes_with_public_ip + import_subnet_routes_with_public_ip = var.export_local_subnet_routes_with_public_ip depends_on = [null_resource.module_depends_on, google_compute_network_peering.local_network_peering] } diff --git a/modules/network-peering/variables.tf b/modules/network-peering/variables.tf index f3be4fed..c4b7409d 100644 --- a/modules/network-peering/variables.tf +++ b/modules/network-peering/variables.tf @@ -42,16 +42,16 @@ variable "export_local_custom_routes" { default = false } -variable "export_peer_public_ip_subnet_routes" { - description = "Export custom routes to local network from peer network." +variable "export_peer_subnet_routes_with_public_ip" { + description = "Export custom routes to local network from peer network (defaults to false; causes the Local Peering Connection to align with the [provider default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network_peering#import_subnet_routes_with_public_ip), and the Remote Peering Connection to be opposite the provider default)." type = bool default = false } -variable "export_local_public_ip_subnet_routes" { - description = "Export custom routes to peer network from local network." +variable "export_local_subnet_routes_with_public_ip" { + description = "Export custom routes to peer network from local network (defaults to true; causes the Local Peering Connection to align with the [provider default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_network_peering#export_subnet_routes_with_public_ip), and the Remote Peering Connection to be opposite the provider default)." type = bool - default = false + default = true } variable "module_depends_on" {