From 16ccf25b6d9deafd44de27cf05fe82a321e52fc6 Mon Sep 17 00:00:00 2001 From: Jeremy Muriel Date: Fri, 18 Jun 2021 11:14:53 +0200 Subject: [PATCH] fix normalizeNullValues when apply resource to accept an empty list and doesn't use a null src otherwise a drift is generate when refresh resource Fixes #766 --- helper/schema/grpc_provider.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/helper/schema/grpc_provider.go b/helper/schema/grpc_provider.go index 49a541b4d58..d24c126899b 100644 --- a/helper/schema/grpc_provider.go +++ b/helper/schema/grpc_provider.go @@ -1261,13 +1261,17 @@ func normalizeNullValues(dst, src cty.Value, apply bool) cty.Value { } // Handle null/empty changes for collections during apply. - // A change between null and empty values prefers src to make sure the state + // A change from emtpy to null values prefers src to make sure the state // is consistent between plan and apply. + // A change from null to empty values prefers dst to not generate drifts of + // values when refresh. if ty.IsCollectionType() && apply { dstEmpty := !dst.IsNull() && dst.IsKnown() && dst.LengthInt() == 0 srcEmpty := !src.IsNull() && src.IsKnown() && src.LengthInt() == 0 - if (src.IsNull() && dstEmpty) || (srcEmpty && dst.IsNull()) { + if src.IsNull() && dstEmpty { + return dst + } else if srcEmpty && dst.IsNull() { return src } }