Skip to main content

Route Table Association

Associate a subnet to a Route Table

Code#

Route Table associated with a subnet#

provider.EC2.makeVpc({
name: "Vpc",
properties: ({ config }) => ({
CidrBlock: "10.0.0.0/16",
}),
});
provider.EC2.makeSubnet({
name: "PubSubnetAz1",
properties: ({ config }) => ({
CidrBlock: "10.0.0.0/24",
AvailabilityZone: `${config.region}a`,
}),
dependencies: ({ resources }) => ({
vpc: resources.EC2.Vpc["Vpc"],
}),
});
provider.EC2.makeRouteTable({
name: "RouteViaIgw",
dependencies: ({ resources }) => ({
vpc: resources.EC2.Vpc["Vpc"],
}),
});
provider.EC2.makeRouteTableAssociation({
dependencies: ({ resources }) => ({
routeTable: resources.EC2.RouteTable["RouteViaIgw"],
subnet: resources.EC2.Subnet["PubSubnetAz1"],
}),
});

Examples#

Dependencies#

List#

List only the route tables with the RouteTableAssociation filter:

gc l -t RouteTableAssociation
Listing resources on 1 provider: aws
✓ aws
✓ Initialising
✓ Listing 5/5
┌────────────────────────────────────────────────────────────────────────────────┐
│ 2 EC2::RouteTableAssociation from aws │
├────────────────────────────────────────────────────────────────────────────────┤
│ name: rt-assoc::route-table-public::subnet-1 │
│ managedByUs: Yes │
│ live: │
│ Main: false │
│ RouteTableAssociationId: rtbassoc-0347f6252694e72d0 │
│ RouteTableId: rtb-0c48ec9583f4e9318 │
│ SubnetId: subnet-029068595723f242e │
│ AssociationState: │
│ State: associated │
│ │
├────────────────────────────────────────────────────────────────────────────────┤
│ name: rt-assoc::route-table-public::subnet-2 │
│ managedByUs: Yes │
│ live: │
│ Main: false │
│ RouteTableAssociationId: rtbassoc-05e975dd7e1adec87 │
│ RouteTableId: rtb-0c48ec9583f4e9318 │
│ SubnetId: subnet-0c9c5cf8b25507188 │
│ AssociationState: │
│ State: associated │
│ │
└────────────────────────────────────────────────────────────────────────────────┘
List Summary:
Provider: aws
┌───────────────────────────────────────────────────────────────────────────────┐
│ aws │
├────────────────────────────┬──────────────────────────────────────────────────┤
│ EC2::RouteTableAssociation │ rt-assoc::route-table-public::subnet-1 │
│ │ rt-assoc::route-table-public::subnet-2 │
└────────────────────────────┴──────────────────────────────────────────────────┘
2 resources, 1 type, 1 provider
Command "gc l -t RouteTableAssociation" executed in 5s