diff --git a/ec2/ec2.go b/ec2/ec2.go index 8f94ad53..ca62e3fa 100644 --- a/ec2/ec2.go +++ b/ec2/ec2.go @@ -2125,6 +2125,19 @@ type CreateSubnetResp struct { Subnet Subnet `xml:"subnet"` } +// The ModifySubnetAttribute request parameters +// +// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-ModifySubnetAttribute.html +type ModifySubnetAttribute struct { + SubnetId string + MapPublicIpOnLaunch bool +} + +type ModifySubnetAttributeResp struct { + RequestId string `xml:"requestId"` + Return bool `xml:"return"` +} + // Response to a DescribeInternetGateways request. type InternetGatewaysResp struct { RequestId string `xml:"requestId"` @@ -2331,6 +2344,22 @@ func (ec2 *EC2) DeleteSubnet(id string) (resp *SimpleResp, err error) { return } +// ModifySubnetAttribute +// +// http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-ModifySubnetAttribute.html +func (ec2 *EC2) ModifySubnetAttribute(options *ModifySubnetAttribute) (resp *ModifySubnetAttributeResp, err error) { + params := makeParams("ModifySubnetAttribute") + params["SubnetId"] = options.SubnetId + params["MapPublicIpOnLaunch.Value"] = options.MapPublicIpOnLaunch + + resp = &SimpleResp{} + err = ec2.query(params, resp) + if err != nil { + return nil, err + } + return +} + // DescribeSubnets // // http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html diff --git a/ec2/ec2_test.go b/ec2/ec2_test.go index 849bfe2e..3d218181 100644 --- a/ec2/ec2_test.go +++ b/ec2/ec2_test.go @@ -1229,6 +1229,24 @@ func (s *S) TestCreateSubnet(c *C) { c.Assert(resp.Subnet.AvailableIpAddressCount, Equals, 251) } +func (s *S) TestModifySubnetAttribute(c *C) { + testServer.Response(200, nil, ModifySubnetAttributeExample) + + options := &ec2.ModifySubnetAttribute{ + SubnetId: "foo", + MapPublicIpOnLaunch: true + } + + resp, err := s.ec2.ModifySubnetAttribute(options) + + req := testServer.WaitRequest() + c.Assert(req.Form["SubnetId"], DeepEquals, []string{"foo"}) + c.Assert(req.Form["MapPublicIpOnLaunch"], Equals, true) + + c.Assert(err, IsNil) + c.Assert(resp.RequestId, Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE") +} + func (s *S) TestResetImageAttribute(c *C) { testServer.Response(200, nil, ResetImageAttributeExample) diff --git a/ec2/responses_test.go b/ec2/responses_test.go index 0a4dbb36..bba2ab6a 100644 --- a/ec2/responses_test.go +++ b/ec2/responses_test.go @@ -845,6 +845,14 @@ var CreateSubnetExample = ` ` +// http://goo.gl/tu2Kxm +var ModifySubnetAttributeExample = ` + + 59dbff89-35bd-4eac-99ed-be587EXAMPLE + true + +` + // http://goo.gl/r6ZCPm var ResetImageAttributeExample = `