Route Table
Provides a resource to create a VPC routing table.
NOTE on Route Tables and Routes: This provider currently provides both a standalone Route resource and a Route Table resource with routes defined in-line. At this time you cannot use a Route Table with in-line routes in conjunction with any Route resources. Doing so will cause a conflict of rule settings and will overwrite rules. NOTE on
gateway_id
andnat_gateway_id
: The AWS API is very forgiving with these two attributes and theaws.ec2.RouteTable
resource can be created with a NAT ID specified as a Gateway ID attribute. This will lead to a permanent diff between your configuration and statefile, as the API returns the correct parameters in the returned route table. If you're experiencing constant diffs in youraws.ec2.RouteTable
resources, the first thing to check is whether or not you're specifying a NAT ID instead of a Gateway ID, or vice-versa. NOTE onpropagating_vgws
and theaws.ec2.VpnGatewayRoutePropagation
resource: If thepropagating_vgws
argument is present, it's not supported to also define route propagations usingaws.ec2.VpnGatewayRoutePropagation
, since this resource will delete any propagating gateways not explicitly listed inpropagating_vgws
. Omit this argument when defining route propagation using the separate resource.
Example Usage
Basic example
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.RouteTable;
import com.pulumi.aws.ec2.RouteTableArgs;
import com.pulumi.aws.ec2.inputs.RouteTableRouteArgs;
import java.util.List;
import java.util.ArrayList;
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 example = new RouteTable("example", RouteTableArgs.builder()
.vpcId(aws_vpc.example().id())
.routes(
RouteTableRouteArgs.builder()
.cidrBlock("10.0.1.0/24")
.gatewayId(aws_internet_gateway.example().id())
.build(),
RouteTableRouteArgs.builder()
.ipv6CidrBlock("::/0")
.egressOnlyGatewayId(aws_egress_only_internet_gateway.example().id())
.build())
.tags(Map.of("Name", "example"))
.build());
}
}
Adopting an existing local route
AWS creates certain routes that the AWS provider mostly ignores. You can manage them by importing or adopting them. See Import below for information on importing. This example shows adopting a route and then updating its target. First, adopt an existing AWS-created route:
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Vpc;
import com.pulumi.aws.ec2.VpcArgs;
import com.pulumi.aws.ec2.RouteTable;
import com.pulumi.aws.ec2.RouteTableArgs;
import com.pulumi.aws.ec2.inputs.RouteTableRouteArgs;
import java.util.List;
import java.util.ArrayList;
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 testVpc = new Vpc("testVpc", VpcArgs.builder()
.cidrBlock("10.1.0.0/16")
.build());
var testRouteTable = new RouteTable("testRouteTable", RouteTableArgs.builder()
.vpcId(testVpc.id())
.routes(RouteTableRouteArgs.builder()
.cidrBlock("10.1.0.0/16")
.gatewayId("local")
.build())
.build());
}
}
Import
Using pulumi import
, import Route Tables using the route table id
. For example:
$ pulumi import aws:ec2/routeTable:RouteTable public_rt rtb-4e616f6d69