Add support for changing TTL on DigitalOcean domain records. Fixes #12631 (#14805)

This commit is contained in:
Andrew Starr-Bochicchio 2017-05-30 11:29:56 -05:00 committed by Paul Stack
parent 77961be736
commit 2a3d752834
3 changed files with 27 additions and 1 deletions

View File

@ -57,6 +57,12 @@ func resourceDigitalOceanRecord() *schema.Resource {
ForceNew: true, ForceNew: true,
}, },
"ttl": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"value": { "value": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -94,6 +100,12 @@ func resourceDigitalOceanRecordCreate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Failed to parse port as an integer: %v", err) return fmt.Errorf("Failed to parse port as an integer: %v", err)
} }
} }
if ttl := d.Get("ttl").(string); ttl != "" {
newRecord.TTL, err = strconv.Atoi(ttl)
if err != nil {
return fmt.Errorf("Failed to parse ttl as an integer: %v", err)
}
}
if weight := d.Get("weight").(string); weight != "" { if weight := d.Get("weight").(string); weight != "" {
newRecord.Weight, err = strconv.Atoi(weight) newRecord.Weight, err = strconv.Atoi(weight)
if err != nil { if err != nil {
@ -146,6 +158,7 @@ func resourceDigitalOceanRecordRead(d *schema.ResourceData, meta interface{}) er
d.Set("weight", strconv.Itoa(rec.Weight)) d.Set("weight", strconv.Itoa(rec.Weight))
d.Set("priority", strconv.Itoa(rec.Priority)) d.Set("priority", strconv.Itoa(rec.Priority))
d.Set("port", strconv.Itoa(rec.Port)) d.Set("port", strconv.Itoa(rec.Port))
d.Set("ttl", strconv.Itoa(rec.TTL))
en := constructFqdn(rec.Name, d.Get("domain").(string)) en := constructFqdn(rec.Name, d.Get("domain").(string))
log.Printf("[DEBUG] Constructed FQDN: %s", en) log.Printf("[DEBUG] Constructed FQDN: %s", en)
@ -168,6 +181,14 @@ func resourceDigitalOceanRecordUpdate(d *schema.ResourceData, meta interface{})
editRecord.Name = v.(string) editRecord.Name = v.(string)
} }
if d.HasChange("ttl") {
newTTL := d.Get("ttl").(string)
editRecord.TTL, err = strconv.Atoi(newTTL)
if err != nil {
return fmt.Errorf("Failed to parse ttl as an integer: %v", err)
}
}
log.Printf("[DEBUG] record update configuration: %#v", editRecord) log.Printf("[DEBUG] record update configuration: %#v", editRecord)
_, _, err = client.Domains.EditRecord(context.Background(), domain, id, &editRecord) _, _, err = client.Domains.EditRecord(context.Background(), domain, id, &editRecord)
if err != nil { if err != nil {

View File

@ -85,6 +85,8 @@ func TestAccDigitalOceanRecord_Updated(t *testing.T) {
"digitalocean_record.foobar", "value", "192.168.0.10"), "digitalocean_record.foobar", "value", "192.168.0.10"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"digitalocean_record.foobar", "type", "A"), "digitalocean_record.foobar", "type", "A"),
resource.TestCheckResourceAttr(
"digitalocean_record.foobar", "ttl", "1800"),
), ),
}, },
{ {
@ -101,6 +103,8 @@ func TestAccDigitalOceanRecord_Updated(t *testing.T) {
"digitalocean_record.foobar", "value", "192.168.0.11"), "digitalocean_record.foobar", "value", "192.168.0.11"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"digitalocean_record.foobar", "type", "A"), "digitalocean_record.foobar", "type", "A"),
resource.TestCheckResourceAttr(
"digitalocean_record.foobar", "ttl", "90"),
), ),
}, },
}, },
@ -341,6 +345,7 @@ resource "digitalocean_record" "foobar" {
name = "terraform" name = "terraform"
value = "192.168.0.11" value = "192.168.0.11"
type = "A" type = "A"
ttl = 90
}` }`
const testAccCheckDigitalOceanRecordConfig_cname = ` const testAccCheckDigitalOceanRecordConfig_cname = `

View File

@ -40,6 +40,7 @@ The following arguments are supported:
* `port` - (Optional) The port of the record, for SRV records. * `port` - (Optional) The port of the record, for SRV records.
* `priority` - (Optional) The priority of the record, for MX and SRV * `priority` - (Optional) The priority of the record, for MX and SRV
records. records.
* `ttl` - (Optional) The time to live for the record, in seconds.
## Attributes Reference ## Attributes Reference
@ -47,4 +48,3 @@ The following attributes are exported:
* `id` - The record ID * `id` - The record ID
* `fqdn` - The FQDN of the record * `fqdn` - The FQDN of the record