Skip to content

Commit a19f53f

Browse files
committed
feat(vpn-gateway): Fix err msgs and tunnel logic for vpn gateway conn
1 parent 807dfbb commit a19f53f

10 files changed

+306
-247
lines changed

ibm/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ func Provider() *schema.Provider {
609609
"ibm_is_vpn_gateway_connection_local_cidrs": vpc.DataSourceIBMIsVPNGatewayConnectionLocalCidrs(),
610610
"ibm_is_vpn_gateway_connection_peer_cidrs": vpc.DataSourceIBMIsVPNGatewayConnectionPeerCidrs(),
611611
"ibm_is_vpn_gateway_advertised_cidrs": vpc.DataSourceIBMIsVPNGatewayAdvertisedCidrs(),
612+
"ibm_is_vpn_gateway_service_connection": vpc.DataSourceIBMIsVPNGatewayServiceConnection(),
612613
"ibm_is_vpn_gateway_service_connections": vpc.DataSourceIBMIsVPNGatewayServiceConnections(),
613614

614615
"ibm_is_vpc_default_routing_table": vpc.DataSourceIBMISVPCDefaultRoutingTable(),

ibm/service/vpc/data_source_ibm_is_vpn_gateway_advertised_cidrs.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func DataSourceIBMIsVPNGatewayAdvertisedCidrs() *schema.Resource {
3434
ExactlyOneOf: []string{"vpn_gateway_name", "vpn_gateway"},
3535
Description: "The VPN gateway name.",
3636
},
37-
"advertised_cidrs": &schema.Schema{
37+
"advertised_cidrs": {
3838
Type: schema.TypeList,
3939
Required: true,
4040
Description: "The additional CIDRs advertised through any enabled routing protocol (for example, BGP). The routing protocol will advertise routes with these CIDRs and VPC prefixes as route destinations.",
@@ -49,7 +49,9 @@ func DataSourceIBMIsVPNGatewayAdvertisedCidrs() *schema.Resource {
4949
func dataSourceIBMIsVPNGatewayAdvertisedCidrsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
5050
vpcClient, err := meta.(conns.ClientSession).VpcV1API()
5151
if err != nil {
52-
return diag.FromErr(err)
52+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("vpcClient creation failed: %s", err.Error()), "(Data) ibm_is_vpn_gateway_advertised_cidrs", "read")
53+
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
54+
return diag.FromErr(tfErr)
5355
}
5456
vpn_gateway_id := d.Get("vpn_gateway").(string)
5557
vpn_gateway_name := d.Get("vpn_gateway_name").(string)
@@ -65,7 +67,11 @@ func dataSourceIBMIsVPNGatewayAdvertisedCidrsRead(context context.Context, d *sc
6567
}
6668
availableVPNGateways, detail, err := vpcClient.ListVPNGatewaysWithContext(context, listvpnGWOptions)
6769
if err != nil || availableVPNGateways == nil {
68-
return diag.FromErr(fmt.Errorf("[ERROR] Error reading list of VPN Gateways:%s\n%s", err, detail))
70+
if err != nil {
71+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Error reading list of VPN Gateways:%s\n%s", err, detail), "(Data) ibm_is_vpn_gateway_advertised_cidrs", "read")
72+
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
73+
return diag.FromErr(tfErr)
74+
}
6975
}
7076
start = flex.GetNext(availableVPNGateways.Next)
7177
allrecs = append(allrecs, availableVPNGateways.VPNGateways...)
@@ -83,8 +89,9 @@ func dataSourceIBMIsVPNGatewayAdvertisedCidrsRead(context context.Context, d *sc
8389
}
8490
}
8591
if !vpn_gateway_found {
86-
log.Printf("[DEBUG] No vpn gateway found with given name %s", vpn_gateway_name)
87-
return diag.FromErr(fmt.Errorf("No vpn gateway found with given name %s", vpn_gateway_name))
92+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("No vpn gateway found with given name %s", vpn_gateway_name), "(Data) ibm_is_vpn_gateway_advertised_cidrs", "read")
93+
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
94+
return diag.FromErr(tfErr)
8895
}
8996
}
9097

@@ -94,8 +101,9 @@ func dataSourceIBMIsVPNGatewayAdvertisedCidrsRead(context context.Context, d *sc
94101

95102
vpnGatewayAdvertisedCidRs, response, err := vpcClient.ListVPNGatewayAdvertisedCIDRsWithContext(context, listVPNGatewayAdvertisedCIDRsOptions)
96103
if err != nil {
97-
log.Printf("[DEBUG] ListVPNGatewayAdvertisedCIDRsWithContext failed %s\n%s", err, response)
98-
return diag.FromErr(fmt.Errorf("ListVPNGatewayAdvertisedCIDRsWithContext failed %s\n%s", err, response))
104+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("ListVPNGatewayAdvertisedCIDRsWithContext failed %s\n%s", err, response), "(Data) ibm_is_vpn_gateway_advertised_cidrs", "read")
105+
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
106+
return diag.FromErr(tfErr)
99107
}
100108
d.SetId(time.Now().UTC().String())
101109
d.Set("advertised_cidrs", vpnGatewayAdvertisedCidRs.AdvertisedCIDRs)

ibm/service/vpc/data_source_ibm_is_vpn_gateway_connection.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ func DataSourceIBMISVPNGatewayConnection() *schema.Resource {
340340
Description: "The VPN tunnel configuration for this VPN gateway connection (in static route mode).",
341341
Elem: &schema.Resource{
342342
Schema: map[string]*schema.Schema{
343+
"neighbor_ip": {
344+
Type: schema.TypeString,
345+
Computed: true,
346+
Description: "The IP address of the neighbor on the virtual tunnel interface.",
347+
},
348+
"protocol_state": {
349+
Type: schema.TypeString,
350+
Computed: true,
351+
Description: "BGP routing protocol state.",
352+
},
343353
"public_ip_address": {
344354
Type: schema.TypeString,
345355
Computed: true,
@@ -350,6 +360,11 @@ func DataSourceIBMISVPNGatewayConnection() *schema.Resource {
350360
Computed: true,
351361
Description: "The status of the VPN Tunnel.",
352362
},
363+
"tunnel_interface_ip": {
364+
Type: schema.TypeString,
365+
Computed: true,
366+
Description: "The IP address of the virtual tunnel interface.",
367+
},
353368
},
354369
},
355370
},
@@ -914,7 +929,7 @@ func setvpnGatewayConnectionIntfDatasourceData(d *schema.ResourceData, vpn_gatew
914929
}
915930

916931
if vpnGatewayConnection.Tunnels != nil {
917-
err = d.Set("tunnels", dataSourceVPNGatewayConnectionsFlattenDynamicTunnels(vpnGatewayConnection.Tunnels))
932+
err = d.Set("tunnels", dataSourceVPNGatewayConnectionFlattenDynamicTunnels(vpnGatewayConnection.Tunnels))
918933
if err != nil {
919934
return fmt.Errorf("[ERROR] Error setting tunnels %s", err)
920935
}
@@ -1437,3 +1452,33 @@ func PrettifyPrint(result interface{}) string {
14371452
}
14381453
return string(output)
14391454
}
1455+
1456+
func dataSourceVPNGatewayConnectionFlattenDynamicTunnels(result []vpcv1.VPNGatewayConnectionDynamicRouteModeTunnel) (tunnels []map[string]interface{}) {
1457+
for _, tunnelsItem := range result {
1458+
tunnels = append(tunnels, dataSourceVPNGatewayConnectionDynamicTunnelsToMap(tunnelsItem))
1459+
}
1460+
1461+
return tunnels
1462+
}
1463+
1464+
func dataSourceVPNGatewayConnectionDynamicTunnelsToMap(tunnelsItem vpcv1.VPNGatewayConnectionDynamicRouteModeTunnel) (tunnelsMap map[string]interface{}) {
1465+
tunnelsMap = map[string]interface{}{}
1466+
1467+
if tunnelsItem.NeighborIP != nil {
1468+
tunnelsMap["neighbor_ip"] = tunnelsItem.NeighborIP.Address
1469+
}
1470+
if tunnelsItem.ProtocolState != nil {
1471+
tunnelsMap["protocol_state"] = tunnelsItem.ProtocolState
1472+
}
1473+
if tunnelsItem.PublicIP != nil {
1474+
tunnelsMap["public_ip_address"] = tunnelsItem.PublicIP.Address
1475+
}
1476+
if tunnelsItem.Status != nil {
1477+
tunnelsMap["status"] = tunnelsItem.Status
1478+
}
1479+
if tunnelsItem.TunnelInterfaceIP != nil {
1480+
tunnelsMap["tunnel_interface_ip"] = tunnelsItem.TunnelInterfaceIP.Address
1481+
}
1482+
1483+
return tunnelsMap
1484+
}

ibm/service/vpc/data_source_ibm_is_vpn_gateway_connections.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@ func DataSourceIBMISVPNGatewayConnections() *schema.Resource {
266266
Computed: true,
267267
Description: "The status of the VPN Tunnel",
268268
},
269+
"neighbor_ip": {
270+
Type: schema.TypeString,
271+
Computed: true,
272+
Description: "The IP address of the neighbor on the virtual tunnel interface.",
273+
},
274+
"tunnel_interface_ip": {
275+
Type: schema.TypeString,
276+
Computed: true,
277+
Description: "The IP address of the virtual tunnel interface.",
278+
},
279+
"protocol_state": {
280+
Type: schema.TypeString,
281+
Computed: true,
282+
Description: "BGP routing protocol state.",
283+
},
269284
},
270285
},
271286
},
@@ -802,7 +817,7 @@ func dataSourceVPNGatewayConnectionsDynamicTunnelsToMap(tunnelsItem vpcv1.VPNGat
802817
tunnelsMap["status"] = tunnelsItem.Status
803818
}
804819
if tunnelsItem.TunnelInterfaceIP != nil {
805-
tunnelsMap["tunnel_interface_ip"] = tunnelsItem.Status
820+
tunnelsMap["tunnel_interface_ip"] = tunnelsItem.TunnelInterfaceIP.Address
806821
}
807822

808823
return tunnelsMap

0 commit comments

Comments
 (0)