Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of digitalocean dns records #14215

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions builtin/providers/digitalocean/resource_digitalocean_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,11 @@ func resourceDigitalOceanRecordRead(d *schema.ResourceData, meta interface{}) er
return err
}

// Update response data for records with domain value
if t := rec.Type; t == "CNAME" || t == "MX" || t == "NS" || t == "SRV" {
// Append dot to response if resource value is absolute
if value := d.Get("value").(string); strings.HasSuffix(value, ".") {
rec.Data += "."
// If resource value ends with current domain, make response data absolute
if strings.HasSuffix(value, domain+".") {
rec.Data += domain + "."
}
if rec.Data == "@" {
rec.Data = domain
}
rec.Data += "."
}

d.Set("name", rec.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,64 @@ func TestAccDigitalOceanRecord_ExternalHostnameValue(t *testing.T) {
})
}

func TestAccDigitalOceanRecord_MX(t *testing.T) {
var record godo.DomainRecord
domain := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDigitalOceanRecordDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(
testAccCheckDigitalOceanRecordConfig_mx, domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanRecordExists("digitalocean_record.foo_record", &record),
testAccCheckDigitalOceanRecordAttributesHostname("foobar."+domain, &record),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "name", "terraform"),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "domain", domain),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "value", "foobar."+domain+"."),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "type", "MX"),
),
},
},
})
}

func TestAccDigitalOceanRecord_MX_at(t *testing.T) {
var record godo.DomainRecord
domain := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDigitalOceanRecordDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(
testAccCheckDigitalOceanRecordConfig_mx_at, domain),
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanRecordExists("digitalocean_record.foo_record", &record),
testAccCheckDigitalOceanRecordAttributesHostname("@", &record),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "name", "terraform"),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "domain", domain),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "value", domain+"."),
resource.TestCheckResourceAttr(
"digitalocean_record.foo_record", "type", "MX"),
),
},
},
})
}

func testAccCheckDigitalOceanRecordDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*godo.Client)

Expand Down Expand Up @@ -298,6 +356,36 @@ resource "digitalocean_record" "foobar" {
type = "CNAME"
}`

const testAccCheckDigitalOceanRecordConfig_mx_at = `
resource "digitalocean_domain" "foobar" {
name = "%s"
ip_address = "192.168.0.10"
}

resource "digitalocean_record" "foo_record" {
domain = "${digitalocean_domain.foobar.name}"

name = "terraform"
value = "${digitalocean_domain.foobar.name}."
type = "MX"
priority = "10"
}`

const testAccCheckDigitalOceanRecordConfig_mx = `
resource "digitalocean_domain" "foobar" {
name = "%s"
ip_address = "192.168.0.10"
}

resource "digitalocean_record" "foo_record" {
domain = "${digitalocean_domain.foobar.name}"

name = "terraform"
value = "foobar.${digitalocean_domain.foobar.name}."
type = "MX"
priority = "10"
}`

const testAccCheckDigitalOceanRecordConfig_external_cname = `
resource "digitalocean_domain" "foobar" {
name = "%s"
Expand Down