Resource: aws_route_table_association

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

resource "aws_route_table_association" "a" {
  subnet_id      = aws_subnet.foo.id
  route_table_id = aws_route_table.bar.id
}
resource "aws_route_table_association" "b" {
  gateway_id     = aws_internet_gateway.foo.id
  route_table_id = aws_route_table.bar.id
}

Argument Reference

This argument supports the following arguments:

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 EC2 Route Table Associations using the associated resource ID and Route Table ID separated by a forward slash (/). For example:

With EC2 Subnets:

import {
  to = aws_route_table_association.assoc
  id = "subnet-6777656e646f6c796e/rtb-656c65616e6f72"
}

With EC2 Internet Gateways:

import {
  to = aws_route_table_association.assoc
  id = "igw-01b3a60780f8d034a/rtb-656c65616e6f72"
}

Using terraform 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:

% terraform import aws_route_table_association.assoc subnet-6777656e646f6c796e/rtb-656c65616e6f72

With EC2 Internet Gateways:

% terraform import aws_route_table_association.assoc igw-01b3a60780f8d034a/rtb-656c65616e6f72