Skip to content

Commit 7d1c43b

Browse files
committed
Merge branch 'f-digitalocean-record-fqdn' of https://github.com/stack72/terraform into stack72-f-digitalocean-record-fqdn
2 parents 1d240c1 + b57a309 commit 7d1c43b

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

builtin/providers/digitalocean/resource_digitalocean_record.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func resourceDigitalOceanRecord() *schema.Resource {
6262
Computed: true,
6363
ForceNew: true,
6464
},
65+
66+
"fqdn": &schema.Schema{
67+
Type: schema.TypeString,
68+
Computed: true,
69+
},
6570
},
6671
}
6772
}
@@ -146,6 +151,10 @@ func resourceDigitalOceanRecordRead(d *schema.ResourceData, meta interface{}) er
146151
d.Set("priority", strconv.Itoa(rec.Priority))
147152
d.Set("port", strconv.Itoa(rec.Port))
148153

154+
en := constructFqdn(rec.Name, d.Get("domain").(string))
155+
log.Printf("[DEBUG] Constructred FQDN: %s", en)
156+
d.Set("fqdn", en)
157+
149158
return nil
150159
}
151160

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

197206
return nil
198207
}
208+
209+
func constructFqdn(name, domain string) string {
210+
rn := strings.ToLower(strings.TrimSuffix(name, "."))
211+
domain = strings.TrimSuffix(domain, ".")
212+
if !strings.HasSuffix(rn, domain) {
213+
rn = strings.Join([]string{name, domain}, ".")
214+
}
215+
return rn
216+
}

builtin/providers/digitalocean/resource_digitalocean_record_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,35 @@ import (
55
"strconv"
66
"testing"
77

8+
"strings"
9+
810
"github.com/digitalocean/godo"
911
"github.com/hashicorp/terraform/helper/acctest"
1012
"github.com/hashicorp/terraform/helper/resource"
1113
"github.com/hashicorp/terraform/terraform"
1214
)
1315

16+
func TestDigitalOceanRecordConstructFqdn(t *testing.T) {
17+
cases := []struct {
18+
Input, Output string
19+
}{
20+
{"www", "www.nonexample.com"},
21+
{"dev.www", "dev.www.nonexample.com"},
22+
{"*", "*.nonexample.com"},
23+
{"nonexample.com", "nonexample.com"},
24+
{"test.nonexample.com", "test.nonexample.com"},
25+
{"test.nonexample.com.", "test.nonexample.com"},
26+
}
27+
28+
domain := "nonexample.com"
29+
for _, tc := range cases {
30+
actual := constructFqdn(tc.Input, domain)
31+
if actual != tc.Output {
32+
t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
33+
}
34+
}
35+
}
36+
1437
func TestAccDigitalOceanRecord_Basic(t *testing.T) {
1538
var record godo.DomainRecord
1639
domain := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))
@@ -31,6 +54,8 @@ func TestAccDigitalOceanRecord_Basic(t *testing.T) {
3154
"digitalocean_record.foobar", "domain", domain),
3255
resource.TestCheckResourceAttr(
3356
"digitalocean_record.foobar", "value", "192.168.0.10"),
57+
resource.TestCheckResourceAttr(
58+
"digitalocean_record.foobar", "fqdn", strings.Join([]string{"terraform", domain}, ".")),
3459
),
3560
},
3661
},

website/source/docs/providers/do/r/record.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ The following arguments are supported:
4545
The following attributes are exported:
4646

4747
* `id` - The record ID
48+
* `fqdn` - The FQDN of the record
4849

0 commit comments

Comments
 (0)