You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
Additional information
No response
The text was updated successfully, but these errors were encountered: