Skip to content

Commit

Permalink
provider/ns1: No splitting answer on spf records. (#13260)
Browse files Browse the repository at this point in the history
* provider/ns1: No splitting answer on spf records.

* provider/ns1: Adds acctest for SPF records.
  • Loading branch information
pashap authored and radeksimko committed Apr 8, 2017
1 parent e885ab8 commit 8e87b10
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/providers/ns1/resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func resourceDataToRecord(r *dns.Record, d *schema.ResourceData) error {
var a *dns.Answer
v := answer["answer"].(string)
switch d.Get("type") {
case "TXT":
case "TXT", "SPF":
a = dns.NewTXTAnswer(v)
default:
a = dns.NewAnswer(strings.Split(v, " "))
Expand Down
38 changes: 38 additions & 0 deletions builtin/providers/ns1/resource_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ func TestAccRecord_updated(t *testing.T) {
})
}

func TestAccRecord_SPF(t *testing.T) {
var record dns.Record
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRecordSPF,
Check: resource.ComposeTestCheckFunc(
testAccCheckRecordExists("ns1_record.spf", &record),
testAccCheckRecordDomain(&record, "terraform-record-test.io"),
testAccCheckRecordTTL(&record, 86400),
testAccCheckRecordUseClientSubnet(&record, true),
testAccCheckRecordAnswerRdata(&record, "v=DKIM1; k=rsa; p=XXXXXXXX"),
),
},
},
})
}

func testAccCheckRecordExists(n string, record *dns.Record) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -297,3 +318,20 @@ resource "ns1_zone" "test" {
zone = "terraform-record-test.io"
}
`

const testAccRecordSPF = `
resource "ns1_record" "spf" {
zone = "${ns1_zone.test.zone}"
domain = "${ns1_zone.test.zone}"
type = "SPF"
ttl = 86400
use_client_subnet = "true"
answers = {
answer = "v=DKIM1; k=rsa; p=XXXXXXXX"
}
}
resource "ns1_zone" "test" {
zone = "terraform-record-test.io"
}
`

0 comments on commit 8e87b10

Please sign in to comment.