diff --git a/builtin/providers/ns1/resource_record_test.go b/builtin/providers/ns1/resource_record_test.go index 36095b579..ec5075303 100644 --- a/builtin/providers/ns1/resource_record_test.go +++ b/builtin/providers/ns1/resource_record_test.go @@ -29,7 +29,7 @@ func TestAccRecord_basic(t *testing.T) { testAccCheckRecordUseClientSubnet(&record, true), testAccCheckRecordRegionName(&record, []string{"cal"}), // testAccCheckRecordAnswerMetaWeight(&record, 10), - testAccCheckRecordAnswerRdata(&record, "test1.terraform-record-test.io"), + testAccCheckRecordAnswerRdata(&record, 0, "test1.terraform-record-test.io"), ), }, }, @@ -52,7 +52,7 @@ func TestAccRecord_updated(t *testing.T) { testAccCheckRecordUseClientSubnet(&record, true), testAccCheckRecordRegionName(&record, []string{"cal"}), // testAccCheckRecordAnswerMetaWeight(&record, 10), - testAccCheckRecordAnswerRdata(&record, "test1.terraform-record-test.io"), + testAccCheckRecordAnswerRdata(&record, 0, "test1.terraform-record-test.io"), ), }, resource.TestStep{ @@ -64,7 +64,7 @@ func TestAccRecord_updated(t *testing.T) { testAccCheckRecordUseClientSubnet(&record, false), testAccCheckRecordRegionName(&record, []string{"ny", "wa"}), // testAccCheckRecordAnswerMetaWeight(&record, 5), - testAccCheckRecordAnswerRdata(&record, "test2.terraform-record-test.io"), + testAccCheckRecordAnswerRdata(&record, 0, "test2.terraform-record-test.io"), ), }, }, @@ -85,7 +85,31 @@ func TestAccRecord_SPF(t *testing.T) { testAccCheckRecordDomain(&record, "terraform-record-test.io"), testAccCheckRecordTTL(&record, 86400), testAccCheckRecordUseClientSubnet(&record, true), - testAccCheckRecordAnswerRdata(&record, "v=DKIM1; k=rsa; p=XXXXXXXX"), + testAccCheckRecordAnswerRdata(&record, 0, "v=DKIM1; k=rsa; p=XXXXXXXX"), + ), + }, + }, + }) +} + +func TestAccRecord_SRV(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: testAccRecordSRV, + Check: resource.ComposeTestCheckFunc( + testAccCheckRecordExists("ns1_record.srv", &record), + testAccCheckRecordDomain(&record, "_some-server._tcp.terraform-record-test.io"), + testAccCheckRecordTTL(&record, 86400), + testAccCheckRecordUseClientSubnet(&record, true), + testAccCheckRecordAnswerRdata(&record, 0, "10"), + testAccCheckRecordAnswerRdata(&record, 1, "0"), + testAccCheckRecordAnswerRdata(&record, 2, "2380"), + testAccCheckRecordAnswerRdata(&record, 3, "node-1.terraform-record-test.io"), ), }, }, @@ -206,12 +230,12 @@ func testAccCheckRecordAnswerMetaWeight(r *dns.Record, expected float64) resourc } } -func testAccCheckRecordAnswerRdata(r *dns.Record, expected string) resource.TestCheckFunc { +func testAccCheckRecordAnswerRdata(r *dns.Record, idx int, expected string) resource.TestCheckFunc { return func(s *terraform.State) error { recordAnswer := r.Answers[0] - recordAnswerString := recordAnswer.Rdata[0] + recordAnswerString := recordAnswer.Rdata[idx] if recordAnswerString != expected { - return fmt.Errorf("Answers[0].Rdata[0]: got: %#v want: %#v", recordAnswerString, expected) + return fmt.Errorf("Answers[0].Rdata[%d]: got: %#v want: %#v", idx, recordAnswerString, expected) } return nil } @@ -335,3 +359,20 @@ resource "ns1_zone" "test" { zone = "terraform-record-test.io" } ` + +const testAccRecordSRV = ` +resource "ns1_record" "srv" { + zone = "${ns1_zone.test.zone}" + domain = "_some-server._tcp.${ns1_zone.test.zone}" + type = "SRV" + ttl = 86400 + use_client_subnet = "true" + answers { + answer = "10 0 2380 node-1.${ns1_zone.test.zone}" + } +} + +resource "ns1_zone" "test" { + zone = "terraform-record-test.io" +} +` diff --git a/website/source/docs/providers/ns1/r/record.html.markdown b/website/source/docs/providers/ns1/r/record.html.markdown index fb03a78f5..9b7148b84 100644 --- a/website/source/docs/providers/ns1/r/record.html.markdown +++ b/website/source/docs/providers/ns1/r/record.html.markdown @@ -51,16 +51,38 @@ The following arguments are supported: * `ttl` - (Optional) The records' time to live. * `link` - (Optional) The target record to link to. This means this record is a 'linked' record, and it inherits all properties from its target. * `use_client_subnet` - (Optional) Whether to use EDNS client subnet data when available(in filter chain). -* `answers` - (Optional) The list of the RDATA fields for the records' specified type. Answers are documented below. -* `filters` - (Optional) The list of NS1 filters for the record(order matters). Filters are documented below. +* `answers` - (Optional) One or more NS1 answers for the records' specified type. Answers are documented below. +* `filters` - (Optional) One or more NS1 filters for the record(order matters). Filters are documented below. Answers (`answers`) support the following: -* `answer` - (Required) List of RDATA fields. -* `region` - (Required) The region this answer belongs to. +* `answer` - (Required) Space delimited string of RDATA fields dependent on the record type. + + A: + + answer = "1.2.3.4" + + CNAME: + + answer = "www.example.com" + + MX: + + answer = "5 mail.example.com" + + SRV: + + answer = "10 0 2380 node-1.example.com" + + SPF: + + answer = "v=DKIM1; k=rsa; p=XXXXXXXX" + + +* `region` - (Optional) The region(or group) name that this answer belongs to. Filters (`filters`) support the following: * `filter` - (Required) The type of filter. -* `disabled` - (Required) Determines whether the filter is applied in the filter chain. -* `config` - (Required) The filters' configuration. Simple key/value pairs determined by the filter type. +* `disabled` - (Optional) Determines whether the filter is applied in the filter chain. +* `config` - (Optional) The filters' configuration. Simple key/value pairs determined by the filter type.