diff --git a/internal/services/domain/helpers.go b/internal/services/domain/helpers.go index 428b01f8f1..3d7d84ce5b 100644 --- a/internal/services/domain/helpers.go +++ b/internal/services/domain/helpers.go @@ -32,17 +32,29 @@ func getRecordFromTypeAndData(dnsType domain.RecordType, data string, records [] var currentRecord *domain.Record for _, r := range records { - flattedData := flattenDomainData(strings.ToLower(r.Data), r.Type).(string) - flattenCurrentData := flattenDomainData(strings.ToLower(data), r.Type).(string) + flattedData := FlattenDomainData(strings.ToLower(r.Data), r.Type).(string) + flattenCurrentData := FlattenDomainData(strings.ToLower(data), r.Type).(string) - if strings.HasPrefix(flattedData, flattenCurrentData) && r.Type == dnsType { - if currentRecord != nil { - return nil, errors.New("multiple records found with same type and data") + if dnsType == domain.RecordTypeSRV { + if flattedData == flattenCurrentData { + if currentRecord != nil { + return nil, fmt.Errorf("multiple records found with same type and data: existing record %s (ID: %s) conflicts with new record data %s", currentRecord.Data, currentRecord.ID, data) + } + + currentRecord = r + + break } + } else { + if strings.HasPrefix(flattedData, flattenCurrentData) && r.Type == dnsType { + if currentRecord != nil { + return nil, fmt.Errorf("multiple records found with same type and data: existing record %s (ID: %s) conflicts with new record data %s", currentRecord.Data, currentRecord.ID, data) + } - currentRecord = r + currentRecord = r - break + break + } } } diff --git a/internal/services/domain/record.go b/internal/services/domain/record.go index 6ff111e572..95a3c4ee9e 100644 --- a/internal/services/domain/record.go +++ b/internal/services/domain/record.go @@ -296,7 +296,7 @@ func resourceRecordCreate(ctx context.Context, d *schema.ResourceData, m any) di return diag.FromErr(err) } - currentRecord, err := getRecordFromTypeAndData(recordType, recordData, dnsZoneData.Records) + currentRecord, err := getRecordFromTypeAndData(recordType, FlattenDomainData(recordData, recordType).(string), dnsZoneData.Records) if err != nil { return diag.FromErr(err) } @@ -408,7 +408,7 @@ func resourceDomainRecordRead(ctx context.Context, d *schema.ResourceData, m any _ = d.Set("dns_zone", dnsZone) _ = d.Set("name", record.Name) _ = d.Set("type", record.Type.String()) - _ = d.Set("data", flattenDomainData(record.Data, record.Type).(string)) + _ = d.Set("data", FlattenDomainData(record.Data, record.Type).(string)) _ = d.Set("ttl", int(record.TTL)) _ = d.Set("priority", int(record.Priority)) _ = d.Set("geo_ip", flattenDomainGeoIP(record.GeoIPConfig)) diff --git a/internal/services/domain/record_test.go b/internal/services/domain/record_test.go index fc6230a190..f4a8f67210 100644 --- a/internal/services/domain/record_test.go +++ b/internal/services/domain/record_test.go @@ -692,6 +692,72 @@ func TestAccDomainRecord_SRVZone(t *testing.T) { }) } +func TestAccDomainRecord_SRVWithDomainDuplication(t *testing.T) { + tt := acctest.NewTestTools(t) + defer tt.Cleanup() + + testDNSZone := "test-srv-duplication." + acctest.TestDomain + logging.L.Debugf("TestAccDomainRecord_SRVWithDomainDuplication: test dns zone: %s", testDNSZone) + + name := "_test_srv_bug" + recordType := "SRV" + data := "0 0 1234 foo.example.com." + ttl := 60 + priority := 0 + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProviderFactories: tt.ProviderFactories, + CheckDestroy: testAccCheckDomainRecordDestroy(tt), + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf(` + resource "scaleway_domain_record" "srv_test" { + dns_zone = "%[1]s" + name = "%[2]s" + type = "%[3]s" + data = "%[4]s" + priority = %[5]d + ttl = %[6]d + } + `, testDNSZone, name, recordType, data, priority, ttl), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainRecordExists(tt, "scaleway_domain_record.srv_test"), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "dns_zone", testDNSZone), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "name", name), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "type", recordType), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "data", "0 0 1234 foo.example.com."), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "ttl", strconv.Itoa(ttl)), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "priority", strconv.Itoa(priority)), + acctest.CheckResourceAttrUUID("scaleway_domain_record.srv_test", "id"), + ), + }, + { + Config: fmt.Sprintf(` + resource "scaleway_domain_record" "srv_test" { + dns_zone = "%[1]s" + name = "%[2]s" + type = "%[3]s" + data = "10 0 5678 bar.example.com." + priority = 10 + ttl = 300 + } + `, testDNSZone, name, recordType), + Check: resource.ComposeTestCheckFunc( + testAccCheckDomainRecordExists(tt, "scaleway_domain_record.srv_test"), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "dns_zone", testDNSZone), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "name", name), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "type", recordType), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "data", "10 0 5678 bar.example.com."), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "ttl", "300"), + resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "priority", "10"), + acctest.CheckResourceAttrUUID("scaleway_domain_record.srv_test", "id"), + ), + }, + }, + }) +} + func testAccCheckDomainRecordExists(tt *acctest.TestTools, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] diff --git a/internal/services/domain/testdata/domain-record-srv-with-domain-duplication.cassette.yaml b/internal/services/domain/testdata/domain-record-srv-with-domain-duplication.cassette.yaml new file mode 100644 index 0000000000..86dfbda048 --- /dev/null +++ b/internal/services/domain/testdata/domain-record-srv-with-domain-duplication.cassette.yaml @@ -0,0 +1,940 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 215 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: '{"changes":[{"add":{"records":[{"data":"0 0 1234 foo.example.com.","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV","comment":null,"id":""}]}}],"return_all_records":false,"disallow_new_zone_creation":false}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 167 + uncompressed: false + body: '{"records":[{"comment":null,"data":"0 0 1234 foo.example.com.","id":"8c8f4c1e-8cc2-4dc2-b730-34b08ecdb762","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}]}' + headers: + Content-Length: + - "167" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:21 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 46b5ebfe-21c9-4973-82a2-1669c25e7955 + status: 200 OK + code: 200 + duration: 4.198144667s + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?name=_test_srv_bug&order_by=name_asc&type=SRV + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 381 + uncompressed: false + body: '{"records":[{"comment":null,"data":"0 0 1234 foo.example.com.test-srv-duplication.scaleway-terraform.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"},{"comment":null,"data":"0 0 1234 foo.example.com.","id":"8c8f4c1e-8cc2-4dc2-b730-34b08ecdb762","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}],"total_count":2}' + headers: + Content-Length: + - "381" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:21 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 714886df-ac64-44c4-bbd3-6a61524bf8b8 + status: 200 OK + code: 200 + duration: 316.176541ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?name=_test_srv_bug&order_by=name_asc&page=1&type=SRV + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 381 + uncompressed: false + body: '{"records":[{"comment":null,"data":"0 0 1234 foo.example.com.test-srv-duplication.scaleway-terraform.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"},{"comment":null,"data":"0 0 1234 foo.example.com.","id":"8c8f4c1e-8cc2-4dc2-b730-34b08ecdb762","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}],"total_count":2}' + headers: + Content-Length: + - "381" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:21 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 503e9642-5792-48a7-bf79-59433ddfef13 + status: 200 OK + code: 200 + duration: 355.19425ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?id=e5ace7ca-ee80-49ec-83cf-a509aec22ca9&name=&order_by=name_asc&page=1&type=unknown + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 227 + uncompressed: false + body: '{"records":[{"comment":null,"data":"0 0 1234 foo.example.com.test-srv-duplication.scaleway-terraform.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}],"total_count":1}' + headers: + Content-Length: + - "227" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:22 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - e5bf280b-8d63-4228-a059-d99d14923706 + status: 200 OK + code: 200 + duration: 376.670375ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=test-srv-duplication.scaleway-terraform.com&domain=&order_by=domain_asc&page=1 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 362 + uncompressed: false + body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv-duplication","updated_at":"2025-08-28T08:44:21Z"}],"total_count":1}' + headers: + Content-Length: + - "362" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:22 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - ea6cba2f-53d2-4b4f-8153-2a6835de7a76 + status: 200 OK + code: 200 + duration: 215.473833ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?name=&order_by=name_asc&type=unknown + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 651 + uncompressed: false + body: '{"records":[{"comment":null,"data":"ns0.dom.scw.cloud.","id":"585a3bdd-e4fc-41e1-a31b-14e6efef15d5","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"ns1.dom.scw.cloud.","id":"5d55fc3f-16d0-42fe-82dd-0aafdd576996","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"0 0 1234 foo.example.com.test-srv-duplication.scaleway-terraform.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"},{"comment":null,"data":"0 0 1234 foo.example.com.","id":"8c8f4c1e-8cc2-4dc2-b730-34b08ecdb762","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}],"total_count":4}' + headers: + Content-Length: + - "651" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:22 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - ff5e946d-3768-42a7-a603-576507b8e5ce + status: 200 OK + code: 200 + duration: 256.639125ms + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?id=e5ace7ca-ee80-49ec-83cf-a509aec22ca9&name=_test_srv_bug&order_by=name_asc&page=1&type=SRV + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 227 + uncompressed: false + body: '{"records":[{"comment":null,"data":"0 0 1234 foo.example.com.test-srv-duplication.scaleway-terraform.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}],"total_count":1}' + headers: + Content-Length: + - "227" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:23 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 6433737b-7c51-4a26-abe4-61f578fc711b + status: 200 OK + code: 200 + duration: 274.149208ms + - id: 7 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=test-srv-duplication.scaleway-terraform.com&domain=&order_by=domain_asc&page=1 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 362 + uncompressed: false + body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv-duplication","updated_at":"2025-08-28T08:44:21Z"}],"total_count":1}' + headers: + Content-Length: + - "362" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:24 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 84297b18-5324-4bcd-a7c6-5202e7bf0d5a + status: 200 OK + code: 200 + duration: 739.464541ms + - id: 8 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?id=e5ace7ca-ee80-49ec-83cf-a509aec22ca9&name=_test_srv_bug&order_by=name_asc&page=1&type=SRV + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 227 + uncompressed: false + body: '{"records":[{"comment":null,"data":"0 0 1234 foo.example.com.test-srv-duplication.scaleway-terraform.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}],"total_count":1}' + headers: + Content-Length: + - "227" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:25 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 1ef0532a-94fe-4d49-8584-9cf55757d4f9 + status: 200 OK + code: 200 + duration: 299.146792ms + - id: 9 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=test-srv-duplication.scaleway-terraform.com&domain=&order_by=domain_asc&page=1 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 362 + uncompressed: false + body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv-duplication","updated_at":"2025-08-28T08:44:21Z"}],"total_count":1}' + headers: + Content-Length: + - "362" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:25 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - c07d1da5-d86e-419a-a2ac-6c726e8eb2a9 + status: 200 OK + code: 200 + duration: 268.728791ms + - id: 10 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 262 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: '{"changes":[{"set":{"id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","records":[{"data":"10 0 5678 bar.example.com.","name":"_test_srv_bug","priority":10,"ttl":300,"type":"SRV","comment":null,"id":""}]}}],"return_all_records":false,"disallow_new_zone_creation":false}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 170 + uncompressed: false + body: '{"records":[{"comment":null,"data":"10 0 5678 bar.example.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":10,"ttl":300,"type":"SRV"}]}' + headers: + Content-Length: + - "170" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:26 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 75ff6ee8-5f2c-4625-8fc2-7e962029b790 + status: 200 OK + code: 200 + duration: 238.58575ms + - id: 11 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?name=_test_srv_bug&order_by=name_asc&type=SRV + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 340 + uncompressed: false + body: '{"records":[{"comment":null,"data":"0 0 1234 foo.example.com.","id":"8c8f4c1e-8cc2-4dc2-b730-34b08ecdb762","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"},{"comment":null,"data":"10 0 5678 bar.example.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":10,"ttl":300,"type":"SRV"}],"total_count":2}' + headers: + Content-Length: + - "340" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:27 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 5a777dc5-1ffe-402e-951e-2a49f923c384 + status: 200 OK + code: 200 + duration: 261.249458ms + - id: 12 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?id=e5ace7ca-ee80-49ec-83cf-a509aec22ca9&name=_test_srv_bug&order_by=name_asc&page=1&type=SRV + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 186 + uncompressed: false + body: '{"records":[{"comment":null,"data":"10 0 5678 bar.example.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":10,"ttl":300,"type":"SRV"}],"total_count":1}' + headers: + Content-Length: + - "186" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:27 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - b8d813d7-326b-4a60-b8ba-ac32367e04c0 + status: 200 OK + code: 200 + duration: 216.967083ms + - id: 13 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=test-srv-duplication.scaleway-terraform.com&domain=&order_by=domain_asc&page=1 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 361 + uncompressed: false + body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"test-srv-duplication","updated_at":"2025-08-28T08:44:27Z"}],"total_count":1}' + headers: + Content-Length: + - "361" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:27 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - b164d6a1-40cd-49e3-b45b-6c5a23a38dcb + status: 200 OK + code: 200 + duration: 276.022834ms + - id: 14 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?name=&order_by=name_asc&type=unknown + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 610 + uncompressed: false + body: '{"records":[{"comment":null,"data":"ns0.dom.scw.cloud.","id":"585a3bdd-e4fc-41e1-a31b-14e6efef15d5","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"ns1.dom.scw.cloud.","id":"5d55fc3f-16d0-42fe-82dd-0aafdd576996","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"0 0 1234 foo.example.com.","id":"8c8f4c1e-8cc2-4dc2-b730-34b08ecdb762","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"},{"comment":null,"data":"10 0 5678 bar.example.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":10,"ttl":300,"type":"SRV"}],"total_count":4}' + headers: + Content-Length: + - "610" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:28 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 0b432026-5e1d-436d-8300-5ef34baf39a7 + status: 200 OK + code: 200 + duration: 258.37625ms + - id: 15 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?id=e5ace7ca-ee80-49ec-83cf-a509aec22ca9&name=_test_srv_bug&order_by=name_asc&page=1&type=SRV + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 186 + uncompressed: false + body: '{"records":[{"comment":null,"data":"10 0 5678 bar.example.com.","id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9","name":"_test_srv_bug","priority":10,"ttl":300,"type":"SRV"}],"total_count":1}' + headers: + Content-Length: + - "186" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:28 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - e161b1e7-a5d6-4bd3-bed1-e76d67c55492 + status: 200 OK + code: 200 + duration: 264.983417ms + - id: 16 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=test-srv-duplication.scaleway-terraform.com&domain=&order_by=domain_asc&page=1 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 361 + uncompressed: false + body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"test-srv-duplication","updated_at":"2025-08-28T08:44:27Z"}],"total_count":1}' + headers: + Content-Length: + - "361" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:29 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 7323b676-869d-41bd-96d9-53107864ac75 + status: 200 OK + code: 200 + duration: 271.111833ms + - id: 17 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 132 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: '{"changes":[{"delete":{"id":"e5ace7ca-ee80-49ec-83cf-a509aec22ca9"}}],"return_all_records":false,"disallow_new_zone_creation":false}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records + method: PATCH + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 14 + uncompressed: false + body: '{"records":[]}' + headers: + Content-Length: + - "14" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:30 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 9030154e-5ee0-4330-a20e-5ef96f1256e3 + status: 200 OK + code: 200 + duration: 244.937208ms + - id: 18 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.scaleway.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv-duplication.scaleway-terraform.com/records?name=&order_by=name_asc&type=unknown + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 453 + uncompressed: false + body: '{"records":[{"comment":null,"data":"ns0.dom.scw.cloud.","id":"585a3bdd-e4fc-41e1-a31b-14e6efef15d5","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"ns1.dom.scw.cloud.","id":"5d55fc3f-16d0-42fe-82dd-0aafdd576996","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"0 0 1234 foo.example.com.","id":"8c8f4c1e-8cc2-4dc2-b730-34b08ecdb762","name":"_test_srv_bug","priority":0,"ttl":60,"type":"SRV"}],"total_count":3}' + headers: + Content-Length: + - "453" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 28 Aug 2025 08:44:30 GMT + Server: + - Scaleway API Gateway (fr-par-1;edge01) + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 2817e899-ac23-40f4-9d68-18cacf476faf + status: 200 OK + code: 200 + duration: 233.7665ms diff --git a/internal/services/domain/testdata/domain-record-srv-zone.cassette.yaml b/internal/services/domain/testdata/domain-record-srv-zone.cassette.yaml index 103a8bf61d..02b6f63811 100644 --- a/internal/services/domain/testdata/domain-record-srv-zone.cassette.yaml +++ b/internal/services/domain/testdata/domain-record-srv-zone.cassette.yaml @@ -27,20 +27,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 194 + content_length: 188 uncompressed: false - body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"fbdb94d0-fe8c-40b4-abb2-d612325e305d","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}]}' + body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}]}' headers: Content-Length: - - "194" + - "188" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:10 GMT + - Thu, 28 Aug 2025 07:24:55 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -48,10 +48,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - afbc7792-7747-4ba0-810f-287232f291e4 + - 5b3f71a6-ccec-4d75-8aa5-b1b6ba483a8d status: 200 OK code: 200 - duration: 1.027307292s + duration: 1.234859708s - id: 1 request: proto: HTTP/1.1 @@ -76,20 +76,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 211 + content_length: 204 uncompressed: false - body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"fbdb94d0-fe8c-40b4-abb2-d612325e305d","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' + body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' headers: Content-Length: - - "211" + - "204" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:10 GMT + - Thu, 28 Aug 2025 07:24:55 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -97,10 +97,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - f2f7860f-08a5-4830-bd0b-670f500da5ee + - d820a21b-90e0-490e-89f8-9b39f8729004 status: 200 OK code: 200 - duration: 139.298625ms + duration: 504.770417ms - id: 2 request: proto: HTTP/1.1 @@ -125,20 +125,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 211 + content_length: 204 uncompressed: false - body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"fbdb94d0-fe8c-40b4-abb2-d612325e305d","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' + body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' headers: Content-Length: - - "211" + - "204" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:10 GMT + - Thu, 28 Aug 2025 07:24:56 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -146,10 +146,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - 71b5d4b6-e179-4f35-81b9-316c460703c3 + - f8278058-d39f-46bb-838d-2968b8e93012 status: 200 OK code: 200 - duration: 88.373542ms + duration: 239.821792ms - id: 3 request: proto: HTTP/1.1 @@ -166,7 +166,7 @@ interactions: headers: User-Agent: - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv.scaleway-terraform.com/records?id=fbdb94d0-fe8c-40b4-abb2-d612325e305d&name=&order_by=name_asc&page=1&type=unknown + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv.scaleway-terraform.com/records?id=23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e&name=&order_by=name_asc&page=1&type=unknown method: GET response: proto: HTTP/2.0 @@ -174,20 +174,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 211 + content_length: 204 uncompressed: false - body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"fbdb94d0-fe8c-40b4-abb2-d612325e305d","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' + body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' headers: Content-Length: - - "211" + - "204" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:10 GMT + - Thu, 28 Aug 2025 07:24:56 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -195,10 +195,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - 444930b5-6bce-40f8-a2cb-c9ae1b7a450e + - 19c5dac2-a902-46f9-af29-5ac32042c7a9 status: 200 OK code: 200 - duration: 177.191125ms + duration: 250.111167ms - id: 4 request: proto: HTTP/1.1 @@ -223,20 +223,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 362 + content_length: 350 uncompressed: false - body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv","updated_at":"2025-07-16T12:20:10Z"}],"total_count":1}' + body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv","updated_at":"2025-08-28T07:24:55Z"}],"total_count":1}' headers: Content-Length: - - "362" + - "350" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:10 GMT + - Thu, 28 Aug 2025 07:24:56 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -244,10 +244,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - 3b3069ba-bc25-48de-ad6a-8116951923ba + - 2fa88fc4-457b-4b4c-ba94-6abead3350b1 status: 200 OK code: 200 - duration: 80.29375ms + duration: 380.588125ms - id: 5 request: proto: HTTP/1.1 @@ -272,20 +272,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 495 + content_length: 474 uncompressed: false - body: '{"records":[{"comment":null,"data":"ns0.dom.scw.cloud.","id":"38489364-f311-4f9a-806c-78600931d819","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"ns1.dom.scw.cloud.","id":"00f0570e-98aa-4e02-ad58-6f5548a7664a","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"fbdb94d0-fe8c-40b4-abb2-d612325e305d","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":3}' + body: '{"records":[{"comment":null,"data":"ns0.dom.scw.cloud.","id":"02010150-17e5-489f-a9ae-b8005f763e99","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"ns1.dom.scw.cloud.","id":"12e27922-0805-4056-91e7-b42a30ec5a98","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":3}' headers: Content-Length: - - "495" + - "474" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:11 GMT + - Thu, 28 Aug 2025 07:24:57 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -293,10 +293,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - faf33f97-d5ab-48eb-9268-c9afe6e73998 + - 2c9bfc4e-b56c-4bff-a348-f2ae29176fec status: 200 OK code: 200 - duration: 237.542625ms + duration: 374.968417ms - id: 6 request: proto: HTTP/1.1 @@ -313,7 +313,7 @@ interactions: headers: User-Agent: - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv.scaleway-terraform.com/records?id=fbdb94d0-fe8c-40b4-abb2-d612325e305d&name=_proxy-preproduction._tcp&order_by=name_asc&page=1&type=SRV + url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv.scaleway-terraform.com/records?id=23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e&name=_proxy-preproduction._tcp&order_by=name_asc&page=1&type=SRV method: GET response: proto: HTTP/2.0 @@ -321,20 +321,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 211 + content_length: 204 uncompressed: false - body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"fbdb94d0-fe8c-40b4-abb2-d612325e305d","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' + body: '{"records":[{"comment":null,"data":"100 1 3128 bigbox.example.com.","id":"23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e","name":"_proxy-preproduction._tcp","priority":100,"ttl":3600,"type":"SRV"}],"total_count":1}' headers: Content-Length: - - "211" + - "204" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:12 GMT + - Thu, 28 Aug 2025 07:24:58 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -342,10 +342,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - 181129c2-ba2d-40f1-90ae-333f35b55a92 + - 582f3a74-f91d-490f-aa27-5e3c35e18965 status: 200 OK code: 200 - duration: 93.073667ms + duration: 482.944084ms - id: 7 request: proto: HTTP/1.1 @@ -370,20 +370,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 362 + content_length: 350 uncompressed: false - body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv","updated_at":"2025-07-16T12:20:10Z"}],"total_count":1}' + body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv","updated_at":"2025-08-28T07:24:55Z"}],"total_count":1}' headers: Content-Length: - - "362" + - "350" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:12 GMT + - Thu, 28 Aug 2025 07:24:58 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -391,10 +391,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - f1310440-3699-4cd2-9b5f-b5257af33195 + - 0ce9cd6f-6e9f-45d5-9069-b18f792fdaf4 status: 200 OK code: 200 - duration: 98.608333ms + duration: 378.63275ms - id: 8 request: proto: HTTP/1.1 @@ -406,7 +406,7 @@ interactions: host: api.scaleway.com remote_addr: "" request_uri: "" - body: '{"changes":[{"delete":{"id":"fbdb94d0-fe8c-40b4-abb2-d612325e305d"}}],"return_all_records":false,"disallow_new_zone_creation":false}' + body: '{"changes":[{"delete":{"id":"23aa10c3-8e04-4cc7-9e4c-206d5c4e4b0e"}}],"return_all_records":false,"disallow_new_zone_creation":false}' form: {} headers: Content-Type: @@ -432,9 +432,9 @@ interactions: Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:13 GMT + - Thu, 28 Aug 2025 07:25:00 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -442,10 +442,10 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - 61d95ef1-c7ba-4402-be0c-3b96042967b5 + - 1db8d3b2-b21a-4645-b8e7-dda194c562ee status: 200 OK code: 200 - duration: 128.473042ms + duration: 581.490625ms - id: 9 request: proto: HTTP/1.1 @@ -470,20 +470,20 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 313 + content_length: 299 uncompressed: false - body: '{"records":[{"comment":null,"data":"ns0.dom.scw.cloud.","id":"38489364-f311-4f9a-806c-78600931d819","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"ns1.dom.scw.cloud.","id":"00f0570e-98aa-4e02-ad58-6f5548a7664a","name":"","priority":0,"ttl":1800,"type":"NS"}],"total_count":2}' + body: '{"records":[{"comment":null,"data":"ns0.dom.scw.cloud.","id":"02010150-17e5-489f-a9ae-b8005f763e99","name":"","priority":0,"ttl":1800,"type":"NS"},{"comment":null,"data":"ns1.dom.scw.cloud.","id":"12e27922-0805-4056-91e7-b42a30ec5a98","name":"","priority":0,"ttl":1800,"type":"NS"}],"total_count":2}' headers: Content-Length: - - "313" + - "299" Content-Security-Policy: - default-src 'none'; frame-ancestors 'none' Content-Type: - application/json Date: - - Wed, 16 Jul 2025 12:20:13 GMT + - Thu, 28 Aug 2025 07:25:00 GMT Server: - - Scaleway API Gateway (fr-par-2;edge03) + - Scaleway API Gateway (fr-par-3;edge03) Strict-Transport-Security: - max-age=63072000 X-Content-Type-Options: @@ -491,301 +491,7 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - d31e402d-4062-40ae-b606-e3c1e3b16dcd + - 45fa492b-d2b9-4623-86fc-e8e51e5c2800 status: 200 OK code: 200 - duration: 160.813416ms - - id: 10 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: api.scaleway.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-srv.scaleway-terraform.com&domain=&order_by=domain_asc - method: GET - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 362 - uncompressed: false - body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv","updated_at":"2025-07-16T12:20:13Z"}],"total_count":1}' - headers: - Content-Length: - - "362" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 16 Jul 2025 12:20:13 GMT - Server: - - Scaleway API Gateway (fr-par-2;edge03) - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - e6d5e6f8-0dcd-4079-88eb-b7964ccce78f - status: 200 OK - code: 200 - duration: 84.655916ms - - id: 11 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: api.scaleway.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-srv.scaleway-terraform.com&domain=&order_by=domain_asc - method: GET - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 362 - uncompressed: false - body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv","updated_at":"2025-07-16T12:20:13Z"}],"total_count":1}' - headers: - Content-Length: - - "362" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 16 Jul 2025 12:20:18 GMT - Server: - - Scaleway API Gateway (fr-par-2;edge03) - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - e8933318-ef48-4d53-9ad8-b5fd498f6ca8 - status: 200 OK - code: 200 - duration: 119.971709ms - - id: 12 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: api.scaleway.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-srv.scaleway-terraform.com&domain=&order_by=domain_asc - method: GET - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 362 - uncompressed: false - body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"pending","subdomain":"test-srv","updated_at":"2025-07-16T12:20:13Z"}],"total_count":1}' - headers: - Content-Length: - - "362" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 16 Jul 2025 12:20:23 GMT - Server: - - Scaleway API Gateway (fr-par-2;edge03) - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - 4c7b7ca2-ed3e-42f1-bbe8-ee625550c98b - status: 200 OK - code: 200 - duration: 100.698625ms - - id: 13 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: api.scaleway.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-srv.scaleway-terraform.com&domain=&order_by=domain_asc - method: GET - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 361 - uncompressed: false - body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"test-srv","updated_at":"2025-07-16T12:20:24Z"}],"total_count":1}' - headers: - Content-Length: - - "361" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 16 Jul 2025 12:20:28 GMT - Server: - - Scaleway API Gateway (fr-par-2;edge03) - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - c6808582-b31a-4e65-80bc-c47df6c03d41 - status: 200 OK - code: 200 - duration: 97.452709ms - - id: 14 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: api.scaleway.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv.scaleway-terraform.com?project_id=105bdce1-64c0-48ab-899d-868455867ecf - method: DELETE - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 2 - uncompressed: false - body: '{}' - headers: - Content-Length: - - "2" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 16 Jul 2025 12:20:28 GMT - Server: - - Scaleway API Gateway (fr-par-2;edge03) - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - 895fc51b-9e12-4c0d-890b-f36df13da01d - status: 200 OK - code: 200 - duration: 165.272041ms - - id: 15 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: api.scaleway.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - User-Agent: - - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests - url: https://api.scaleway.com/domain/v2beta1/dns-zones/test-srv.scaleway-terraform.com/records?name=&order_by=name_asc&type=unknown - method: GET - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 33 - uncompressed: false - body: '{"message":"subdomain not found"}' - headers: - Content-Length: - - "33" - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 16 Jul 2025 12:20:28 GMT - Server: - - Scaleway API Gateway (fr-par-2;edge03) - Strict-Transport-Security: - - max-age=63072000 - X-Content-Type-Options: - - nosniff - X-Frame-Options: - - DENY - X-Request-Id: - - 9b4ac104-c632-4c22-91c7-ef8cd9036eb3 - status: 403 Forbidden - code: 403 - duration: 129.817833ms + duration: 466.386208ms diff --git a/internal/services/domain/types.go b/internal/services/domain/types.go index a3bcfaa7dc..d341366a4d 100644 --- a/internal/services/domain/types.go +++ b/internal/services/domain/types.go @@ -8,7 +8,8 @@ import ( "github.com/scaleway/terraform-provider-scaleway/v2/internal/types" ) -func flattenDomainData(data string, recordType domain.RecordType) any { +// FlattenDomainData normalizes domain record data based on record type +func FlattenDomainData(data string, recordType domain.RecordType) any { switch recordType { case domain.RecordTypeMX: // API return this format: "{priority} {data}" dataSplit := strings.SplitN(data, " ", 2) @@ -17,11 +18,59 @@ func flattenDomainData(data string, recordType domain.RecordType) any { } case domain.RecordTypeTXT: return strings.Trim(data, "\"") + case domain.RecordTypeSRV: + return NormalizeSRVData(data) } return data } +// NormalizeSRVData normalizes SRV record data by handling weight field and zone domain suffixes +func NormalizeSRVData(data string) string { + parts := strings.Fields(data) + + if len(parts) >= 4 { + priority, weight, port, target := parts[0], parts[1], parts[2], parts[3] + target = RemoveZoneDomainSuffix(target) + + return strings.Join([]string{priority, weight, port, target}, " ") + } + + if len(parts) == 3 { + priority, port, target := parts[0], parts[1], parts[2] + + return strings.Join([]string{priority, "0", port, target}, " ") + } + + return data +} + +// RemoveZoneDomainSuffix removes the zone domain suffix from a target +func RemoveZoneDomainSuffix(target string) string { + if !strings.Contains(target, ".") { + return target + } + + hadTrailingDot := strings.HasSuffix(target, ".") + + targetParts := strings.Split(strings.TrimSuffix(target, "."), ".") + + switch { + case len(targetParts) > 4: + target = strings.Join(targetParts[:len(targetParts)-3], ".") + case len(targetParts) > 3: + target = strings.Join(targetParts[:len(targetParts)-2], ".") + default: + target = strings.TrimSuffix(target, ".") + } + + if hadTrailingDot { + target += "." + } + + return target +} + func flattenDomainGeoIP(config *domain.RecordGeoIPConfig) any { flattenedResult := []map[string]any{} diff --git a/internal/services/domain/types_test.go b/internal/services/domain/types_test.go new file mode 100644 index 0000000000..ce4af3b055 --- /dev/null +++ b/internal/services/domain/types_test.go @@ -0,0 +1,208 @@ +package domain_test + +import ( + "testing" + + domainSDK "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1" + "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/domain" +) + +func TestFlattenDomainData(t *testing.T) { + tests := []struct { + name string + data string + recordType domainSDK.RecordType + expected string + }{ + { + name: "SRV record with domain duplication", + data: "0 0 1234 foo.noet-ia.com.noet-ia.com.", + recordType: domainSDK.RecordTypeSRV, + expected: "0 0 1234 foo.noet-ia.", + }, + { + name: "SRV record without domain duplication", + data: "0 0 1234 foo.noet-ia.com", + recordType: domainSDK.RecordTypeSRV, + expected: "0 0 1234 foo.noet-ia.com", + }, + { + name: "SRV record with complex domain duplication", + data: "10 5 8080 service.example.com.example.com.", + recordType: domainSDK.RecordTypeSRV, + expected: "10 5 8080 service.example.", + }, + { + name: "SRV record with no duplication pattern", + data: "0 0 1234 foo.bar.com", + recordType: domainSDK.RecordTypeSRV, + expected: "0 0 1234 foo.bar.com", + }, + { + name: "SRV record with trailing dot only", + data: "0 0 1234 foo.example.com.", + recordType: domainSDK.RecordTypeSRV, + expected: "0 0 1234 foo.example.com.", + }, + { + name: "SRV record with real test case", + data: "0 0 1234 foo.example.com.test-srv-duplication.scaleway-terraform.com.", + recordType: domainSDK.RecordTypeSRV, + expected: "0 0 1234 foo.example.com.", + }, + { + name: "SRV record with Terraform data (3 parts)", + data: "0 1234 foo.example.com", + recordType: domainSDK.RecordTypeSRV, + expected: "0 0 1234 foo.example.com", + }, + { + name: "MX record", + data: "10 mail.example.com", + recordType: domainSDK.RecordTypeMX, + expected: "mail.example.com", + }, + { + name: "TXT record", + data: "\"v=spf1 include:_spf.example.com ~all\"", + recordType: domainSDK.RecordTypeTXT, + expected: "v=spf1 include:_spf.example.com ~all", + }, + { + name: "A record", + data: "192.168.1.1", + recordType: domainSDK.RecordTypeA, + expected: "192.168.1.1", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := domain.FlattenDomainData(tt.data, tt.recordType) + if result != tt.expected { + t.Errorf("flattenDomainData(%q, %v) = %q, want %q", tt.data, tt.recordType, result, tt.expected) + } + }) + } +} + +func TestNormalizeSRVData(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + { + name: "SRV with weight 0", + input: "0 0 8080 server.example.com", + expected: "0 0 8080 server.example.com", + }, + { + name: "SRV with weight 1", + input: "0 1 8080 server.example.com", + expected: "0 1 8080 server.example.com", + }, + { + name: "SRV with high weight", + input: "0 100 8080 server.example.com", + expected: "0 100 8080 server.example.com", + }, + { + name: "SRV with priority 10", + input: "10 0 8080 server.example.com", + expected: "10 0 8080 server.example.com", + }, + { + name: "SRV with port 443", + input: "0 0 443 server.example.com", + expected: "0 0 443 server.example.com", + }, + { + name: "SRV with complex target", + input: "0 0 8080 server.subdomain.example.com", + expected: "0 0 8080 server.subdomain", + }, + { + name: "SRV with trailing dot", + input: "0 0 8080 server.example.com.", + expected: "0 0 8080 server.example.com.", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := domain.NormalizeSRVData(tt.input) + if result != tt.expected { + t.Errorf("normalizeSRVData(%q) = %q, want %q", tt.input, result, tt.expected) + } + }) + } +} + +func TestRemoveZoneDomainSuffix(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + { + name: "simple domain", + input: "server.example.com", + expected: "server.example.com", + }, + { + name: "with trailing dot", + input: "server.example.com.", + expected: "server.example.com.", + }, + { + name: "with zone domain duplication", + input: "server.example.com.zone.tld", + expected: "server.example", + }, + { + name: "with zone domain duplication and trailing dot", + input: "server.example.com.zone.tld.", + expected: "server.example.", + }, + { + name: "with complex zone domain duplication", + input: "server.example.com.subdomain.zone.tld", + expected: "server.example.com", + }, + { + name: "with complex zone domain duplication and trailing dot", + input: "server.example.com.subdomain.zone.tld.", + expected: "server.example.com.", + }, + { + name: "no domain duplication pattern", + input: "server.example.com.other.tld", + expected: "server.example", + }, + { + name: "no domain duplication pattern with trailing dot", + input: "server.example.com.other.tld.", + expected: "server.example.", + }, + { + name: "single word", + input: "server", + expected: "server", + }, + { + name: "single word with trailing dot", + input: "server.", + expected: "server.", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := domain.RemoveZoneDomainSuffix(tt.input) + if result != tt.expected { + t.Errorf("removeZoneDomainSuffix(%q) = %q, want %q", tt.input, result, tt.expected) + } + }) + } +}