From b46c24decbc85a417510a3f195aae48b5b915f38 Mon Sep 17 00:00:00 2001 From: Dimitrios Karagiannis Date: Mon, 28 Oct 2019 16:11:30 +0000 Subject: [PATCH] megaport_aws_vxc: handle partner configs Signed-off-by: Dimitrios Karagiannis --- megaport/api/types.go | 57 +++++++++++++++++++++++++++ megaport/resource_megaport_aws_vxc.go | 13 +++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/megaport/api/types.go b/megaport/api/types.go index c47a504..4e838ad 100644 --- a/megaport/api/types.go +++ b/megaport/api/types.go @@ -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 @@ -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 diff --git a/megaport/resource_megaport_aws_vxc.go b/megaport/resource_megaport_aws_vxc.go index 3983526..0911ef0 100644 --- a/megaport/resource_megaport_aws_vxc.go +++ b/megaport/resource_megaport_aws_vxc.go @@ -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()) @@ -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 }