DefaultRouteTable class

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.

> NOTE: This is an advanced resource with special caveats. Please read this document in its entirety before using this resource. The aws.ec2.DefaultRouteTable resource behaves differently from normal resources. Terraform does not create this resource but instead attempts to "adopt" it into management. Do not use both aws.ec2.DefaultRouteTable to manage a default route table and aws.ec2.MainRouteTableAssociation with the same VPC due to possible route conflicts. See aws.ec2.MainRouteTableAssociation documentation for more details.

Every VPC has a default route table that can be managed but not destroyed. When the provider 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 this provider, see aws.ec2.RouteTable.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.ec2.DefaultRouteTable("example", {
    routes: [
        {
            cidrBlock: "10.0.1.0/24",
            gatewayId: exampleAwsInternetGateway.id,
        },
        {
            ipv6CidrBlock: "::/0",
            egressOnlyGatewayId: exampleAwsEgressOnlyInternetGateway.id,
        },
    ],
    defaultRouteTableId: exampleAwsVpc.defaultRouteTableId,
    tags: {
        Name: "example",
    },
});
import pulumi
import pulumi_aws as aws

example = aws.ec2.DefaultRouteTable("example",
    routes=[
        {
            "cidr_block": "10.0.1.0/24",
            "gateway_id": example_aws_internet_gateway["id"],
        },
        {
            "ipv6_cidr_block": "::/0",
            "egress_only_gateway_id": example_aws_egress_only_internet_gateway["id"],
        },
    ],
    default_route_table_id=example_aws_vpc["defaultRouteTableId"],
    tags={
        "Name": "example",
    })
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.Ec2.DefaultRouteTable("example", new()
    {
        Routes = new[]
        {
            new Aws.Ec2.Inputs.DefaultRouteTableRouteArgs
            {
                CidrBlock = "10.0.1.0/24",
                GatewayId = exampleAwsInternetGateway.Id,
            },
            new Aws.Ec2.Inputs.DefaultRouteTableRouteArgs
            {
                Ipv6CidrBlock = "::/0",
                EgressOnlyGatewayId = exampleAwsEgressOnlyInternetGateway.Id,
            },
        },
        DefaultRouteTableId = exampleAwsVpc.DefaultRouteTableId,
        Tags =
        {
            { "Name", "example" },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ec2.NewDefaultRouteTable(ctx, "example", &ec2.DefaultRouteTableArgs{
			Routes: ec2.DefaultRouteTableRouteArray{
				&ec2.DefaultRouteTableRouteArgs{
					CidrBlock: pulumi.String("10.0.1.0/24"),
					GatewayId: pulumi.Any(exampleAwsInternetGateway.Id),
				},
				&ec2.DefaultRouteTableRouteArgs{
					Ipv6CidrBlock:       pulumi.String("::/0"),
					EgressOnlyGatewayId: pulumi.Any(exampleAwsEgressOnlyInternetGateway.Id),
				},
			},
			DefaultRouteTableId: pulumi.Any(exampleAwsVpc.DefaultRouteTableId),
			Tags: pulumi.StringMap{
				"Name": pulumi.String("example"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_ec2_defaultroutetable" "example" {
  routes {
    cidr_block = "10.0.1.0/24"
    gateway_id = exampleAwsInternetGateway.id
  }
  routes {
    ipv6_cidr_block        = "::/0"
    egress_only_gateway_id = exampleAwsEgressOnlyInternetGateway.id
  }
  default_route_table_id = exampleAwsVpc.defaultRouteTableId
  tags = {
    "Name" = "example"
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.DefaultRouteTable;
import com.pulumi.aws.ec2.DefaultRouteTableArgs;
import com.pulumi.aws.ec2.inputs.DefaultRouteTableRouteArgs;
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 example = new DefaultRouteTable("example", DefaultRouteTableArgs.builder()
            .routes(
                DefaultRouteTableRouteArgs.builder()
                    .cidrBlock("10.0.1.0/24")
                    .gatewayId(exampleAwsInternetGateway.id())
                    .build(),
                DefaultRouteTableRouteArgs.builder()
                    .ipv6CidrBlock("::/0")
                    .egressOnlyGatewayId(exampleAwsEgressOnlyInternetGateway.id())
                    .build())
            .defaultRouteTableId(exampleAwsVpc.defaultRouteTableId())
            .tags(Map.of("Name", "example"))
            .build());

    }
}
resources:
  example:
    type: aws:ec2:DefaultRouteTable
    properties:
      routes:
        - cidrBlock: 10.0.1.0/24
          gatewayId: ${exampleAwsInternetGateway.id}
        - ipv6CidrBlock: ::/0
          egressOnlyGatewayId: ${exampleAwsEgressOnlyInternetGateway.id}
      defaultRouteTableId: ${exampleAwsVpc.defaultRouteTableId}
      tags:
        Name: example

To subsequently remove all managed routes:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.ec2.DefaultRouteTable("example", {
    defaultRouteTableId: exampleAwsVpc.defaultRouteTableId,
    routes: [],
    tags: {
        Name: "example",
    },
});
import pulumi
import pulumi_aws as aws

example = aws.ec2.DefaultRouteTable("example",
    default_route_table_id=example_aws_vpc["defaultRouteTableId"],
    routes=[],
    tags={
        "Name": "example",
    })
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.Ec2.DefaultRouteTable("example", new()
    {
        DefaultRouteTableId = exampleAwsVpc.DefaultRouteTableId,
        Routes = new[] {},
        Tags =
        {
            { "Name", "example" },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ec2.NewDefaultRouteTable(ctx, "example", &ec2.DefaultRouteTableArgs{
			DefaultRouteTableId: pulumi.Any(exampleAwsVpc.DefaultRouteTableId),
			Routes:              ec2.DefaultRouteTableRouteArray{},
			Tags: pulumi.StringMap{
				"Name": pulumi.String("example"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_ec2_defaultroutetable" "example" {
  default_route_table_id = exampleAwsVpc.defaultRouteTableId
  tags = {
    "Name" = "example"
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.DefaultRouteTable;
import com.pulumi.aws.ec2.DefaultRouteTableArgs;
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 example = new DefaultRouteTable("example", DefaultRouteTableArgs.builder()
            .defaultRouteTableId(exampleAwsVpc.defaultRouteTableId())
            .routes()
            .tags(Map.of("Name", "example"))
            .build());

    }
}
resources:
  example:
    type: aws:ec2:DefaultRouteTable
    properties:
      defaultRouteTableId: ${exampleAwsVpc.defaultRouteTableId}
      routes: []
      tags:
        Name: example

Import

Using pulumi import, import Default VPC route tables using the vpcId. For example:

$ pulumi import aws:ec2/defaultRouteTable:DefaultRouteTable example vpc-33cc44dd

Constructors

DefaultRouteTable(String name, {DefaultRouteTableArgs? args, CustomResourceOptions? options})
Creates a new DefaultRouteTable. name The Pulumi resource name. args Arguments used to configure this DefaultRouteTable. The set of arguments for DefaultRouteTable. options Resource options controlling this resource's behavior.
DefaultRouteTable.reference(String urn)
Creates a typed reference to an existing DefaultRouteTable resource.

Properties

arn ↔ Output<String>
The ARN of the route table.
latefinal
childResources Set<Resource>
finalinherited
completionSources Map<String, IOutputCompletionSource>
latefinalinherited
defaultRouteTableId ↔ Output<String>
ID of the default route table.
latefinal
hashCode int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
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
ownerId ↔ Output<String>
ID of the AWS account that owns the route table.
latefinal
propagatingVgws ↔ Output<List<String>?>
List of virtual gateways for propagation.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
routes ↔ Output<List<DefaultRouteTableRoute>>
Set of objects. Detailed below
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tags ↔ Output<Map<String, String>?>
Map of tags to assign to the resource. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
latefinal
tagsAll ↔ Output<Map<String, String>>
A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
latefinal
transformations List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited
vpcId ↔ Output<String>
ID of the VPC.
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, {DefaultRouteTableState? state, CustomResourceOptions? options}) DefaultRouteTable
Gets an existing DefaultRouteTable resource's state with the given name and id.