diff --git a/builtin/providers/dnsimple/resource_dnsimple_record.go b/builtin/providers/dnsimple/resource_dnsimple_record.go index 4a9f7aa2e..a5e39472c 100644 --- a/builtin/providers/dnsimple/resource_dnsimple_record.go +++ b/builtin/providers/dnsimple/resource_dnsimple_record.go @@ -58,6 +58,7 @@ func resourceDNSimpleRecord() *schema.Resource { "priority": { Type: schema.TypeString, Computed: true, + Optional: true, }, }, } @@ -76,6 +77,10 @@ func resourceDNSimpleRecordCreate(d *schema.ResourceData, meta interface{}) erro newRecord.TTL, _ = strconv.Atoi(attr.(string)) } + if attr, ok := d.GetOk("priority"); ok { + newRecord.Priority, _ = strconv.Atoi(attr.(string)) + } + log.Printf("[DEBUG] DNSimple Record create configuration: %#v", newRecord) resp, err := provider.client.Zones.CreateRecord(provider.config.Account, d.Get("domain").(string), newRecord) @@ -142,6 +147,10 @@ func resourceDNSimpleRecordUpdate(d *schema.ResourceData, meta interface{}) erro updateRecord.TTL, _ = strconv.Atoi(attr.(string)) } + if attr, ok := d.GetOk("priority"); ok { + updateRecord.Priority, _ = strconv.Atoi(attr.(string)) + } + log.Printf("[DEBUG] DNSimple Record update configuration: %#v", updateRecord) _, err = provider.client.Zones.UpdateRecord(provider.config.Account, d.Get("domain").(string), recordID, updateRecord) diff --git a/builtin/providers/dnsimple/resource_dnsimple_record_test.go b/builtin/providers/dnsimple/resource_dnsimple_record_test.go index 7195ba2c4..e7e5e876f 100644 --- a/builtin/providers/dnsimple/resource_dnsimple_record_test.go +++ b/builtin/providers/dnsimple/resource_dnsimple_record_test.go @@ -37,6 +37,33 @@ func TestAccDNSimpleRecord_Basic(t *testing.T) { }) } +func TestAccDNSimpleRecord_CreateMxWithPriority(t *testing.T) { + var record dnsimple.ZoneRecord + domain := os.Getenv("DNSIMPLE_DOMAIN") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDNSimpleRecordDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: fmt.Sprintf(testAccCheckDNSimpleRecordConfig_mx, domain), + Check: resource.ComposeTestCheckFunc( + testAccCheckDNSimpleRecordExists("dnsimple_record.foobar", &record), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "name", ""), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "domain", domain), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "value", "mx.example.com"), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "priority", "5"), + ), + }, + }, + }) +} + func TestAccDNSimpleRecord_Updated(t *testing.T) { var record dnsimple.ZoneRecord domain := os.Getenv("DNSIMPLE_DOMAIN") @@ -76,6 +103,47 @@ func TestAccDNSimpleRecord_Updated(t *testing.T) { }) } +func TestAccDNSimpleRecord_UpdatedMx(t *testing.T) { + var record dnsimple.ZoneRecord + domain := os.Getenv("DNSIMPLE_DOMAIN") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDNSimpleRecordDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: fmt.Sprintf(testAccCheckDNSimpleRecordConfig_mx, domain), + Check: resource.ComposeTestCheckFunc( + testAccCheckDNSimpleRecordExists("dnsimple_record.foobar", &record), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "name", ""), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "domain", domain), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "value", "mx.example.com"), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "priority", "5"), + ), + }, + resource.TestStep{ + Config: fmt.Sprintf(testAccCheckDNSimpleRecordConfig_mx_new_value, domain), + Check: resource.ComposeTestCheckFunc( + testAccCheckDNSimpleRecordExists("dnsimple_record.foobar", &record), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "name", ""), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "domain", domain), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "value", "mx2.example.com"), + resource.TestCheckResourceAttr( + "dnsimple_record.foobar", "priority", "10"), + ), + }, + }, + }) +} + func testAccCheckDNSimpleRecordDestroy(s *terraform.State) error { provider := testAccProvider.Meta().(*Client) @@ -166,3 +234,25 @@ resource "dnsimple_record" "foobar" { type = "A" ttl = 3600 }` + +const testAccCheckDNSimpleRecordConfig_mx = ` +resource "dnsimple_record" "foobar" { + domain = "%s" + + name = "" + value = "mx.example.com" + type = "MX" + ttl = 3600 + priority = 5 +}` + +const testAccCheckDNSimpleRecordConfig_mx_new_value = ` +resource "dnsimple_record" "foobar" { + domain = "%s" + + name = "" + value = "mx2.example.com" + type = "MX" + ttl = 3600 + priority = 10 +}` diff --git a/website/source/docs/providers/dnsimple/r/record.html.markdown b/website/source/docs/providers/dnsimple/r/record.html.markdown index 18a94d139..addf1be1e 100644 --- a/website/source/docs/providers/dnsimple/r/record.html.markdown +++ b/website/source/docs/providers/dnsimple/r/record.html.markdown @@ -43,6 +43,7 @@ The following arguments are supported: * `value` - (Required) The value of the record * `type` - (Required) The type of the record * `ttl` - (Optional) The TTL of the record +* `priority` - (Optional) The priority of the record - only useful for some record types ## Attributes Reference