From 426735e2d775e8d7b681cc8e1b9bd56d171c32c2 Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 20 Jun 2022 16:07:10 +0100 Subject: [PATCH] resource_cloudflare_record: Add DiffSuppressFunc to value param Fixes: #154 When a trailing period is passed to the cloudflare_record resource, we get a perpetual diff that looks as follows: ``` ~ value: "_dbdxxx05384ca.hnyhpvdqhv.acm-validations.aws" => "_dbdxxxf205384ca.hnyhpvdqhv.acm-validations.aws." ``` We should ensure that we are adhering to the following RFCs where it states that an FQDN can have a trailing `.` Therefore, we can now use a DiffSuppressFunc to check that the old value with the final `.` removed and the new value with the `.` removed are the same and if they are then we don't need to cause a diff --- .changelog/1706.txt | 3 +++ internal/provider/schema_cloudflare_record.go | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 .changelog/1706.txt diff --git a/.changelog/1706.txt b/.changelog/1706.txt new file mode 100644 index 0000000000..2a36e57ddb --- /dev/null +++ b/.changelog/1706.txt @@ -0,0 +1,3 @@ +``release-note:enhancement +resource/cloudflare_record: ensure trailing `.` in `value` don't cause surious diffs +``` diff --git a/internal/provider/schema_cloudflare_record.go b/internal/provider/schema_cloudflare_record.go index 0873d07db8..efc7d580cf 100644 --- a/internal/provider/schema_cloudflare_record.go +++ b/internal/provider/schema_cloudflare_record.go @@ -42,6 +42,9 @@ func resourceCloudflareRecordSchema() map[string]*schema.Schema { Optional: true, Computed: true, ConflictsWith: []string{"data"}, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return strings.TrimSuffix(old, ".") == strings.TrimSuffix(new, ".") + }, }, "data": {