Skip to content

Commit ff08324

Browse files
authored
fix(webhosting): normalize apex DNS record names (#3457)
1 parent 4562eb2 commit ff08324

File tree

5 files changed

+498
-776
lines changed

5 files changed

+498
-776
lines changed

internal/services/webhosting/helpers.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package webhosting
22

33
import (
44
"context"
5+
"strings"
56
"time"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -79,9 +80,15 @@ func waitForHosting(ctx context.Context, api *webhosting.HostingAPI, region scw.
7980

8081
func flattenDNSRecords(records []*webhosting.DNSRecord) []map[string]any {
8182
result := []map[string]any{}
83+
8284
for _, r := range records {
85+
name := r.Name
86+
if name == "" {
87+
name = extractDNSRecordName(r.RawData)
88+
}
89+
8390
result = append(result, map[string]any{
84-
"name": r.Name,
91+
"name": name,
8592
"type": r.Type.String(),
8693
"ttl": r.TTL,
8794
"value": r.Value,
@@ -93,6 +100,15 @@ func flattenDNSRecords(records []*webhosting.DNSRecord) []map[string]any {
93100
return result
94101
}
95102

103+
func extractDNSRecordName(raw string) string {
104+
fields := strings.Fields(raw)
105+
if len(fields) == 0 {
106+
return ""
107+
}
108+
109+
return strings.TrimSuffix(fields[0], ".")
110+
}
111+
96112
func flattenNameServers(servers []*webhosting.Nameserver) []map[string]any {
97113
result := []map[string]any{}
98114
for _, s := range servers {

0 commit comments

Comments
 (0)