1. Packages
  2. AWS
  3. API Docs
  4. ec2
  5. RouteTableAssociation
AWS v6.75.0 published on Wednesday, Apr 2, 2025 by Pulumi

aws.ec2.RouteTableAssociation

Explore with Pulumi AI

Provides a resource to create an association between a route table and a subnet or a route table and an internet gateway or virtual private gateway.

Example Usage

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

const a = new aws.ec2.RouteTableAssociation("a", {
    subnetId: foo.id,
    routeTableId: bar.id,
});
Copy
import pulumi
import pulumi_aws as aws

a = aws.ec2.RouteTableAssociation("a",
    subnet_id=foo["id"],
    route_table_id=bar["id"])
Copy
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ec2.NewRouteTableAssociation(ctx, "a", &ec2.RouteTableAssociationArgs{
			SubnetId:     pulumi.Any(foo.Id),
			RouteTableId: pulumi.Any(bar.Id),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var a = new Aws.Ec2.RouteTableAssociation("a", new()
    {
        SubnetId = foo.Id,
        RouteTableId = bar.Id,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.RouteTableAssociation;
import com.pulumi.aws.ec2.RouteTableAssociationArgs;
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 a = new RouteTableAssociation("a", RouteTableAssociationArgs.builder()
            .subnetId(foo.id())
            .routeTableId(bar.id())
            .build());

    }
}
Copy
resources:
  a:
    type: aws:ec2:RouteTableAssociation
    properties:
      subnetId: ${foo.id}
      routeTableId: ${bar.id}
Copy
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const b = new aws.ec2.RouteTableAssociation("b", {
    gatewayId: foo.id,
    routeTableId: bar.id,
});
Copy
import pulumi
import pulumi_aws as aws

b = aws.ec2.RouteTableAssociation("b",
    gateway_id=foo["id"],
    route_table_id=bar["id"])
Copy
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ec2.NewRouteTableAssociation(ctx, "b", &ec2.RouteTableAssociationArgs{
			GatewayId:    pulumi.Any(foo.Id),
			RouteTableId: pulumi.Any(bar.Id),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var b = new Aws.Ec2.RouteTableAssociation("b", new()
    {
        GatewayId = foo.Id,
        RouteTableId = bar.Id,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.RouteTableAssociation;
import com.pulumi.aws.ec2.RouteTableAssociationArgs;
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 b = new RouteTableAssociation("b", RouteTableAssociationArgs.builder()
            .gatewayId(foo.id())
            .routeTableId(bar.id())
            .build());

    }
}
Copy
resources:
  b:
    type: aws:ec2:RouteTableAssociation
    properties:
      gatewayId: ${foo.id}
      routeTableId: ${bar.id}
Copy

Create RouteTableAssociation Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new RouteTableAssociation(name: string, args: RouteTableAssociationArgs, opts?: CustomResourceOptions);
@overload
def RouteTableAssociation(resource_name: str,
                          args: RouteTableAssociationArgs,
                          opts: Optional[ResourceOptions] = None)

@overload
def RouteTableAssociation(resource_name: str,
                          opts: Optional[ResourceOptions] = None,
                          route_table_id: Optional[str] = None,
                          gateway_id: Optional[str] = None,
                          subnet_id: Optional[str] = None)
func NewRouteTableAssociation(ctx *Context, name string, args RouteTableAssociationArgs, opts ...ResourceOption) (*RouteTableAssociation, error)
public RouteTableAssociation(string name, RouteTableAssociationArgs args, CustomResourceOptions? opts = null)
public RouteTableAssociation(String name, RouteTableAssociationArgs args)
public RouteTableAssociation(String name, RouteTableAssociationArgs args, CustomResourceOptions options)
type: aws:ec2:RouteTableAssociation
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. RouteTableAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. RouteTableAssociationArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. RouteTableAssociationArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. RouteTableAssociationArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. RouteTableAssociationArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var routeTableAssociationResource = new Aws.Ec2.RouteTableAssociation("routeTableAssociationResource", new()
{
    RouteTableId = "string",
    GatewayId = "string",
    SubnetId = "string",
});
Copy
example, err := ec2.NewRouteTableAssociation(ctx, "routeTableAssociationResource", &ec2.RouteTableAssociationArgs{
	RouteTableId: pulumi.String("string"),
	GatewayId:    pulumi.String("string"),
	SubnetId:     pulumi.String("string"),
})
Copy
var routeTableAssociationResource = new RouteTableAssociation("routeTableAssociationResource", RouteTableAssociationArgs.builder()
    .routeTableId("string")
    .gatewayId("string")
    .subnetId("string")
    .build());
Copy
route_table_association_resource = aws.ec2.RouteTableAssociation("routeTableAssociationResource",
    route_table_id="string",
    gateway_id="string",
    subnet_id="string")
Copy
const routeTableAssociationResource = new aws.ec2.RouteTableAssociation("routeTableAssociationResource", {
    routeTableId: "string",
    gatewayId: "string",
    subnetId: "string",
});
Copy
type: aws:ec2:RouteTableAssociation
properties:
    gatewayId: string
    routeTableId: string
    subnetId: string
Copy

RouteTableAssociation Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The RouteTableAssociation resource accepts the following input properties:

RouteTableId This property is required. string
The ID of the routing table to associate with.
GatewayId Changes to this property will trigger replacement. string
The gateway ID to create an association. Conflicts with subnet_id.
SubnetId Changes to this property will trigger replacement. string
The subnet ID to create an association. Conflicts with gateway_id.
RouteTableId This property is required. string
The ID of the routing table to associate with.
GatewayId Changes to this property will trigger replacement. string
The gateway ID to create an association. Conflicts with subnet_id.
SubnetId Changes to this property will trigger replacement. string
The subnet ID to create an association. Conflicts with gateway_id.
routeTableId This property is required. String
The ID of the routing table to associate with.
gatewayId Changes to this property will trigger replacement. String
The gateway ID to create an association. Conflicts with subnet_id.
subnetId Changes to this property will trigger replacement. String
The subnet ID to create an association. Conflicts with gateway_id.
routeTableId This property is required. string
The ID of the routing table to associate with.
gatewayId Changes to this property will trigger replacement. string
The gateway ID to create an association. Conflicts with subnet_id.
subnetId Changes to this property will trigger replacement. string
The subnet ID to create an association. Conflicts with gateway_id.
route_table_id This property is required. str
The ID of the routing table to associate with.
gateway_id Changes to this property will trigger replacement. str
The gateway ID to create an association. Conflicts with subnet_id.
subnet_id Changes to this property will trigger replacement. str
The subnet ID to create an association. Conflicts with gateway_id.
routeTableId This property is required. String
The ID of the routing table to associate with.
gatewayId Changes to this property will trigger replacement. String
The gateway ID to create an association. Conflicts with subnet_id.
subnetId Changes to this property will trigger replacement. String
The subnet ID to create an association. Conflicts with gateway_id.

Outputs

All input properties are implicitly available as output properties. Additionally, the RouteTableAssociation resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing RouteTableAssociation Resource

Get an existing RouteTableAssociation resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: RouteTableAssociationState, opts?: CustomResourceOptions): RouteTableAssociation
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        gateway_id: Optional[str] = None,
        route_table_id: Optional[str] = None,
        subnet_id: Optional[str] = None) -> RouteTableAssociation
func GetRouteTableAssociation(ctx *Context, name string, id IDInput, state *RouteTableAssociationState, opts ...ResourceOption) (*RouteTableAssociation, error)
public static RouteTableAssociation Get(string name, Input<string> id, RouteTableAssociationState? state, CustomResourceOptions? opts = null)
public static RouteTableAssociation get(String name, Output<String> id, RouteTableAssociationState state, CustomResourceOptions options)
resources:  _:    type: aws:ec2:RouteTableAssociation    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
GatewayId Changes to this property will trigger replacement. string
The gateway ID to create an association. Conflicts with subnet_id.
RouteTableId string
The ID of the routing table to associate with.
SubnetId Changes to this property will trigger replacement. string
The subnet ID to create an association. Conflicts with gateway_id.
GatewayId Changes to this property will trigger replacement. string
The gateway ID to create an association. Conflicts with subnet_id.
RouteTableId string
The ID of the routing table to associate with.
SubnetId Changes to this property will trigger replacement. string
The subnet ID to create an association. Conflicts with gateway_id.
gatewayId Changes to this property will trigger replacement. String
The gateway ID to create an association. Conflicts with subnet_id.
routeTableId String
The ID of the routing table to associate with.
subnetId Changes to this property will trigger replacement. String
The subnet ID to create an association. Conflicts with gateway_id.
gatewayId Changes to this property will trigger replacement. string
The gateway ID to create an association. Conflicts with subnet_id.
routeTableId string
The ID of the routing table to associate with.
subnetId Changes to this property will trigger replacement. string
The subnet ID to create an association. Conflicts with gateway_id.
gateway_id Changes to this property will trigger replacement. str
The gateway ID to create an association. Conflicts with subnet_id.
route_table_id str
The ID of the routing table to associate with.
subnet_id Changes to this property will trigger replacement. str
The subnet ID to create an association. Conflicts with gateway_id.
gatewayId Changes to this property will trigger replacement. String
The gateway ID to create an association. Conflicts with subnet_id.
routeTableId String
The ID of the routing table to associate with.
subnetId Changes to this property will trigger replacement. String
The subnet ID to create an association. Conflicts with gateway_id.

Import

With EC2 Internet Gateways:

Using pulumi import to import EC2 Route Table Associations using the associated resource ID and Route Table ID separated by a forward slash (/). For example:

With EC2 Subnets:

$ pulumi import aws:ec2/routeTableAssociation:RouteTableAssociation assoc subnet-6777656e646f6c796e/rtb-656c65616e6f72
Copy

With EC2 Internet Gateways:

$ pulumi import aws:ec2/routeTableAssociation:RouteTableAssociation assoc igw-01b3a60780f8d034a/rtb-656c65616e6f72
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.