diff --git a/ec2/ec2.go b/ec2/ec2.go index 4e89b431..dffc90c0 100644 --- a/ec2/ec2.go +++ b/ec2/ec2.go @@ -3080,3 +3080,42 @@ func (ec2 *EC2) ResetImageAttribute(imageId string, options *ResetImageAttribute } return } + +type CreateCustomerGateway struct { + Type string + IpAddress string + BgpAsn int +} + +// Response to a CreateCustomerGateway request +type CreateCustomerGatewayResp struct { + RequestId string `xml:"requestId"` + CustomerGateway CustomerGateway `xml:"customerGateway"` +} + +type CustomerGateway struct { + CustomerGatewayId string `xml:"customerGatewayId"` + State string `xml:"state"` + Type string `xml:"type"` + IpAddress string `xml:"ipAddress"` + BgpAsn int `xml:"bgpAsn"` + Tags []Tag `xml:"tagSet>item"` +} + +//Create a customer gateway +func (ec2 *EC2) CreateCustomerGateway(options *CreateCustomerGateway)(resp *CreateCustomerGatewayResp, err error){ + params := makeParams("CreateCustomerGateway") + params["Type"] = options.Type + params["IpAddress"] = options.IpAddress + if options.BgpAsn != 0{ + params["BgpAsn"] = strconv.Itoa(options.BgpAsn) + } + + resp = &CreateCustomerGatewayResp{} + err = ec2.query(params, resp) + if err != nil{ + return nil, err + } + return +} + diff --git a/ec2/ec2_test.go b/ec2/ec2_test.go index 3ea2bdc7..e05714db 100644 --- a/ec2/ec2_test.go +++ b/ec2/ec2_test.go @@ -1436,3 +1436,25 @@ func (s *S) TestReplaceNetworkAclAssociation(c *C) { c.Assert(resp.RequestId, Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE") c.Assert(resp.NewAssociationId, Equals, "aclassoc-17b85d7e") } + +func (s *S) TestCreateCustomerGateway(c *C) { + testServer.Response(200, nil, CreateCustomerGatewayResponseExample) + + options := &ec2.CreateCustomerGateway{ + Type: "ipsec.1", + IpAddress: "10.0.0.20", + BgpAsn: 65534, + } + + resp, err := s.ec2.CreateCustomerGateway(options) + + req := testServer.WaitRequest() + c.Assert(req.Form["Type"], DeepEquals, []string{"ipsec.1"}) + + c.Assert(err, IsNil) + c.Assert(resp.RequestId, Equals, "7a62c49f-347e-4fc4-9331-6e8eEXAMPLE") + c.Assert(resp.CustomerGateway.Type, Equals, "ipsec.1") + c.Assert(resp.CustomerGateway.State, Equals, "pending") + c.Assert(resp.CustomerGateway.BgpAsn, Equals, 65534) + c.Assert(resp.CustomerGateway.IpAddress, Equals, "10.0.0.20") +} diff --git a/ec2/responses_test.go b/ec2/responses_test.go index 94a681c7..43781ebe 100644 --- a/ec2/responses_test.go +++ b/ec2/responses_test.go @@ -1205,3 +1205,17 @@ var ReplaceNetworkAclAssociationResponseExample = ` aclassoc-17b85d7e ` + +var CreateCustomerGatewayResponseExample = ` + + 7a62c49f-347e-4fc4-9331-6e8eEXAMPLE + + cgw-b4dc3961 + pending + ipsec.1 + 10.0.0.20 + 65534 + + + +`