Skip to content

Commit 6466535

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

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

internal/services/webhosting/helpers.go

Lines changed: 16 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"
@@ -80,8 +81,13 @@ func waitForHosting(ctx context.Context, api *webhosting.HostingAPI, region scw.
8081
func flattenDNSRecords(records []*webhosting.DNSRecord) []map[string]any {
8182
result := []map[string]any{}
8283
for _, r := range records {
84+
name := r.Name
85+
if name == "" {
86+
name = extractDNSRecordName(r.RawData)
87+
}
88+
8389
result = append(result, map[string]any{
84-
"name": r.Name,
90+
"name": name,
8591
"type": r.Type.String(),
8692
"ttl": r.TTL,
8793
"value": r.Value,
@@ -93,6 +99,15 @@ func flattenDNSRecords(records []*webhosting.DNSRecord) []map[string]any {
9399
return result
94100
}
95101

102+
func extractDNSRecordName(raw string) string {
103+
fields := strings.Fields(raw)
104+
if len(fields) == 0 {
105+
return ""
106+
}
107+
108+
return strings.TrimSuffix(fields[0], ".")
109+
}
110+
96111
func flattenNameServers(servers []*webhosting.Nameserver) []map[string]any {
97112
result := []map[string]any{}
98113
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
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", "[email protected]"),
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)