Skip to content

Commit

Permalink
Ashutosh / Yahya - Added Create Customer Gateway for AWS VPC VPN. Add…
Browse files Browse the repository at this point in the history
…ing enhancement as specified here : hashicorp/terraform#551
  • Loading branch information
ashutoshraina committed Dec 15, 2014
1 parent b2b88cf commit 1cc167c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

22 changes: 22 additions & 0 deletions ec2/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
14 changes: 14 additions & 0 deletions ec2/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1205,3 +1205,17 @@ var ReplaceNetworkAclAssociationResponseExample = `
<newAssociationId>aclassoc-17b85d7e</newAssociationId>
</ReplaceNetworkAclAssociationResponse>
`

var CreateCustomerGatewayResponseExample = `
<CreateCustomerGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2014-06-15/">
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
<customerGateway>
<customerGatewayId>cgw-b4dc3961</customerGatewayId>
<state>pending</state>
<type>ipsec.1</type>
<ipAddress>10.0.0.20</ipAddress>
<bgpAsn>65534</bgpAsn>
<tagSet/>
</customerGateway>
</CreateCustomerGatewayResponse>
`

0 comments on commit 1cc167c

Please sign in to comment.