From 6886b754253ae083c457694aae39a4834d6461f9 Mon Sep 17 00:00:00 2001 From: Dmytro Aleksandrov Date: Sat, 20 Feb 2016 12:08:43 +0200 Subject: [PATCH] Fix record id parsing for hyphened hostnames (#5228) --- builtin/providers/powerdns/client.go | 8 +++--- .../powerdns/resource_powerdns_record_test.go | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/builtin/providers/powerdns/client.go b/builtin/providers/powerdns/client.go index 058a8cbf1..ca54ac718 100644 --- a/builtin/providers/powerdns/client.go +++ b/builtin/providers/powerdns/client.go @@ -91,17 +91,19 @@ type errorResponse struct { ErrorMsg string `json:"error"` } +const idSeparator string = ":::" + func (record *Record) Id() string { - return fmt.Sprintf("%s-%s", record.Name, record.Type) + return record.Name + idSeparator + record.Type } func (rrSet *ResourceRecordSet) Id() string { - return fmt.Sprintf("%s-%s", rrSet.Name, rrSet.Type) + return rrSet.Name + idSeparator + rrSet.Type } // Returns name and type of record or record set based on it's ID func parseId(recId string) (string, string, error) { - s := strings.Split(recId, "-") + s := strings.Split(recId, idSeparator) if len(s) == 2 { return s[0], s[1], nil } else { diff --git a/builtin/providers/powerdns/resource_powerdns_record_test.go b/builtin/providers/powerdns/resource_powerdns_record_test.go index 44831f263..0953a4c51 100644 --- a/builtin/providers/powerdns/resource_powerdns_record_test.go +++ b/builtin/providers/powerdns/resource_powerdns_record_test.go @@ -24,6 +24,23 @@ func TestAccPDNSRecord_A(t *testing.T) { }) } +func TestAccPDNSRecord_WithCount(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckPDNSRecordDestroy, + Steps: []resource.TestStep{ + { + Config: testPDNSRecordConfigHyphenedWithCount, + Check: resource.ComposeTestCheckFunc( + testAccCheckPDNSRecordExists("powerdns_record.test-counted.0"), + testAccCheckPDNSRecordExists("powerdns_record.test-counted.1"), + ), + }, + }, + }) +} + func TestAccPDNSRecord_AAAA(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -262,6 +279,16 @@ resource "powerdns_record" "test-a" { records = [ "1.1.1.1", "2.2.2.2" ] }` +const testPDNSRecordConfigHyphenedWithCount = ` +resource "powerdns_record" "test-counted" { + count = "2" + zone = "sysa.xyz" + name = "redis-${count.index}.sysa.xyz" + type = "A" + ttl = 60 + records = [ "1.1.1.${count.index}" ] +}` + const testPDNSRecordConfigAAAA = ` resource "powerdns_record" "test-aaaa" { zone = "sysa.xyz"