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