@@ -40,7 +40,10 @@ type API interface {
4040 GetDNSZones (ctx context.Context , publish types.PublishingStrategy ) ([]DNSZoneResponse , error )
4141 GetDNSInstancePermittedNetworks (ctx context.Context , dnsID string , dnsZone string ) ([]string , error )
4242 GetDNSCustomResolverIP (ctx context.Context , dnsID string , vpcID string ) (string , error )
43+ CreateDNSCustomResolver (ctx context.Context , name string , dnsID string , vpcID string ) (* dnssvcsv1.CustomResolver , error )
44+ EnableDNSCustomResolver (ctx context.Context , dnsID string , resolverID string ) (* dnssvcsv1.CustomResolver , error )
4345 CreateDNSRecord (ctx context.Context , publish types.PublishingStrategy , crnstr string , baseDomain string , hostname string , cname string ) error
46+ AddVPCToPermittedNetworks (ctx context.Context , vpcCRN string , dnsID string , dnsZone string ) error
4447
4548 // VPC
4649 GetVPCByName (ctx context.Context , vpcName string ) (* vpcv1.VPC , error )
@@ -294,6 +297,46 @@ func (c *Client) GetDNSCustomResolverIP(ctx context.Context, dnsID string, vpcID
294297 return "" , fmt .Errorf ("DNS server IP of custom resolver for %q not found" , dnsID )
295298}
296299
300+ // CreateDNSCustomResolver creates a custom resolver associated with the specified VPC in the specified DNS zone.
301+ func (c * Client ) CreateDNSCustomResolver (ctx context.Context , name string , dnsID string , vpcID string ) (* dnssvcsv1.CustomResolver , error ) {
302+ createCustomResolverOptions := c .dnsServicesAPI .NewCreateCustomResolverOptions (dnsID )
303+ createCustomResolverOptions .SetName (name )
304+
305+ subnets , err := c .GetVPCSubnets (ctx , vpcID )
306+ if err != nil {
307+ return nil , err
308+ }
309+
310+ locations := []dnssvcsv1.LocationInput {}
311+ for _ , subnet := range subnets {
312+ location , err := c .dnsServicesAPI .NewLocationInput (* subnet .CRN )
313+ if err != nil {
314+ return nil , err
315+ }
316+ location .Enabled = core .BoolPtr (true )
317+ locations = append (locations , * location )
318+ }
319+ createCustomResolverOptions .SetLocations (locations )
320+
321+ customResolver , _ , err := c .dnsServicesAPI .CreateCustomResolverWithContext (ctx , createCustomResolverOptions )
322+ if err != nil {
323+ return nil , err
324+ }
325+ return customResolver , nil
326+ }
327+
328+ // EnableDNSCustomResolver enables a specified custom resolver.
329+ func (c * Client ) EnableDNSCustomResolver (ctx context.Context , dnsID string , resolverID string ) (* dnssvcsv1.CustomResolver , error ) {
330+ updateCustomResolverOptions := c .dnsServicesAPI .NewUpdateCustomResolverOptions (dnsID , resolverID )
331+ updateCustomResolverOptions .SetEnabled (true )
332+
333+ customResolver , _ , err := c .dnsServicesAPI .UpdateCustomResolverWithContext (ctx , updateCustomResolverOptions )
334+ if err != nil {
335+ return nil , err
336+ }
337+ return customResolver , nil
338+ }
339+
297340// GetDNSZoneIDByName gets the CIS zone ID from its domain name.
298341func (c * Client ) GetDNSZoneIDByName (ctx context.Context , name string , publish types.PublishingStrategy ) (string , error ) {
299342 zones , err := c .GetDNSZones (ctx , publish )
@@ -415,6 +458,24 @@ func (c *Client) GetDNSInstancePermittedNetworks(ctx context.Context, dnsID stri
415458 return networks , nil
416459}
417460
461+ // AddVPCToPermittedNetworks adds the specified VPC to the specified DNS zone.
462+ func (c * Client ) AddVPCToPermittedNetworks (ctx context.Context , vpcCRN string , dnsID string , dnsZone string ) error {
463+ createPermittedNetworkOptions := c .dnsServicesAPI .NewCreatePermittedNetworkOptions (dnsID , dnsZone )
464+ permittedNetwork , err := c .dnsServicesAPI .NewPermittedNetworkVpc (vpcCRN )
465+ if err != nil {
466+ return err
467+ }
468+
469+ createPermittedNetworkOptions .SetPermittedNetwork (permittedNetwork )
470+ createPermittedNetworkOptions .SetType ("vpc" )
471+
472+ _ , _ , err = c .dnsServicesAPI .CreatePermittedNetworkWithContext (ctx , createPermittedNetworkOptions )
473+ if err != nil {
474+ return err
475+ }
476+ return nil
477+ }
478+
418479// CreateDNSRecord Creates a DNS CNAME record in the given base domain and CRN.
419480func (c * Client ) CreateDNSRecord (ctx context.Context , publish types.PublishingStrategy , crnstr string , baseDomain string , hostname string , cname string ) error {
420481 switch publish {
0 commit comments