Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shared DNS recordset searching #848

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ func TestAccDNSV2RecordSet_basic(t *testing.T) {
})
}

// TestAccDNSV2RecordSet_childFirst covers #847
func TestAccDNSV2RecordSet_childFirst(t *testing.T) {
zoneName := randomZoneName()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDNSV2RecordSetDestroy,
Steps: []resource.TestStep{
{
Config: testAccDNSV2RecordSet_childFirst1(zoneName),
},
{
Config: testAccDNSV2RecordSet_childFirst2(zoneName),
},
},
})
}

func TestAccDNSV2RecordSet_readTTL(t *testing.T) {
var recordset recordsets.RecordSet
zoneName := randomZoneName()
Expand Down Expand Up @@ -326,3 +344,56 @@ resource "opentelekomcloud_dns_recordset_v2" "recordset_2" {
}
`, zoneName)
}

func testAccDNSV2RecordSet_childFirst1(zoneName string) string {
return fmt.Sprintf(`
resource "opentelekomcloud_dns_zone_v2" "zone_1" {
name = "%[1]s"
email = "email2@example.com"
description = "a zone"
ttl = 6000
}

resource "opentelekomcloud_dns_recordset_v2" "recordset" {
zone_id = opentelekomcloud_dns_zone_v2.zone_1.id
name = "test.test.%[1]s"
type = "A"
description = "a record set"
ttl = 3000
records = ["10.1.0.0"]

tags = {
foo = "bar"
key = "value"
}
}
`, zoneName)
}

func testAccDNSV2RecordSet_childFirst2(zoneName string) string {
return fmt.Sprintf(`
resource "opentelekomcloud_dns_zone_v2" "zone_1" {
name = "%[1]s"
email = "email2@example.com"
description = "a zone"
ttl = 6000
}

resource "opentelekomcloud_dns_recordset_v2" "recordset" {
zone_id = opentelekomcloud_dns_zone_v2.zone_1.id
name = "test.test.%[1]s"
type = "A"
description = "a record set"
ttl = 3000
records = ["10.1.0.0"]
}
resource "opentelekomcloud_dns_recordset_v2" "recordset_sup" {
zone_id = opentelekomcloud_dns_zone_v2.zone_1.id
name = "test.%[1]s"
type = "A"
description = "a parent record set"
ttl = 3000
records = ["10.1.0.0"]
}
`, zoneName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,16 @@ func getExistingRecordSetID(d cfg.SchemaOrDiff, meta interface{}) (id string, er
if err != nil {
return "", fmt.Errorf("error extracting record sets: %s", err)
}
if len(sets) != 0 {
id = sets[0].ID
if len(sets) == 0 {
return
}
for _, set := range sets {
if set.Name == createOpts.Name {
id = set.ID
return
}
}

return
}

Expand Down