Skip to content

Commit

Permalink
megaport_aws_vxc: handle partner configs
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Oct 28, 2019
1 parent b9f14e1 commit b46c24d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
57 changes: 57 additions & 0 deletions megaport/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ type ProductAssociatedVxc struct {
ProductUid string
ProvisioningStatus string
RateLimit uint64
Resources ProductAssociatedVxcResources // TODO: not documented - is the struct here the same as in Product?
SecondaryName string
UsageAlgorithm string
VxcApproval ProductAssociatedVxcApproval
Expand All @@ -265,6 +266,62 @@ type ProductAssociatedVxcApproval struct {
// Uid // TODO: haven't seen a value other than null
}

type ProductAssociatedVxcResources struct {
AwsVirtualInterface ProductAssociatedVxcResourcesAwsVirtualInterface `json:"aws_virtualinterface"`
}

type ProductAssociatedVxcResourcesAwsVirtualInterface struct {
Account string
AmazonAsn uint64 `json:"-"`
AmazonIpAddress string
AmazonAddress string `json:"Amazon_address"`
// Amazon_Asn uint64 `json:"Amazon_asn"`
Asn uint64 `json:"-"`
AuthKey string
// Auth_key string `json:"Auth_key"`
ConnectType string
CustomerIpAddress string
// Customer_address string `json:"Customer_address"`
Id uint64 `json:"-"`
Name string
OwnerAccount string
PeerAsn uint64 `json:"-"`
// Prefixes // null?
ResourceName string `json:"Resource_name"`
ResourceType string `json:"Resource_type"`
Type string
VifId string `json:"Vif_id"`
Vlan uint64 `json:"-"`
}

type productAssociatedVxcResourcesAwsVirtualInterfaceFloats struct {
AmazonAsn float64 `json:"amazonAsn"`
Asn float64 `json:"asn"`
Id float64 `json:"id"`
PeerAsn float64 `json:"peerAsn"`
Vlan float64 `json:"vlan"`
}

type productAssociatedVxcResourcesAwsVirtualInterface ProductAssociatedVxcResourcesAwsVirtualInterface

func (pr *ProductAssociatedVxcResourcesAwsVirtualInterface) UnmarshalJSON(b []byte) (err error) {
v := productAssociatedVxcResourcesAwsVirtualInterface{}
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*pr = ProductAssociatedVxcResourcesAwsVirtualInterface(v)
vf := productAssociatedVxcResourcesAwsVirtualInterfaceFloats{}
if err := json.Unmarshal(b, &vf); err != nil {
return err
}
pr.AmazonAsn = uint64(vf.AmazonAsn)
pr.Asn = uint64(vf.Asn)
pr.Id = uint64(vf.Id)
pr.PeerAsn = uint64(vf.PeerAsn)
pr.Vlan = uint64(vf.Vlan)
return nil
}

type MegaportCharges struct {
Currency string
DailyRate float64
Expand Down
13 changes: 12 additions & 1 deletion megaport/resource_megaport_aws_vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ func resourceMegaportVxcAwsEndElem() *schema.Resource {
}
}

func flattenVxcEndAws(v api.ProductAssociatedVxcEnd, r api.ProductAssociatedVxcResources) []interface{} {
return []interface{}{map[string]interface{}{
"product_uid": v.ProductUid,
"aws_account_id": r.AwsVirtualInterface.OwnerAccount,
"customer_asn": int(r.AwsVirtualInterface.Asn),
"bgp_auth_key": r.AwsVirtualInterface.AuthKey,
}}
}

func resourceMegaportAwsVxcRead(d *schema.ResourceData, m interface{}) error {
cfg := m.(*Config)
p, err := cfg.Client.GetCloudVxc(d.Id())
Expand All @@ -89,7 +98,9 @@ func resourceMegaportAwsVxcRead(d *schema.ResourceData, m interface{}) error {
d.Set("name", p.ProductName)
d.Set("rate_limit", p.RateLimit)
d.Set("a_end", flattenVxcEnd(p.AEnd))
d.Set("b_end", flattenVxcEnd(p.BEnd))
if err := d.Set("b_end", flattenVxcEndAws(p.BEnd, p.Resources)); err != nil {
return err
}
d.Set("invoice_reference", p.CostCentre)
return nil
}
Expand Down

0 comments on commit b46c24d

Please sign in to comment.