Skip to content

Support for asymmetric (local -> peer) peerings #589

@nemethloci

Description

@nemethloci

TL;DR

Sometimes VPC peerings are created between VPC, that belong to different organization and as such it's not possible for either party to provision both direction of the peerings. In such cases each party needs to provision only one direction. While this can be easily achieved by not using the peering submodule, just by using the peering resource directly, for unified mgmt IMHO it would make sense to add support this scenario also via the module.

Terraform Resources

Detailed design

My initial idea is to add a single "local_only" boolean type variable, and make the peer -> local peering resources conditional on it. Here's a simple implementation of the idea. Please let me know if you could accept this and I can create a PR.


diff --git a/modules/network-peering/main.tf b/modules/network-peering/main.tf
index ec55515..035cb89 100644
--- a/modules/network-peering/main.tf
+++ b/modules/network-peering/main.tf
@@ -48,6 +48,7 @@ resource "google_compute_network_peering" "local_network_peering" {
 }
 
 resource "google_compute_network_peering" "peer_network_peering" {
+  count = var.local_only ? 0 : 1
   provider             = google-beta
   name                 = local.peer_network_peering_name
   network              = var.peer_network
@@ -63,6 +64,11 @@ resource "google_compute_network_peering" "peer_network_peering" {
   depends_on = [null_resource.module_depends_on, google_compute_network_peering.local_network_peering]
 }
 
+moved {
+  from = google_compute_network_peering.peer_network_peering
+  to = google_compute_network_peering.peer_network_peering[0]
+}
+
 resource "null_resource" "module_depends_on" {
   triggers = {
     value = length(var.module_depends_on)
diff --git a/modules/network-peering/variables.tf b/modules/network-peering/variables.tf
index c3e25bb..3f0ce50 100644
--- a/modules/network-peering/variables.tf
+++ b/modules/network-peering/variables.tf
@@ -65,3 +65,9 @@ variable "stack_type" {
   type        = string
   default     = "IPV4_ONLY"
 }
+
+variable "local_only" {
+  description = "If to provision also the remote -> local peering direction or only the local -> remote"
+  type        = bool
+  default     = false
+}

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions