From c754882704665edf2febb26fa37e3435135d96e8 Mon Sep 17 00:00:00 2001 From: Thomas Hofmann Date: Tue, 6 Dec 2022 18:51:44 +0100 Subject: [PATCH] ibmcloud: add support for subdomains (#1779) Co-authored-by: Ludovic Fernandez --- providers/dns/ibmcloud/internal/wrapper.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/providers/dns/ibmcloud/internal/wrapper.go b/providers/dns/ibmcloud/internal/wrapper.go index 6129d9c1..dd89d1d4 100644 --- a/providers/dns/ibmcloud/internal/wrapper.go +++ b/providers/dns/ibmcloud/internal/wrapper.go @@ -2,6 +2,7 @@ package internal import ( "fmt" + "strings" "github.com/softlayer/softlayer-go/datatypes" "github.com/softlayer/softlayer-go/services" @@ -66,7 +67,16 @@ func getDomainID(service services.Dns_Domain, domain string) (*int, error) { return r.Id, nil } - return nil, fmt.Errorf("no data found of domain: %s", domain) + // The domain was not found by name. + // For subdomains this is not unusual in softlayer. + // So in case a subdomain like `sub.toplevel.tld` was used try again using the parent domain + // (strip the first part in the domain string -> `toplevel.tld`). + _, parent, found := strings.Cut(domain, ".") + if !found || !strings.Contains(parent, ".") { + return nil, fmt.Errorf("no data found for domain: %s", domain) + } + + return getDomainID(service, parent) } func findTxtRecords(service services.Dns_Domain, fqdn string) ([]datatypes.Dns_Domain_ResourceRecord, error) {