Skip to content

Commit

Permalink
Add EC2 AssociateRouteTable
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheath committed Apr 2, 2014
1 parent 4bd3836 commit 6f54e50
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ec2/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,3 +815,10 @@ var DescribeRouteTablesExample = `
</routeTableSet>
</DescribeRouteTablesResponse>
`

var AssociateRouteTableExample = `
<AssociateRouteTableResponse xmlns="http://ec2.amazonaws.com/doc/2014-02-01/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<associationId>rtbassoc-f8ad4891</associationId>
</AssociateRouteTableResponse>
`
29 changes: 29 additions & 0 deletions ec2/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,32 @@ func (ec2 *EC2) DescribeRouteTables(routeTableIds []string, filter *Filter) (res
}
return
}

// AssociateRouteTableResp represents a response from an AssociateRouteTable call
//
// See http://goo.gl/T4KlYk for more details.
type AssociateRouteTableResp struct {
RequestId string `xml:"requestId"`
AssociationId string `xml:"associationId"`
}

// AssociateRouteTable associates a subnet with a route table.
//
// The subnet and route table must be in the same VPC. This association causes
// traffic originating from the subnet to be routed according to the routes
// in the route table. The action returns an association ID, which you need in
// order to disassociate the route table from the subnet later.
// A route table can be associated with multiple subnets.
//
// See http://goo.gl/bfnONU for more details.
func (ec2 *EC2) AssociateRouteTable(routeTableId, subnetId string) (resp *AssociateRouteTableResp, err error) {
params := makeParams("AssociateRouteTable")
params["RouteTableId"] = routeTableId
params["SubnetId"] = subnetId
resp = &AssociateRouteTableResp{}
err = ec2.query(params, resp)
if err != nil {
return nil, err
}
return
}
15 changes: 15 additions & 0 deletions ec2/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ func (s *S) TestDescribeRouteTables(c *gocheck.C) {
{Id: "rtbassoc-faad4893", RouteTableId: "rtb-f9ad4890", SubnetId: "subnet-15ad487c"},
})
}

func (s *S) TestAssociateRouteTable(c *gocheck.C) {
testServer.Response(200, nil, AssociateRouteTableExample)

resp, err := s.ec2.AssociateRouteTable("rtb-e4ad488d", "subnet-15ad487c")

req := testServer.WaitRequest()
c.Assert(req.Form["Action"], gocheck.DeepEquals, []string{"AssociateRouteTable"})
c.Assert(req.Form["RouteTableId"], gocheck.DeepEquals, []string{"rtb-e4ad488d"})
c.Assert(req.Form["SubnetId"], gocheck.DeepEquals, []string{"subnet-15ad487c"})

c.Assert(err, gocheck.IsNil)
c.Assert(resp.RequestId, gocheck.Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE")
c.Assert(resp.AssociationId, gocheck.Equals, "rtbassoc-f8ad4891")
}

0 comments on commit 6f54e50

Please sign in to comment.