@@ -20,16 +20,16 @@ import (
2020
2121 "github.com/hashicorp/terraform-exec/tfexec"
2222
23- oci_dns "github.com/oracle/oci-go-sdk/v52/dns"
24-
2523 "github.com/hashicorp/hcl2/hclwrite"
2624
2725 "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
2826
2927 oci_core "github.com/oracle/oci-go-sdk/v52/core"
28+ oci_dns "github.com/oracle/oci-go-sdk/v52/dns"
3029 oci_identity "github.com/oracle/oci-go-sdk/v52/identity"
3130 oci_load_balancer "github.com/oracle/oci-go-sdk/v52/loadbalancer"
3231 oci_log_analytics "github.com/oracle/oci-go-sdk/v52/loganalytics"
32+ oci_network_load_balancer "github.com/oracle/oci-go-sdk/v52/networkloadbalancer"
3333 oci_objectstorage "github.com/oracle/oci-go-sdk/v52/objectstorage"
3434)
3535
@@ -829,6 +829,7 @@ func init() {
829829 // Custom overrides for generating composite Network Load Balancer IDs within the resource discovery framework
830830 exportNetworkLoadBalancerBackendHints .processDiscoveredResourcesFn = processNetworkLoadBalancerBackends
831831 exportNetworkLoadBalancerBackendSetHints .processDiscoveredResourcesFn = processNetworkLoadBalancerBackendSets
832+ exportNetworkLoadBalancerListenerHints .findResourcesOverrideFn = findNetworkLoadBalancerListeners
832833 exportNetworkLoadBalancerListenerHints .processDiscoveredResourcesFn = processNetworkLoadBalancerListeners
833834
834835 exportCoreDrgRouteTableRouteRuleHints .datasourceClass = "oci_core_drg_route_table_route_rules"
@@ -1455,6 +1456,68 @@ func processNetworkLoadBalancerBackends(ctx *resourceDiscoveryContext, resources
14551456 return resources , nil
14561457}
14571458
1459+ func findNetworkLoadBalancerListeners (ctx * resourceDiscoveryContext , tfMeta * TerraformResourceAssociation , parent * OCIResource , resourceGraph * TerraformResourceGraph ) ([]* OCIResource , error ) {
1460+ networkLoadBalancerId := parent .sourceAttributes ["network_load_balancer_id" ].(string )
1461+ backendSetName := parent .sourceAttributes ["name" ].(string )
1462+
1463+ request := oci_network_load_balancer.GetNetworkLoadBalancerRequest {}
1464+ request .NetworkLoadBalancerId = & networkLoadBalancerId
1465+ request .RequestMetadata .RetryPolicy = GetRetryPolicy (true , "network_load_balancer" )
1466+
1467+ response , err := ctx .clients .networkLoadBalancerClient ().GetNetworkLoadBalancer (context .Background (), request )
1468+ if err != nil {
1469+ return nil , err
1470+ }
1471+
1472+ listenerResource := resourcesMap [tfMeta .resourceClass ]
1473+
1474+ results := []* OCIResource {}
1475+ for listenerName , listener := range response .NetworkLoadBalancer .Listeners {
1476+ if * listener .DefaultBackendSetName != backendSetName {
1477+ continue
1478+ }
1479+
1480+ d := listenerResource .TestResourceData ()
1481+ d .SetId (getNlbListenerCompositeId (listenerName , networkLoadBalancerId ))
1482+
1483+ // This calls into the listener resource's Read fn which has the unfortunate implementation of
1484+ // calling GetNetworkLoadBalancer and looping through the listeners to find the expected one. So this entire method
1485+ // may require O(n^^2) time. However, the benefits of having Read populate the ResourceData struct is better than duplicating it here.
1486+ if err := listenerResource .Read (d , ctx .clients ); err != nil {
1487+ // add error to the errorList and continue discovering rest of the resources
1488+ rdError := & ResourceDiscoveryError {tfMeta .resourceClass , parent .terraformName , err , resourceGraph }
1489+ ctx .addErrorToList (rdError )
1490+ continue
1491+ }
1492+
1493+ resource := & OCIResource {
1494+ compartmentId : parent .compartmentId ,
1495+ sourceAttributes : convertResourceDataToMap (listenerResource .Schema , d ),
1496+ rawResource : listener ,
1497+ TerraformResource : TerraformResource {
1498+ id : d .Id (),
1499+ terraformClass : tfMeta .resourceClass ,
1500+ terraformName : fmt .Sprintf ("%s_%s" , parent .parent .terraformName , listenerName ),
1501+ },
1502+ getHclStringFn : getHclStringFromGenericMap ,
1503+ parent : parent ,
1504+ }
1505+
1506+ if ! parent .omitFromExport {
1507+ resource .sourceAttributes ["default_backend_set_name" ] = InterpolationString {
1508+ resourceReference : parent .getTerraformReference (),
1509+ interpolation : tfHclVersion .getDoubleExpHclString (parent .getTerraformReference (), "name" ),
1510+ value : parent .sourceAttributes ["name" ].(string ),
1511+ }
1512+ } else {
1513+ resource .sourceAttributes ["default_backend_set_name" ] = parent .sourceAttributes ["name" ].(string )
1514+ }
1515+ results = append (results , resource )
1516+ }
1517+
1518+ return results , nil
1519+ }
1520+
14581521func processNetworkLoadBalancerListeners (ctx * resourceDiscoveryContext , resources []* OCIResource ) ([]* OCIResource , error ) {
14591522 for _ , listener := range resources {
14601523 if listener .parent == nil {
0 commit comments