providers/digitalocean: force fqdn in dns rr value
Fixes a bug that forces DNS record to be recreated when dealing with records that have domain values (CNAME, MX, NS, etc.)
This commit is contained in:
parent
c294ce323c
commit
3565ae034e
|
@ -68,10 +68,18 @@ func resourceDigitalOceanRecord() *schema.Resource {
|
|||
func resourceDigitalOceanRecordCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*digitalocean.Client)
|
||||
|
||||
rrValue := d.Get("value").(string)
|
||||
// Ensure all records with domain value are absolute (ending with dot)
|
||||
if t := d.Get("type").(string); t == "CNAME" || t == "MX" || t == "NS" || t == "SRV" {
|
||||
if rrValue[len(rrValue)-1] != '.' {
|
||||
rrValue += "."
|
||||
}
|
||||
}
|
||||
|
||||
newRecord := digitalocean.CreateRecord{
|
||||
Type: d.Get("type").(string),
|
||||
Name: d.Get("name").(string),
|
||||
Data: d.Get("value").(string),
|
||||
Data: rrValue,
|
||||
Priority: d.Get("priority").(string),
|
||||
Port: d.Get("port").(string),
|
||||
Weight: d.Get("weight").(string),
|
||||
|
|
|
@ -76,6 +76,33 @@ func TestAccDigitalOceanRecord_Updated(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccDigitalOceanRecord_HostnameValue(t *testing.T) {
|
||||
var record digitalocean.Record
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckDigitalOceanRecordDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccCheckDigitalOceanRecordConfig_cname,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckDigitalOceanRecordExists("digitalocean_record.foobar", &record),
|
||||
testAccCheckDigitalOceanRecordAttributesHostname(&record),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_record.foobar", "name", "terraform"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_record.foobar", "domain", "foobar-test-terraform.com"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_record.foobar", "value", "a.foobar-test-terraform.com"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"digitalocean_record.foobar", "type", "CNAME"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanRecordDestroy(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*digitalocean.Client)
|
||||
|
||||
|
@ -146,6 +173,17 @@ func testAccCheckDigitalOceanRecordExists(n string, record *digitalocean.Record)
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckDigitalOceanRecordAttributesHostname(record *digitalocean.Record) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
|
||||
if record.Data != "a.foobar-test-terraform.com" {
|
||||
return fmt.Errorf("Bad value: %s", record.Data)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
const testAccCheckDigitalOceanRecordConfig_basic = `
|
||||
resource "digitalocean_domain" "foobar" {
|
||||
name = "foobar-test-terraform.com"
|
||||
|
@ -173,3 +211,17 @@ resource "digitalocean_record" "foobar" {
|
|||
value = "192.168.0.11"
|
||||
type = "A"
|
||||
}`
|
||||
|
||||
const testAccCheckDigitalOceanRecordConfig_cname = `
|
||||
resource "digitalocean_domain" "foobar" {
|
||||
name = "foobar-test-terraform.com"
|
||||
ip_address = "192.168.0.10"
|
||||
}
|
||||
|
||||
resource "digitalocean_record" "foobar" {
|
||||
domain = "${digitalocean_domain.foobar.name}"
|
||||
|
||||
name = "terraform"
|
||||
value = "a.foobar-test-terraform.com"
|
||||
type = "CNAME"
|
||||
}`
|
||||
|
|
Loading…
Reference in New Issue