Skip to content

Commit

Permalink
Merge branch 'partner-configs'
Browse files Browse the repository at this point in the history
  • Loading branch information
alkar committed Nov 4, 2019
2 parents b54e1ac + dff5f4c commit 486be63
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
51 changes: 47 additions & 4 deletions megaport/api/vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type vxcCreatePayloadAssociatedVxc struct {
CostCentre *string `json:"costCentre,omitempty"`
AEnd *vxcCreatePayloadVxcEnd `json:"aEnd,omitempty"`
BEnd *vxcCreatePayloadVxcEnd `json:"bEnd,omitempty"`
PartnerConfig *PartnerConfig `json:"partnerConfigs,omitempty"`
PartnerConfig interface{} `json:"partnerConfigs,omitempty"`
}

type vxcCreatePayloadVxcEnd struct {
Expand Down Expand Up @@ -186,12 +186,55 @@ func (c *Client) DeletePrivateVxc(uid string) error {
return c.delete(uid)
}

type PartnerConfig map[string]interface{}
type PartnerConfig interface {
connectType() string
toPayload() interface{}
}

type PartnerConfigAWS struct {
AmazonIPAddress *string
AWSConnectionName *string
AWSAccountID *string
BGPAuthKey *string
CustomerASN *uint64
CustomerIPAddress *string
Type *string
}

func (v *PartnerConfigAWS) connectType() string {
return "AWS"
}

func (v *PartnerConfigAWS) toPayload() interface{} {
return &vxcCreatePayloadPartnerConfigAWS{
AmazonIpAddress: v.AmazonIPAddress,
Asn: v.CustomerASN,
AuthKey: v.BGPAuthKey,
ConnectType: String(v.connectType()),
CustomerIpAddress: v.CustomerIPAddress,
Name: v.AWSConnectionName,
OwnerAccount: v.AWSAccountID,
Type: v.Type,
}
}

type vxcCreatePayloadPartnerConfigAWS struct {
// AmazonAsn *uint64 `json:""`
AmazonIpAddress *string `json:"amazonIpAddress"`
Asn *uint64 `json:"asn"`
AuthKey *string `json:"authKey"`
ConnectType *string `json:"connectType"`
CustomerIpAddress *string `json:"customerIpAddress"`
Name *string `json:"name"`
OwnerAccount *string `json:"ownerAccount"`
// Prefixes *string `json:""`
Type *string `json:"type"`
}

type CloudVxcCreateInput struct {
InvoiceReference *string
Name *string
PartnerConfig *PartnerConfig
PartnerConfig PartnerConfig
ProductUidA *string
ProductUidB *string
RateLimit *uint64
Expand All @@ -202,7 +245,7 @@ func (v *CloudVxcCreateInput) toPayload() ([]byte, error) {
payload := []*vxcCreatePayload{{ProductUid: v.ProductUidA}}
av := &vxcCreatePayloadAssociatedVxc{
CostCentre: v.InvoiceReference,
PartnerConfig: v.PartnerConfig,
PartnerConfig: v.PartnerConfig.toPayload(),
ProductName: v.Name,
RateLimit: v.RateLimit,
}
Expand Down
22 changes: 13 additions & 9 deletions megaport/resource_megaport_aws_vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func resourceMegaportVxcAwsEndElem() *schema.Resource {
Required: true,
ForceNew: true,
},
"aws_connection_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"aws_account_id": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -141,15 +146,14 @@ func resourceMegaportAwsVxcCreate(d *schema.ResourceData, m interface{}) error {
InvoiceReference: api.String(d.Get("invoice_reference")),
VlanA: api.Uint64FromInt(a["vlan"]),
RateLimit: api.Uint64FromInt(d.Get("rate_limit")),
PartnerConfig: &api.PartnerConfig{
"connectType": "AWS",
"type": "private",
"asn": b["customer_asn"],
"ownerAccount": b["aws_account_id"],
"authKey": b["bgp_auth_key"],
"prefixes": nil,
"customerIpAddress": nil,
"amazonIpAddress": nil,
PartnerConfig: &api.PartnerConfigAWS{
AWSConnectionName: api.String(d.Get("aws_connection_name")),
AWSAccountID: api.String(b["aws_account_id"]),
AmazonIPAddress: api.String(d.Get("amazon_ip_address")),
BGPAuthKey: api.String(b["bgp_auth_key"]),
CustomerASN: api.Uint64(b["customer_asn"]),
CustomerIPAddress: api.String(d.Get("customer_ip_address")),
Type: api.String(d.Get("type")),
},
})
if err != nil {
Expand Down

0 comments on commit 486be63

Please sign in to comment.