Skip to content

Commit 16ccf25

Browse files
committed
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
1 parent 7a6c389 commit 16ccf25

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

helper/schema/grpc_provider.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1261,13 +1261,17 @@ func normalizeNullValues(dst, src cty.Value, apply bool) cty.Value {
12611261
}
12621262

12631263
// Handle null/empty changes for collections during apply.
1264-
// A change between null and empty values prefers src to make sure the state
1264+
// A change from emtpy to null values prefers src to make sure the state
12651265
// is consistent between plan and apply.
1266+
// A change from null to empty values prefers dst to not generate drifts of
1267+
// values when refresh.
12661268
if ty.IsCollectionType() && apply {
12671269
dstEmpty := !dst.IsNull() && dst.IsKnown() && dst.LengthInt() == 0
12681270
srcEmpty := !src.IsNull() && src.IsKnown() && src.LengthInt() == 0
12691271

1270-
if (src.IsNull() && dstEmpty) || (srcEmpty && dst.IsNull()) {
1272+
if src.IsNull() && dstEmpty {
1273+
return dst
1274+
} else if srcEmpty && dst.IsNull() {
12711275
return src
12721276
}
12731277
}

0 commit comments

Comments
 (0)