Skip to content

Commit 95ba956

Browse files
committed
fix(webhosting): normalize apex DNS record names
1 parent e9e8231 commit 95ba956

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
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 {

internal/services/webhosting/webhosting_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ func TestAccWebhosting_Basic(t *testing.T) {
3535
resource "scaleway_webhosting" "main" {
3636
offer_id = data.scaleway_webhosting_offer.by_name.offer_id
3737
email = "hashicorp@scaleway.com"
38-
domain = "scaleway.com"
38+
domain = "devtools-tf-tests.scaleway.com"
3939
tags = ["devtools", "provider", "terraform"]
4040
}
4141
`,
4242
Check: resource.ComposeTestCheckFunc(
4343
testAccCheckWebhostingExists(tt, "scaleway_webhosting.main"),
4444
resource.TestCheckResourceAttrPair("scaleway_webhosting.main", "offer_id", "data.scaleway_webhosting_offer.by_name", "offer_id"),
4545
resource.TestCheckResourceAttr("scaleway_webhosting.main", "email", "hashicorp@scaleway.com"),
46-
resource.TestCheckResourceAttr("scaleway_webhosting.main", "domain", "scaleway.com"),
46+
resource.TestCheckResourceAttr("scaleway_webhosting.main", "domain", "devtools-tf-tests.scaleway.com"),
4747
resource.TestCheckResourceAttr("scaleway_webhosting.main", "status", webhostingSDK.HostingStatusReady.String()),
4848
resource.TestCheckResourceAttr("scaleway_webhosting.main", "tags.0", "devtools"),
4949
resource.TestCheckResourceAttr("scaleway_webhosting.main", "tags.1", "provider"),

0 commit comments

Comments
 (0)