@@ -2861,6 +2861,97 @@ func TestResourceChange_nestedSet(t *testing.T) {
28612861 - volume_type = "gp2" -> null
28622862 }
28632863 }
2864+ ` ,
2865+ },
2866+ "in-place update - empty nested sets" : {
2867+ Action : plans .Update ,
2868+ Mode : addrs .ManagedResourceMode ,
2869+ Before : cty .ObjectVal (map [string ]cty.Value {
2870+ "id" : cty .StringVal ("i-02ae66f368e8518a9" ),
2871+ "ami" : cty .StringVal ("ami-BEFORE" ),
2872+ "disks" : cty .NullVal (cty .Set (cty .Object (map [string ]cty.Type {
2873+ "mount_point" : cty .String ,
2874+ "size" : cty .String ,
2875+ }))),
2876+ "root_block_device" : cty .SetValEmpty (cty .Object (map [string ]cty.Type {
2877+ "volume_type" : cty .String ,
2878+ })),
2879+ }),
2880+ After : cty .ObjectVal (map [string ]cty.Value {
2881+ "id" : cty .StringVal ("i-02ae66f368e8518a9" ),
2882+ "ami" : cty .StringVal ("ami-AFTER" ),
2883+ "disks" : cty .SetValEmpty (cty .Object (map [string ]cty.Type {
2884+ "mount_point" : cty .String ,
2885+ "size" : cty .String ,
2886+ })),
2887+ "root_block_device" : cty .SetValEmpty (cty .Object (map [string ]cty.Type {
2888+ "volume_type" : cty .String ,
2889+ })),
2890+ }),
2891+ RequiredReplace : cty .NewPathSet (),
2892+ Schema : testSchema (configschema .NestingSet ),
2893+ ExpectedOutput : ` # test_instance.example will be updated in-place
2894+ ~ resource "test_instance" "example" {
2895+ ~ ami = "ami-BEFORE" -> "ami-AFTER"
2896+ + disks = []
2897+ id = "i-02ae66f368e8518a9"
2898+ }
2899+ ` ,
2900+ },
2901+ "in-place update - null insertion" : {
2902+ Action : plans .Update ,
2903+ Mode : addrs .ManagedResourceMode ,
2904+ Before : cty .ObjectVal (map [string ]cty.Value {
2905+ "id" : cty .StringVal ("i-02ae66f368e8518a9" ),
2906+ "ami" : cty .StringVal ("ami-BEFORE" ),
2907+ "disks" : cty .NullVal (cty .Set (cty .Object (map [string ]cty.Type {
2908+ "mount_point" : cty .String ,
2909+ "size" : cty .String ,
2910+ }))),
2911+ "root_block_device" : cty .SetVal ([]cty.Value {
2912+ cty .ObjectVal (map [string ]cty.Value {
2913+ "volume_type" : cty .StringVal ("gp2" ),
2914+ "new_field" : cty .NullVal (cty .String ),
2915+ }),
2916+ }),
2917+ }),
2918+ After : cty .ObjectVal (map [string ]cty.Value {
2919+ "id" : cty .StringVal ("i-02ae66f368e8518a9" ),
2920+ "ami" : cty .StringVal ("ami-AFTER" ),
2921+ "disks" : cty .SetVal ([]cty.Value {
2922+ cty .ObjectVal (map [string ]cty.Value {
2923+ "mount_point" : cty .StringVal ("/var/diska" ),
2924+ "size" : cty .StringVal ("50GB" ),
2925+ }),
2926+ }),
2927+ "root_block_device" : cty .SetVal ([]cty.Value {
2928+ cty .ObjectVal (map [string ]cty.Value {
2929+ "volume_type" : cty .StringVal ("gp2" ),
2930+ "new_field" : cty .StringVal ("new_value" ),
2931+ }),
2932+ }),
2933+ }),
2934+ RequiredReplace : cty .NewPathSet (),
2935+ Schema : testSchemaPlus (configschema .NestingSet ),
2936+ ExpectedOutput : ` # test_instance.example will be updated in-place
2937+ ~ resource "test_instance" "example" {
2938+ ~ ami = "ami-BEFORE" -> "ami-AFTER"
2939+ + disks = [
2940+ + {
2941+ + mount_point = "/var/diska"
2942+ + size = "50GB"
2943+ },
2944+ ]
2945+ id = "i-02ae66f368e8518a9"
2946+
2947+ + root_block_device {
2948+ + new_field = "new_value"
2949+ + volume_type = "gp2"
2950+ }
2951+ - root_block_device {
2952+ - volume_type = "gp2" -> null
2953+ }
2954+ }
28642955` ,
28652956 },
28662957 }
0 commit comments