Skip to content

Commit a2dafcf

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 a2dafcf

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

helper/schema/grpc_provider.go

Lines changed: 6 additions & 2 deletions
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
}

helper/schema/grpc_provider_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ func TestNormalizeNullValues(t *testing.T) {
13691369
"network_interface": cty.ListVal([]cty.Value{
13701370
cty.ObjectVal(map[string]cty.Value{
13711371
"network_ip": cty.StringVal("10.128.0.64"),
1372-
"access_config": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{"public_ptr_domain_name": cty.String, "nat_ip": cty.String}))),
1372+
"access_config": cty.ListValEmpty(cty.Object(map[string]cty.Type{"public_ptr_domain_name": cty.String, "nat_ip": cty.String})),
13731373
"address": cty.StringVal("address"),
13741374
"name": cty.StringVal("nic0"),
13751375
}),
@@ -1529,9 +1529,9 @@ func TestNormalizeNullValues(t *testing.T) {
15291529
})),
15301530
}),
15311531
Expect: cty.ObjectVal(map[string]cty.Value{
1532-
"set": cty.NullVal(cty.Set(cty.Object(map[string]cty.Type{
1532+
"set": cty.SetValEmpty(cty.Object(map[string]cty.Type{
15331533
"list": cty.List(cty.String),
1534-
}))),
1534+
})),
15351535
}),
15361536
Apply: true,
15371537
},

0 commit comments

Comments
 (0)