Skip to content

Commit

Permalink
Record: Add warning if TTL has changed (#1157)
Browse files Browse the repository at this point in the history
* Record: Add warning if TTL has changed

* remove example

* Update digitalocean/domain/resource_record.go

Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>

---------

Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>
  • Loading branch information
danaelhe and andrewsomething committed May 17, 2024
1 parent dd19ccc commit 4a9379e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion digitalocean/domain/resource_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func resourceDigitalOceanRecordCreate(ctx context.Context, d *schema.ResourceDat
func resourceDigitalOceanRecordRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*config.CombinedConfig).GodoClient()
domain := d.Get("domain").(string)
ttl := d.Get("ttl")
id, err := strconv.Atoi(d.Id())
if err != nil {
return diag.Errorf("invalid record ID: %v", err)
Expand All @@ -200,6 +201,20 @@ func resourceDigitalOceanRecordRead(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

var warn = []diag.Diagnostic{}

if ttl != rec.TTL {
ttlChangeWarn := fmt.Sprintf("The TTL for record ID %d changed from %d to %d. DNS requires that multiple records with the same FQDN share the same TTL. If inconsistent TTLs are provided, DigitalOcean will rectify them automatically.\n\nFor reference, see RFC 2181, section 5.2: https://www.rfc-editor.org/rfc/rfc2181#section-5.", rec.ID, ttl, rec.TTL)

warn = []diag.Diagnostic{
{
Severity: diag.Warning,
Summary: "digitalocean_record TTL changed",
Detail: ttlChangeWarn,
},
}
}

if t := rec.Type; t == "CNAME" || t == "MX" || t == "NS" || t == "SRV" || t == "CAA" {
if rec.Data != "@" && rec.Tag != "iodef" {
rec.Data += "."
Expand All @@ -220,7 +235,7 @@ func resourceDigitalOceanRecordRead(ctx context.Context, d *schema.ResourceData,
log.Printf("[DEBUG] Constructed FQDN: %s", en)
d.Set("fqdn", en)

return nil
return warn
}

func resourceDigitalOceanRecordImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
Expand Down

0 comments on commit 4a9379e

Please sign in to comment.