Skip to content
Open
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## 1.5.0 (Unreleased)

FEATURES:
* **Added option to cache PowerDNS API response ** ([#81](https://github.com/pan-net/terraform-provider-powerdns/pull/81), @menai34)
* **Added option to cache PowerDNS API response** ([#81](https://github.com/pan-net/terraform-provider-powerdns/pull/81), @menai34)
* **Fixed resources with upper case names not destroyed** ([#88](https://github.com/pan-net/terraform-provider-powerdns/pull/88), @PetrusHahol)

## 1.4.1 (January 21, 2021)

Expand Down
4 changes: 2 additions & 2 deletions powerdns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func (client *Client) ListRecordsInRRSet(zone string, name string, tpe string) (

records := make([]Record, 0, 10)
for _, r := range allRecords {
if r.Name == name && r.Type == tpe {
if strings.EqualFold(r.Name, name) && r.Type == tpe {
records = append(records, r)
}
}
Expand All @@ -547,7 +547,7 @@ func (client *Client) RecordExists(zone string, name string, tpe string) (bool,
}

for _, record := range allRecords {
if record.Name == name && record.Type == tpe {
if strings.EqualFold(record.Name, name) && record.Type == tpe {
return true, nil
}
}
Expand Down
6 changes: 6 additions & 0 deletions powerdns/resource_powerdns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ func resourcePDNSRecord() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},
},

"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},
},

"type": {
Expand Down
64 changes: 64 additions & 0 deletions powerdns/resource_powerdns_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,52 @@ func TestAccPDNSRecord_SOA(t *testing.T) {
})
}

func TestAccPDNSRecord_A_ZoneMixedCaps(t *testing.T) {
resourceName := "powerdns_record.test-a"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
{
// using mixed caps for zone property to create resource with A type
Config: testPDNSRecordConfigZoneMixedCaps,
},
{
// using A type record config to confirm plan doesn't generate diff
ResourceName: resourceName,
Config: testPDNSRecordConfigA,
ExpectNonEmptyPlan: false,
PlanOnly: true,
},
},
})
}

func TestAccPDNSRecord_A_NameMixedCaps(t *testing.T) {
resourceName := "powerdns_record.test-a"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
{
// using mixed caps for name property to create resource with A type
Config: testPDNSRecordConfigNameMixedCaps,
},
{
// using A type record config to confirm plan doesn't generate diff
ResourceName: resourceName,
Config: testPDNSRecordConfigA,
ExpectNonEmptyPlan: false,
PlanOnly: true,
},
},
})
}

func testAccCheckPDNSRecordDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "powerdns_record" {
Expand Down Expand Up @@ -654,3 +700,21 @@ resource "powerdns_record" "test-soa" {
ttl = 3600
records = [ "something.something. hostmaster.sysa.xyz. 2019090301 10800 3600 604800 3600" ]
}`

const testPDNSRecordConfigZoneMixedCaps = `
resource "powerdns_record" "test-a" {
zone = "sySa.xyz."
name = "testpdnsrecordconfiga.sysa.xyz."
type = "A"
ttl = 60
records = [ "1.1.1.1", "2.2.2.2" ]
}`

const testPDNSRecordConfigNameMixedCaps = `
resource "powerdns_record" "test-a" {
zone = "sysa.xyz."
name = "TestPDNSRecordConfigA.sysa.xyz."
type = "A"
ttl = 60
records = [ "1.1.1.1", "2.2.2.2" ]
}`
3 changes: 3 additions & 0 deletions powerdns/resource_powerdns_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func resourcePDNSZone() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},
},

"kind": {
Expand Down
32 changes: 31 additions & 1 deletion powerdns/resource_powerdns_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestAccPDNSZoneNativeSmallCaps(t *testing.T) {
CheckDestroy: testAccCheckPDNSZoneDestroy,
Steps: []resource.TestStep{
{
// using small caps config to create resource with test-native name
// using small caps config to create resource with test-native kind
Config: testPDNSZoneConfigNativeSmallCaps,
},
{
Expand All @@ -80,6 +80,29 @@ func TestAccPDNSZoneNativeSmallCaps(t *testing.T) {
})
}

func TestAccPDNSZoneNativeNameMixedCaps(t *testing.T) {
resourceName := "powerdns_zone.test-native"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSZoneDestroy,
Steps: []resource.TestStep{
{
// using mixed caps config to create resource with test-native name
Config: testPDNSZoneConfigNativeNameMixedCaps,
},
{
// using test-native config with Native to confirm plan doesn't generate diff
ResourceName: resourceName,
Config: testPDNSZoneConfigNative,
ExpectNonEmptyPlan: false,
PlanOnly: true,
},
},
})
}

func TestAccPDNSZoneMaster(t *testing.T) {
resourceName := "powerdns_zone.test-master"

Expand Down Expand Up @@ -444,6 +467,13 @@ resource "powerdns_zone" "test-native" {
nameservers = ["ns1.sysa.abc.", "ns2.sysa.abc."]
}`

const testPDNSZoneConfigNativeNameMixedCaps = `
resource "powerdns_zone" "test-native" {
name = "sySa.abc."
kind = "native"
nameservers = ["ns1.sysa.abc.", "ns2.sysa.abc."]
}`

const testPDNSZoneConfigMaster = `
resource "powerdns_zone" "test-master" {
name = "master.sysa.abc."
Expand Down