google_network_connectivity_policy_based_route

Policy-based Routes are more powerful routes that route L4 network traffic based on not just destination IP, but also source IP, protocol and more. A Policy-based Route always take precedence when it conflicts with other types of routes.

To get more information about PolicyBasedRoute, see:

Open in Cloud Shell

Example Usage - Network Connectivity Policy Based Route Basic

resource "google_network_connectivity_policy_based_route" "default" {
  name = "my-pbr"
  network = google_compute_network.my_network.id
  filter {
    protocol_version = "IPV4"
  }
  next_hop_other_routes = "DEFAULT_ROUTING"
}

resource "google_compute_network" "my_network" {
  name                    = "my-network"
  auto_create_subnetworks = false
}
Open in Cloud Shell

Example Usage - Network Connectivity Policy Based Route Full

resource "google_network_connectivity_policy_based_route" "default" {
  name = "my-pbr"
  description = "My routing policy"
  network = google_compute_network.my_network.id
  priority = 2302

  filter {
    protocol_version = "IPV4"
    ip_protocol = "UDP"
    src_range = "10.0.0.0/24"
    dest_range = "0.0.0.0/0"
  }
  next_hop_ilb_ip = google_compute_global_address.ilb.address

  virtual_machine {
    tags = ["restricted"]
  }

  labels = {
    env = "default"
  }
}

resource "google_compute_network" "my_network" {
  name                    = "my-network"
  auto_create_subnetworks = false
}

# This example substitutes an arbitrary internal IP for an internal network
# load balancer for brevity. Consult https://cloud.google.com/load-balancing/docs/internal
# to set one up.
resource "google_compute_global_address" "ilb" {
  name = "my-ilb"
}

Argument Reference

The following arguments are supported:

The filter block supports:


The virtual_machine block supports:

The interconnect_attachment block supports:

Attributes Reference

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

The warnings block contains:

Timeouts

This resource provides the following Timeouts configuration options:

Import

PolicyBasedRoute can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import PolicyBasedRoute using one of the formats above. For example:

import {
  id = "projects/{{project}}/locations/global/policyBasedRoutes/{{name}}"
  to = google_network_connectivity_policy_based_route.default
}

When using the terraform import command, PolicyBasedRoute can be imported using one of the formats above. For example:

$ terraform import google_network_connectivity_policy_based_route.default projects/{{project}}/locations/global/policyBasedRoutes/{{name}}
$ terraform import google_network_connectivity_policy_based_route.default {{project}}/{{name}}
$ terraform import google_network_connectivity_policy_based_route.default {{name}}

User Project Overrides

This resource supports User Project Overrides.