Represents the association between a {RouteTable} and a {Subnet}.
You can get a route table association 2 ways:
enumerating associations from a route table
Asking a subnet for its route table association
Given a route table:
route_table.associations.each do |assoc| if assoc.main? # main association does not have a subnet puts "#{assoc.id} : main association" else puts "#{assoc.id} : #{assoc.subnet.id}" end end
All subnets are associated with a route table. If the association was never explicitly created, then they are associated by default with the main route table.
subnet.route_table_association #=> AWS::EC2::RouteTable::Association subnet.route_table_association.main? #=> true/false
To replace a route table association start at the subnet end:
subnet.route_table = some_other_route_table
If this route table is associated (by default) to the main route table via the main (default) association a new association is created. If it was previously associated directly to a different route table then that association will be repalced.
You can delete all but the main route table association. When you delete an association, the subnet becomes associated with the main route table.
# delete all explicit route table associations -- as a result # all subnets will default to the main route table vpc.subnets.each do |subnet| assoc = subnet.route_table_association assoc.delete unless assoc.main? end
@return [String] An identifier representing the association
between the network ACL and subnet.
@return [String] An identifier representing the association
between the network ACL and subnet.
@return [Boolean] Returns true if this association is the main
(default) association for all subnets within this route table's VPC.
@return [Boolean] Returns true if this association is the main
(default) association for all subnets within this route table's VPC.
@return [RouteTable]
@return [Subnet,nil] Returns the subnet this association belongs.
If this is the main (default) association, then this method returns nil.
@private
# File lib/aws/ec2/route_table/association.rb, line 74 def initialize route_table, association_id, subnet_id @route_table = route_table @association_id = association_id if subnet_id @main = false @subnet = Subnet.new(subnet_id, :config => route_table.config) else @main = true end end
Deletes the association between the route table and the subnet @return [nil]
# File lib/aws/ec2/route_table/association.rb, line 109 def delete route_table.client.disassociate_route_table( :association_id => association_id) nil end