Allow dnsimple_record.priority attribute to be set (#12843)
* Allow priority attribute of dnsimple_record to be set Some DNS record types (like MX) allow a priority to specified, and the ability to do so is important in many environments. This diff will change dnsimple_record.priority from computed to optional, allowing it to be used in terraform configs like so: resource "dnsimple_record" "mx1" { domain = "example.com" name = "" value = "mx1.example.com" type = "MX" priority = "1" } resource "dnsimple_record" "mx2" { domain = "example.com" name = "" value = "mx2.example.com" type = "MX" priority = "2" } * mention new priority attribute of dnsimple_record * add acceptance specs for creating/updating MX records at dnsimple
This commit is contained in:
parent
30bc2d930b
commit
593a0c699b
|
@ -58,6 +58,7 @@ func resourceDNSimpleRecord() *schema.Resource {
|
||||||
"priority": {
|
"priority": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
Optional: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -76,6 +77,10 @@ func resourceDNSimpleRecordCreate(d *schema.ResourceData, meta interface{}) erro
|
||||||
newRecord.TTL, _ = strconv.Atoi(attr.(string))
|
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)
|
log.Printf("[DEBUG] DNSimple Record create configuration: %#v", newRecord)
|
||||||
|
|
||||||
resp, err := provider.client.Zones.CreateRecord(provider.config.Account, d.Get("domain").(string), 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))
|
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)
|
log.Printf("[DEBUG] DNSimple Record update configuration: %#v", updateRecord)
|
||||||
|
|
||||||
_, err = provider.client.Zones.UpdateRecord(provider.config.Account, d.Get("domain").(string), recordID, updateRecord)
|
_, err = provider.client.Zones.UpdateRecord(provider.config.Account, d.Get("domain").(string), recordID, updateRecord)
|
||||||
|
|
|
@ -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) {
|
func TestAccDNSimpleRecord_Updated(t *testing.T) {
|
||||||
var record dnsimple.ZoneRecord
|
var record dnsimple.ZoneRecord
|
||||||
domain := os.Getenv("DNSIMPLE_DOMAIN")
|
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 {
|
func testAccCheckDNSimpleRecordDestroy(s *terraform.State) error {
|
||||||
provider := testAccProvider.Meta().(*Client)
|
provider := testAccProvider.Meta().(*Client)
|
||||||
|
|
||||||
|
@ -166,3 +234,25 @@ resource "dnsimple_record" "foobar" {
|
||||||
type = "A"
|
type = "A"
|
||||||
ttl = 3600
|
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
|
||||||
|
}`
|
||||||
|
|
|
@ -43,6 +43,7 @@ The following arguments are supported:
|
||||||
* `value` - (Required) The value of the record
|
* `value` - (Required) The value of the record
|
||||||
* `type` - (Required) The type of the record
|
* `type` - (Required) The type of the record
|
||||||
* `ttl` - (Optional) The TTL 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
|
## Attributes Reference
|
||||||
|
|
Loading…
Reference in New Issue