@@ -39,13 +39,15 @@ type API interface {
3939 GetDNSZoneIDByName (ctx context.Context , name string , publish types.PublishingStrategy ) (string , error )
4040 GetDNSZones (ctx context.Context , publish types.PublishingStrategy ) ([]DNSZoneResponse , error )
4141 GetDNSInstancePermittedNetworks (ctx context.Context , dnsID string , dnsZone string ) ([]string , error )
42+ GetDNSCustomResolverIP (ctx context.Context , dnsID string , vpcID string ) (string , error )
4243 CreateDNSRecord (ctx context.Context , crnstr string , baseDomain string , hostname string , cname string ) error
4344
4445 // VPC
4546 GetVPCByName (ctx context.Context , vpcName string ) (* vpcv1.VPC , error )
4647 GetPublicGatewayByVPC (ctx context.Context , vpcName string ) (* vpcv1.PublicGateway , error )
4748 SetVPCServiceURLForRegion (ctx context.Context , region string ) error
4849 GetVPCs (ctx context.Context , region string ) ([]vpcv1.VPC , error )
50+ GetVPCSubnets (ctx context.Context , vpcID string ) ([]vpcv1.Subnet , error )
4951
5052 // TG
5153 GetTGConnectionVPC (ctx context.Context , gatewayID string , vpcSubnetID string ) (string , error )
@@ -253,7 +255,6 @@ func (c *Client) GetDNSRecordsByName(ctx context.Context, crnstr string, zoneID
253255
254256// GetInstanceCRNByName finds the CRN of the instance with the specified name.
255257func (c * Client ) GetInstanceCRNByName (ctx context.Context , name string , publish types.PublishingStrategy ) (string , error ) {
256-
257258 zones , err := c .GetDNSZones (ctx , publish )
258259 if err != nil {
259260 return "" , err
@@ -268,9 +269,33 @@ func (c *Client) GetInstanceCRNByName(ctx context.Context, name string, publish
268269 return "" , fmt .Errorf ("DNS zone %q not found" , name )
269270}
270271
272+ // GetDNSCustomResolverIP gets the DNS Server IP of a custom resolver associated with the specified VPC subnet in the specified DNS zone.
273+ func (c * Client ) GetDNSCustomResolverIP (ctx context.Context , dnsID string , vpcID string ) (string , error ) {
274+ listCustomResolversOptions := c .dnsServicesAPI .NewListCustomResolversOptions (dnsID )
275+ customResolvers , _ , err := c .dnsServicesAPI .ListCustomResolversWithContext (ctx , listCustomResolversOptions )
276+ if err != nil {
277+ return "" , err
278+ }
279+
280+ subnets , err := c .GetVPCSubnets (ctx , vpcID )
281+ if err != nil {
282+ return "" , err
283+ }
284+
285+ for _ , customResolver := range customResolvers .CustomResolvers {
286+ for _ , location := range customResolver .Locations {
287+ for _ , subnet := range subnets {
288+ if * subnet .CRN == * location .SubnetCrn {
289+ return * location .DnsServerIp , nil
290+ }
291+ }
292+ }
293+ }
294+ return "" , fmt .Errorf ("DNS server IP of custom resolver for %q not found" , dnsID )
295+ }
296+
271297// GetDNSZoneIDByName gets the CIS zone ID from its domain name.
272298func (c * Client ) GetDNSZoneIDByName (ctx context.Context , name string , publish types.PublishingStrategy ) (string , error ) {
273-
274299 zones , err := c .GetDNSZones (ctx , publish )
275300 if err != nil {
276301 return "" , err
@@ -372,7 +397,7 @@ func (c *Client) GetDNSZones(ctx context.Context, publish types.PublishingStrate
372397 return allZones , nil
373398}
374399
375- // GetDNSInstancePermittedNetworks gets the permitted VPC networks for a DNS Services instance
400+ // GetDNSInstancePermittedNetworks gets the permitted VPC networks for a DNS Services instance.
376401func (c * Client ) GetDNSInstancePermittedNetworks (ctx context.Context , dnsID string , dnsZone string ) ([]string , error ) {
377402 _ , cancel := context .WithTimeout (ctx , 1 * time .Minute )
378403 defer cancel ()
@@ -510,6 +535,18 @@ func (c *Client) GetPublicGatewayByVPC(ctx context.Context, vpcName string) (*vp
510535 return nil , nil
511536}
512537
538+ // GetVPCSubnets retrieves all subnets in the given VPC.
539+ func (c * Client ) GetVPCSubnets (ctx context.Context , vpcID string ) ([]vpcv1.Subnet , error ) {
540+ listSubnetsOptions := c .vpcAPI .NewListSubnetsOptions ()
541+ listSubnetsOptions .VPCID = & vpcID
542+ subnets , _ , err := c .vpcAPI .ListSubnetsWithContext (ctx , listSubnetsOptions )
543+ if err != nil {
544+ return nil , err
545+ }
546+
547+ return subnets .Subnets , nil
548+ }
549+
513550// GetSubnetByName gets a VPC Subnet by its name and region.
514551func (c * Client ) GetSubnetByName (ctx context.Context , subnetName string , region string ) (* vpcv1.Subnet , error ) {
515552 _ , cancel := context .WithTimeout (ctx , 1 * time .Minute )
0 commit comments