Skip to content

Commit ee64d24

Browse files
authored
Merge branch 'master' into feat/mnq-sqs-dlq-arn-id-normalization
2 parents 767d66f + 48bdcf8 commit ee64d24

File tree

7 files changed

+1355
-374
lines changed

7 files changed

+1355
-374
lines changed

internal/services/domain/helpers.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,29 @@ func getRecordFromTypeAndData(dnsType domain.RecordType, data string, records []
3232
var currentRecord *domain.Record
3333

3434
for _, r := range records {
35-
flattedData := flattenDomainData(strings.ToLower(r.Data), r.Type).(string)
36-
flattenCurrentData := flattenDomainData(strings.ToLower(data), r.Type).(string)
35+
flattedData := FlattenDomainData(strings.ToLower(r.Data), r.Type).(string)
36+
flattenCurrentData := FlattenDomainData(strings.ToLower(data), r.Type).(string)
3737

38-
if strings.HasPrefix(flattedData, flattenCurrentData) && r.Type == dnsType {
39-
if currentRecord != nil {
40-
return nil, errors.New("multiple records found with same type and data")
38+
if dnsType == domain.RecordTypeSRV {
39+
if flattedData == flattenCurrentData {
40+
if currentRecord != nil {
41+
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)
42+
}
43+
44+
currentRecord = r
45+
46+
break
4147
}
48+
} else {
49+
if strings.HasPrefix(flattedData, flattenCurrentData) && r.Type == dnsType {
50+
if currentRecord != nil {
51+
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)
52+
}
4253

43-
currentRecord = r
54+
currentRecord = r
4455

45-
break
56+
break
57+
}
4658
}
4759
}
4860

internal/services/domain/record.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func resourceRecordCreate(ctx context.Context, d *schema.ResourceData, m any) di
296296
return diag.FromErr(err)
297297
}
298298

299-
currentRecord, err := getRecordFromTypeAndData(recordType, recordData, dnsZoneData.Records)
299+
currentRecord, err := getRecordFromTypeAndData(recordType, FlattenDomainData(recordData, recordType).(string), dnsZoneData.Records)
300300
if err != nil {
301301
return diag.FromErr(err)
302302
}
@@ -408,7 +408,7 @@ func resourceDomainRecordRead(ctx context.Context, d *schema.ResourceData, m any
408408
_ = d.Set("dns_zone", dnsZone)
409409
_ = d.Set("name", record.Name)
410410
_ = d.Set("type", record.Type.String())
411-
_ = d.Set("data", flattenDomainData(record.Data, record.Type).(string))
411+
_ = d.Set("data", FlattenDomainData(record.Data, record.Type).(string))
412412
_ = d.Set("ttl", int(record.TTL))
413413
_ = d.Set("priority", int(record.Priority))
414414
_ = d.Set("geo_ip", flattenDomainGeoIP(record.GeoIPConfig))

internal/services/domain/record_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,72 @@ func TestAccDomainRecord_SRVZone(t *testing.T) {
692692
})
693693
}
694694

695+
func TestAccDomainRecord_SRVWithDomainDuplication(t *testing.T) {
696+
tt := acctest.NewTestTools(t)
697+
defer tt.Cleanup()
698+
699+
testDNSZone := "test-srv-duplication." + acctest.TestDomain
700+
logging.L.Debugf("TestAccDomainRecord_SRVWithDomainDuplication: test dns zone: %s", testDNSZone)
701+
702+
name := "_test_srv_bug"
703+
recordType := "SRV"
704+
data := "0 0 1234 foo.example.com."
705+
ttl := 60
706+
priority := 0
707+
708+
resource.ParallelTest(t, resource.TestCase{
709+
PreCheck: func() { acctest.PreCheck(t) },
710+
ProviderFactories: tt.ProviderFactories,
711+
CheckDestroy: testAccCheckDomainRecordDestroy(tt),
712+
Steps: []resource.TestStep{
713+
{
714+
Config: fmt.Sprintf(`
715+
resource "scaleway_domain_record" "srv_test" {
716+
dns_zone = "%[1]s"
717+
name = "%[2]s"
718+
type = "%[3]s"
719+
data = "%[4]s"
720+
priority = %[5]d
721+
ttl = %[6]d
722+
}
723+
`, testDNSZone, name, recordType, data, priority, ttl),
724+
Check: resource.ComposeTestCheckFunc(
725+
testAccCheckDomainRecordExists(tt, "scaleway_domain_record.srv_test"),
726+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "dns_zone", testDNSZone),
727+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "name", name),
728+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "type", recordType),
729+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "data", "0 0 1234 foo.example.com."),
730+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "ttl", strconv.Itoa(ttl)),
731+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "priority", strconv.Itoa(priority)),
732+
acctest.CheckResourceAttrUUID("scaleway_domain_record.srv_test", "id"),
733+
),
734+
},
735+
{
736+
Config: fmt.Sprintf(`
737+
resource "scaleway_domain_record" "srv_test" {
738+
dns_zone = "%[1]s"
739+
name = "%[2]s"
740+
type = "%[3]s"
741+
data = "10 0 5678 bar.example.com."
742+
priority = 10
743+
ttl = 300
744+
}
745+
`, testDNSZone, name, recordType),
746+
Check: resource.ComposeTestCheckFunc(
747+
testAccCheckDomainRecordExists(tt, "scaleway_domain_record.srv_test"),
748+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "dns_zone", testDNSZone),
749+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "name", name),
750+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "type", recordType),
751+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "data", "10 0 5678 bar.example.com."),
752+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "ttl", "300"),
753+
resource.TestCheckResourceAttr("scaleway_domain_record.srv_test", "priority", "10"),
754+
acctest.CheckResourceAttrUUID("scaleway_domain_record.srv_test", "id"),
755+
),
756+
},
757+
},
758+
})
759+
}
760+
695761
func testAccCheckDomainRecordExists(tt *acctest.TestTools, n string) resource.TestCheckFunc {
696762
return func(s *terraform.State) error {
697763
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)