» google_compute_network_peering_routes_config

Manage a network peering's route settings without managing the peering as a whole. This resource is primarily intended for use with GCP-generated peerings that shouldn't otherwise be managed by other tools. Deleting this resource is a no-op and the peering will not be modified.

To get more information about NetworkPeeringRoutesConfig, see:

» Example Usage - Network Peering Routes Config Basic

resource "google_compute_network_peering_routes_config" "peering_primary_routes" {
  peering = google_compute_network_peering.peering_primary.name
  network = google_compute_network.network_primary.name

  import_custom_routes = true
  export_custom_routes = true
}

resource "google_compute_network_peering" "peering_primary" {
  name         = "primary-peering"
  network      = google_compute_network.network_primary.id
  peer_network = google_compute_network.network_secondary.id

  import_custom_routes = true
  export_custom_routes = true
}

resource "google_compute_network_peering" "peering_secondary" {
  name         = "secondary-peering"
  network      = google_compute_network.network_secondary.id
  peer_network = google_compute_network.network_primary.id
}

resource "google_compute_network" "network_primary" {
  name                    = "primary-network"
  auto_create_subnetworks = "false"
}

resource "google_compute_network" "network_secondary" {
  name                    = "secondary-network"
  auto_create_subnetworks = "false"
}

» Example Usage - Network Peering Routes Config Gke

resource "google_compute_network_peering_routes_config" "peering_gke_routes" {
  peering = google_container_cluster.private_cluster.private_cluster_config[0].peering_name
  network = google_compute_network.container_network.name

  import_custom_routes = true
  export_custom_routes = true
}

resource "google_compute_network" "container_network" {
  name                    = "container-network"
  auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "container_subnetwork" {
  name                     = "container-subnetwork"
  region                   = "us-central1"
  network                  = google_compute_network.container_network.name
  ip_cidr_range            = "10.0.36.0/24"
  private_ip_google_access = true

  secondary_ip_range {
    range_name    = "pod"
    ip_cidr_range = "10.0.0.0/19"
  }

  secondary_ip_range {
    range_name    = "svc"
    ip_cidr_range = "10.0.32.0/22"
  }
}

resource "google_container_cluster" "private_cluster" {
  name               = "private-cluster"
  location           = "us-central1-a"
  initial_node_count = 1

  network    = google_compute_network.container_network.name
  subnetwork = google_compute_subnetwork.container_subnetwork.name

  private_cluster_config {
    enable_private_endpoint = true
    enable_private_nodes    = true
    master_ipv4_cidr_block  = "10.42.0.0/28"
  }

  master_authorized_networks_config {}

  ip_allocation_policy {
    cluster_secondary_range_name  = google_compute_subnetwork.container_subnetwork.secondary_ip_range[0].range_name
    services_secondary_range_name = google_compute_subnetwork.container_subnetwork.secondary_ip_range[1].range_name
  }
}

» Argument Reference

The following arguments are supported:

  • peering - (Required) Name of the peering.

  • export_custom_routes - (Required) Whether to export the custom routes to the peer network.

  • import_custom_routes - (Required) Whether to import the custom routes to the peer network.

  • network - (Required) The name of the primary network for the peering.


  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

» Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format projects/{{project}}/global/networks/{{network}}/networkPeerings/{{peering}}

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 6 minutes.
  • update - Default is 6 minutes.
  • delete - Default is 6 minutes.

» Import

NetworkPeeringRoutesConfig can be imported using any of these accepted formats:

$ terraform import google_compute_network_peering_routes_config.default projects/{{project}}/global/networks/{{network}}/networkPeerings/{{peering}}
$ terraform import google_compute_network_peering_routes_config.default {{project}}/{{network}}/{{peering}}
$ terraform import google_compute_network_peering_routes_config.default {{network}}/{{peering}}

» User Project Overrides

This resource supports User Project Overrides.