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

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

Open
nemethloci opened this issue Jan 16, 2025 · 0 comments
Open

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

nemethloci opened this issue Jan 16, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@nemethloci
Copy link

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

@nemethloci nemethloci added the enhancement New feature or request label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant