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

provider/digitalocean: Adds a FQDN out to the digitalocean_record #5071

Merged
merged 1 commit into from
Feb 22, 2016
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
18 changes: 18 additions & 0 deletions builtin/providers/digitalocean/resource_digitalocean_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func resourceDigitalOceanRecord() *schema.Resource {
Computed: true,
ForceNew: true,
},

"fqdn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -146,6 +151,10 @@ func resourceDigitalOceanRecordRead(d *schema.ResourceData, meta interface{}) er
d.Set("priority", strconv.Itoa(rec.Priority))
d.Set("port", strconv.Itoa(rec.Port))

en := constructFqdn(rec.Name, d.Get("domain").(string))
log.Printf("[DEBUG] Constructred FQDN: %s", en)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here

d.Set("fqdn", en)

return nil
}

Expand Down Expand Up @@ -196,3 +205,12 @@ func resourceDigitalOceanRecordDelete(d *schema.ResourceData, meta interface{})

return nil
}

func constructFqdn(name, domain string) string {
rn := strings.ToLower(strings.TrimSuffix(name, "."))
domain = strings.TrimSuffix(domain, ".")
if !strings.HasSuffix(rn, domain) {
rn = strings.Join([]string{name, domain}, ".")
}
return rn
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,35 @@ import (
"strconv"
"testing"

"strings"

"github.com/digitalocean/godo"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestDigitalOceanRecordConstructFqdn(t *testing.T) {
cases := []struct {
Input, Output string
}{
{"www", "www.nonexample.com"},
{"dev.www", "dev.www.nonexample.com"},
{"*", "*.nonexample.com"},
{"nonexample.com", "nonexample.com"},
{"test.nonexample.com", "test.nonexample.com"},
{"test.nonexample.com.", "test.nonexample.com"},
}

domain := "nonexample.com"
for _, tc := range cases {
actual := constructFqdn(tc.Input, domain)
if actual != tc.Output {
t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
}
}
}

func TestAccDigitalOceanRecord_Basic(t *testing.T) {
var record godo.DomainRecord
domain := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))
Expand All @@ -31,6 +54,8 @@ func TestAccDigitalOceanRecord_Basic(t *testing.T) {
"digitalocean_record.foobar", "domain", domain),
resource.TestCheckResourceAttr(
"digitalocean_record.foobar", "value", "192.168.0.10"),
resource.TestCheckResourceAttr(
"digitalocean_record.foobar", "fqdn", strings.Join([]string{"terraform", domain}, ".")),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions website/source/docs/providers/do/r/record.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ The following arguments are supported:
The following attributes are exported:

* `id` - The record ID
* `fqdn` - The FQDN of the record