I am trying to set-up a peering connection between 2 VPC networks.
One network (the transit one) configures static routes, and I would like to have those propagated to the peered network.
Here's an example:
...
data "google_compute_network" "transit-network" {
project = var.transit_project_id
name = var.transit_network
}
resource "google_compute_network_peering" "to-transit" {
name = "${var.project}-transit"
network = "${google_compute_network.vpc_network.self_link}"
peer_network = data.google_compute_network.transit-network.self_link
}
resource "google_compute_network_peering" "from-transit" {
name = "transit-${var.project}"
network = data.google_compute_network.transit-network.self_link
peer_network = "${google_compute_network.vpc_network.self_link}"
}
...
I know that this is simply through the GCP console, but, I can't find a way to do it through terraform.
From the API it seems that is by using the field peering.exchangeSubnetRoutes
EDIT:
I have found the solution using the google-beta
provider:
resource "google_compute_network_peering" "to-transit" {
name = "${var.project}-transit"
provider = "google-beta"
network = "${google_compute_network.vpc_network.self_link}"
peer_network = data.google_compute_network.transit-network.self_link
import_custom_routes = true
}
resource "google_compute_network_peering" "from-transit" {
name = "transit-${var.project}"
provider = "google-beta"
network = data.google_compute_network.transit-network.self_link
peer_network = "${google_compute_network.vpc_network.self_link}"
export_custom_routes = true
}
Using the beta
provider I can specify import_custom_routes
and export_custom_routes