From 0153fc981ca7a0cafe4787c426d6ce2c46ba4036 Mon Sep 17 00:00:00 2001 From: Aam Date: Tue, 2 Jul 2024 11:05:21 +0200 Subject: [PATCH] feat(terraform): add ability to supress github etag while being noisy when no actual state has been changed --- helper/schema/schema.go | 3 ++- helper/schema/schema_test.go | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 176288b0cd8..904b8d9b961 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -980,7 +980,8 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro return fmt.Errorf("%s: DefaultFunc is for configurable attributes,"+ "there's nothing to configure on computed-only field", k) } - if v.DiffSuppressFunc != nil { + // Allow this behavior for etag, which is a special case (being too noisy) + if v.DiffSuppressFunc != nil && k != "etag" { return fmt.Errorf("%s: DiffSuppressFunc is for suppressing differences"+ " between config and state representation. "+ "There is no config for computed-only field, nothing to compare.", k) diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 1c9b1f21988..775bf5dff0e 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -4797,6 +4797,28 @@ func TestSchemaMap_InternalValidate(t *testing.T) { true, }, + "Etag with DiffSuppressFunc": { + map[string]*Schema{ + "etag": { + Type: TypeString, + Computed: true, + DiffSuppressFunc: func(k, oldValue, newValue string, d *ResourceData) bool { return true }, + }, + }, + false, + }, + + "Non Etag with DiffSuppressFunc": { + map[string]*Schema{ + "non_etag": { + Type: TypeString, + Computed: true, + DiffSuppressFunc: func(k, oldValue, newValue string, d *ResourceData) bool { return true }, + }, + }, + true, + }, + "DiffSuppressOnRefresh without DiffSuppressFunc": { map[string]*Schema{ "string": { @@ -5064,7 +5086,6 @@ func TestSchemaMap_InternalValidate(t *testing.T) { } }) } - } func TestSchemaMap_DiffSuppress(t *testing.T) {