PolicyBasedRoute class
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:
- API documentation
- How-to Guides
- Use policy-based routes
Example Usage
Network Connectivity Policy Based Route Basic
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const myNetwork = new gcp.compute.Network("my_network", {
name: "my-network",
autoCreateSubnetworks: false,
});
const _default = new gcp.networkconnectivity.PolicyBasedRoute("default", {
name: "my-pbr",
network: myNetwork.id,
filter: {
protocolVersion: "IPV4",
},
nextHopOtherRoutes: "DEFAULT_ROUTING",
});
import pulumi
import pulumi_gcp as gcp
my_network = gcp.compute.Network("my_network",
name="my-network",
auto_create_subnetworks=False)
default = gcp.networkconnectivity.PolicyBasedRoute("default",
name="my-pbr",
network=my_network.id,
filter={
"protocol_version": "IPV4",
},
next_hop_other_routes="DEFAULT_ROUTING")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var myNetwork = new Gcp.Compute.Network("my_network", new()
{
Name = "my-network",
AutoCreateSubnetworks = false,
});
var @default = new Gcp.NetworkConnectivity.PolicyBasedRoute("default", new()
{
Name = "my-pbr",
Network = myNetwork.Id,
Filter = new Gcp.NetworkConnectivity.Inputs.PolicyBasedRouteFilterArgs
{
ProtocolVersion = "IPV4",
},
NextHopOtherRoutes = "DEFAULT_ROUTING",
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/networkconnectivity"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
myNetwork, err := compute.NewNetwork(ctx, "my_network", &compute.NetworkArgs{
Name: pulumi.String("my-network"),
AutoCreateSubnetworks: pulumi.Bool(false),
})
if err != nil {
return err
}
_, err = networkconnectivity.NewPolicyBasedRoute(ctx, "default", &networkconnectivity.PolicyBasedRouteArgs{
Name: pulumi.String("my-pbr"),
Network: myNetwork.ID().ToIDOutput().ToStringOutput(),
Filter: &networkconnectivity.PolicyBasedRouteFilterArgs{
ProtocolVersion: pulumi.String("IPV4"),
},
NextHopOtherRoutes: pulumi.String("DEFAULT_ROUTING"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
gcp = {
source = "pulumi/gcp"
}
}
}
resource "gcp_networkconnectivity_policybasedroute" "default" {
name = "my-pbr"
network = gcp_compute_network.my_network.id
filter = {
protocol_version = "IPV4"
}
next_hop_other_routes = "DEFAULT_ROUTING"
}
resource "gcp_compute_network" "my_network" {
name = "my-network"
auto_create_subnetworks = false
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.Network;
import com.pulumi.gcp.compute.NetworkArgs;
import com.pulumi.gcp.networkconnectivity.PolicyBasedRoute;
import com.pulumi.gcp.networkconnectivity.PolicyBasedRouteArgs;
import com.pulumi.gcp.networkconnectivity.inputs.PolicyBasedRouteFilterArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var myNetwork = new Network("myNetwork", NetworkArgs.builder()
.name("my-network")
.autoCreateSubnetworks(false)
.build());
var default_ = new PolicyBasedRoute("default", PolicyBasedRouteArgs.builder()
.name("my-pbr")
.network(myNetwork.id())
.filter(PolicyBasedRouteFilterArgs.builder()
.protocolVersion("IPV4")
.build())
.nextHopOtherRoutes("DEFAULT_ROUTING")
.build());
}
}
resources:
default:
type: gcp:networkconnectivity:PolicyBasedRoute
properties:
name: my-pbr
network: ${myNetwork.id}
filter:
protocolVersion: IPV4
nextHopOtherRoutes: DEFAULT_ROUTING
myNetwork:
type: gcp:compute:Network
name: my_network
properties:
name: my-network
autoCreateSubnetworks: false
Network Connectivity Policy Based Route Full
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const myNetwork = new gcp.compute.Network("my_network", {
name: "my-network",
autoCreateSubnetworks: 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.
const ilb = new gcp.compute.GlobalAddress("ilb", {name: "my-ilb"});
const _default = new gcp.networkconnectivity.PolicyBasedRoute("default", {
name: "my-pbr",
description: "My routing policy",
network: myNetwork.id,
priority: 2302,
filter: {
protocolVersion: "IPV4",
ipProtocol: "UDP",
srcRange: "10.0.0.0/24",
destRange: "0.0.0.0/0",
},
nextHopIlbIp: ilb.address,
virtualMachine: {
tags: ["restricted"],
},
labels: {
env: "default",
},
});
import pulumi
import pulumi_gcp as gcp
my_network = gcp.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.
ilb = gcp.compute.GlobalAddress("ilb", name="my-ilb")
default = gcp.networkconnectivity.PolicyBasedRoute("default",
name="my-pbr",
description="My routing policy",
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=ilb.address,
virtual_machine={
"tags": ["restricted"],
},
labels={
"env": "default",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var myNetwork = new Gcp.Compute.Network("my_network", new()
{
Name = "my-network",
AutoCreateSubnetworks = 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.
var ilb = new Gcp.Compute.GlobalAddress("ilb", new()
{
Name = "my-ilb",
});
var @default = new Gcp.NetworkConnectivity.PolicyBasedRoute("default", new()
{
Name = "my-pbr",
Description = "My routing policy",
Network = myNetwork.Id,
Priority = 2302,
Filter = new Gcp.NetworkConnectivity.Inputs.PolicyBasedRouteFilterArgs
{
ProtocolVersion = "IPV4",
IpProtocol = "UDP",
SrcRange = "10.0.0.0/24",
DestRange = "0.0.0.0/0",
},
NextHopIlbIp = ilb.Address,
VirtualMachine = new Gcp.NetworkConnectivity.Inputs.PolicyBasedRouteVirtualMachineArgs
{
Tags = new[]
{
"restricted",
},
},
Labels =
{
{ "env", "default" },
},
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/networkconnectivity"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
myNetwork, err := compute.NewNetwork(ctx, "my_network", &compute.NetworkArgs{
Name: pulumi.String("my-network"),
AutoCreateSubnetworks: pulumi.Bool(false),
})
if err != nil {
return err
}
// 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.
ilb, err := compute.NewGlobalAddress(ctx, "ilb", &compute.GlobalAddressArgs{
Name: pulumi.String("my-ilb"),
})
if err != nil {
return err
}
_, err = networkconnectivity.NewPolicyBasedRoute(ctx, "default", &networkconnectivity.PolicyBasedRouteArgs{
Name: pulumi.String("my-pbr"),
Description: pulumi.String("My routing policy"),
Network: myNetwork.ID().ToIDOutput().ToStringOutput(),
Priority: pulumi.Int(2302),
Filter: &networkconnectivity.PolicyBasedRouteFilterArgs{
ProtocolVersion: pulumi.String("IPV4"),
IpProtocol: pulumi.String("UDP"),
SrcRange: pulumi.String("10.0.0.0/24"),
DestRange: pulumi.String("0.0.0.0/0"),
},
NextHopIlbIp: ilb.Address,
VirtualMachine: &networkconnectivity.PolicyBasedRouteVirtualMachineArgs{
Tags: pulumi.StringArray{
pulumi.String("restricted"),
},
},
Labels: pulumi.StringMap{
"env": pulumi.String("default"),
},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
gcp = {
source = "pulumi/gcp"
}
}
}
resource "gcp_networkconnectivity_policybasedroute" "default" {
name = "my-pbr"
description = "My routing policy"
network = gcp_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 = gcp_compute_globaladdress.ilb.address
virtual_machine = {
tags = ["restricted"]
}
labels = {
"env" = "default"
}
}
resource "gcp_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 "gcp_compute_globaladdress" "ilb" {
name = "my-ilb"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.Network;
import com.pulumi.gcp.compute.NetworkArgs;
import com.pulumi.gcp.compute.GlobalAddress;
import com.pulumi.gcp.compute.GlobalAddressArgs;
import com.pulumi.gcp.networkconnectivity.PolicyBasedRoute;
import com.pulumi.gcp.networkconnectivity.PolicyBasedRouteArgs;
import com.pulumi.gcp.networkconnectivity.inputs.PolicyBasedRouteFilterArgs;
import com.pulumi.gcp.networkconnectivity.inputs.PolicyBasedRouteVirtualMachineArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var myNetwork = new Network("myNetwork", NetworkArgs.builder()
.name("my-network")
.autoCreateSubnetworks(false)
.build());
// 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.
var ilb = new GlobalAddress("ilb", GlobalAddressArgs.builder()
.name("my-ilb")
.build());
var default_ = new PolicyBasedRoute("default", PolicyBasedRouteArgs.builder()
.name("my-pbr")
.description("My routing policy")
.network(myNetwork.id())
.priority(2302)
.filter(PolicyBasedRouteFilterArgs.builder()
.protocolVersion("IPV4")
.ipProtocol("UDP")
.srcRange("10.0.0.0/24")
.destRange("0.0.0.0/0")
.build())
.nextHopIlbIp(ilb.address())
.virtualMachine(PolicyBasedRouteVirtualMachineArgs.builder()
.tags("restricted")
.build())
.labels(Map.of("env", "default"))
.build());
}
}
resources:
default:
type: gcp:networkconnectivity:PolicyBasedRoute
properties:
name: my-pbr
description: My routing policy
network: ${myNetwork.id}
priority: 2302
filter:
protocolVersion: IPV4
ipProtocol: UDP
srcRange: 10.0.0.0/24
destRange: 0.0.0.0/0
nextHopIlbIp: ${ilb.address}
virtualMachine:
tags:
- restricted
labels:
env: default
myNetwork:
type: gcp:compute:Network
name: my_network
properties:
name: my-network
autoCreateSubnetworks: 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.
ilb:
type: gcp:compute:GlobalAddress
properties:
name: my-ilb
Import
PolicyBasedRoute can be imported using any of these accepted formats:
projects/{{project}}/locations/global/policyBasedRoutes/{{name}}{{project}}/{{name}}{{name}}
When using the pulumi import command, PolicyBasedRoute can be imported using one of the formats above. For example:
$ pulumi import gcp:networkconnectivity/policyBasedRoute:PolicyBasedRoute default projects/{{project}}/locations/global/policyBasedRoutes/{{name}}
$ pulumi import gcp:networkconnectivity/policyBasedRoute:PolicyBasedRoute default {{project}}/{{name}}
$ pulumi import gcp:networkconnectivity/policyBasedRoute:PolicyBasedRoute default {{name}}
Constructors
- PolicyBasedRoute(String name, {PolicyBasedRouteArgs? args, CustomResourceOptions? options})
-
Creates a new PolicyBasedRoute.
nameThe Pulumi resource name.argsArguments used to configure this PolicyBasedRoute. The set of arguments for PolicyBasedRoute.optionsResource options controlling this resource's behavior. - PolicyBasedRoute.reference(String urn)
- Creates a typed reference to an existing PolicyBasedRoute resource.
Properties
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
createTime
↔ Output<
String> -
Time when the policy-based route was created.
latefinal
-
deletionPolicy
↔ Output<
String> -
Whether Terraform will be prevented from destroying the resource. Defaults to DELETE.
When a 'terraform destroy' or 'pulumi up' would delete the resource,
the command will fail if this field is set to "PREVENT" in Terraform state.
When set to "ABANDON", the command will remove the resource from Terraform
management without updating or deleting the resource in the API.
When set to "DELETE", deleting the resource is allowed.
latefinal
-
description
↔ Output<
String?> -
An optional description of this resource.
latefinal
-
effectiveLabels
↔ Output<
Map< String, String> > -
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Pulumi, other clients and services.
latefinal
-
filter
↔ Output<
PolicyBasedRouteFilter> -
The filter to match L4 traffic.
Structure is documented below.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
-
interconnectAttachment
↔ Output<
PolicyBasedRouteInterconnectAttachment?> -
The interconnect attachments that this policy-based route applies to.
Structure is documented below.
latefinal
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
kind
↔ Output<
String> -
Type of this resource.
latefinal
-
labels
↔ Output<
Map< String, String> ?> -
User-defined labels.
latefinal
-
name
↔ Output<
String> -
The name of the policy based route.
latefinal
-
network
↔ Output<
String> -
Fully-qualified URL of the network that this route applies to, for example: projects/my-project/global/networks/my-network.
latefinal
-
nextHopIlbIp
↔ Output<
String?> -
The IP address of a global-access-enabled L4 ILB that is the next hop for matching packets.
latefinal
-
nextHopOtherRoutes
↔ Output<
String?> -
Other routes that will be referenced to determine the next hop of the packet.
Possible values are:
DEFAULT_ROUTING.latefinal -
priority
↔ Output<
int?> -
The priority of this policy-based route. Priority is used to break ties in cases where there are more than one matching policy-based routes found. In cases where multiple policy-based routes are matched, the one with the lowest-numbered priority value wins. The default value is 1000. The priority value must be from 1 to 65535, inclusive.
latefinal
-
project
↔ Output<
String> -
The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
latefinal
-
pulumiLabels
↔ Output<
Map< String, String> > -
The combination of labels configured directly on the resource
and default labels configured on the provider.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
updateTime
↔ Output<
String> -
Time when the policy-based route was created.
latefinal
-
urn
↔ Output<
String> -
latefinalinherited
-
virtualMachine
↔ Output<
PolicyBasedRouteVirtualMachine?> -
VM instances to which this policy-based route applies to.
Structure is documented below.
latefinal
-
warnings
↔ Output<
List< PolicyBasedRouteWarning> > -
If potential misconfigurations are detected for this route, this field will be populated with warning messages.
Structure is documented below.
latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {PolicyBasedRouteState? state, CustomResourceOptions? options}) → PolicyBasedRoute -
Gets an existing PolicyBasedRoute resource's state with the given
nameandid.