Resource: aws_default_route_table

Provides a resource to manage a default route table of a VPC. This resource can manage the default route table of the default or a non-default VPC.

Every VPC has a default route table that can be managed but not destroyed. When Terraform first adopts a default route table, it immediately removes all defined routes. It then proceeds to create any routes specified in the configuration. This step is required so that only the routes specified in the configuration exist in the default route table.

For more information, see the Amazon VPC User Guide on Route Tables. For information about managing normal route tables in Terraform, see aws_route_table.

Example Usage

resource "aws_default_route_table" "example" {
  default_route_table_id = aws_vpc.example.default_route_table_id

  route {
    cidr_block = "10.0.1.0/24"
    gateway_id = aws_internet_gateway.example.id
  }

  route {
    ipv6_cidr_block        = "::/0"
    egress_only_gateway_id = aws_egress_only_internet_gateway.example.id
  }

  tags = {
    Name = "example"
  }
}

To subsequently remove all managed routes:

resource "aws_default_route_table" "example" {
  default_route_table_id = aws_vpc.example.default_route_table_id

  route = []

  tags = {
    Name = "example"
  }
}

Argument Reference

The following arguments are required:

The following arguments are optional:

route

This argument is processed in attribute-as-blocks mode.

One of the following destination arguments must be supplied:

One of the following target arguments must be supplied:

Note that the default route, mapping the VPC's CIDR block to "local", is created implicitly and cannot be specified.

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import Default VPC route tables using the vpc_id. For example:

import {
  to = aws_default_route_table.example
  id = "vpc-33cc44dd"
}

Using terraform import, import Default VPC route tables using the vpc_id. For example:

% terraform import aws_default_route_table.example vpc-33cc44dd