@@ -5,10 +5,12 @@ import (
55 "math/big"
66 "testing"
77
8+ "github.com/hashicorp/terraform-plugin-framework/attr"
89 "github.com/hashicorp/terraform-plugin-framework/resource"
910 rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
1011 "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1112 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
13+ "github.com/hashicorp/terraform-plugin-framework/types"
1214 "github.com/hexops/autogold/v2"
1315 "github.com/zclconf/go-cty/cty"
1416
@@ -225,6 +227,54 @@ func TestPFDetailedDiffDynamicType(t *testing.T) {
225227 })
226228}
227229
230+ func TestPFDetailedDiffNestedDynamicType (t * testing.T ) {
231+ t .Parallel ()
232+
233+ attributeSchema := rschema.Schema {
234+ Attributes : map [string ]rschema.Attribute {
235+ "key" : rschema.ObjectAttribute {
236+ Optional : true ,
237+ AttributeTypes : map [string ]attr.Type {
238+ "nested" : types .DynamicType ,
239+ },
240+ },
241+ },
242+ }
243+ res := pb .NewResource (pb.NewResourceArgs {
244+ ResourceSchema : attributeSchema ,
245+ })
246+
247+ t .Run ("no change" , func (t * testing.T ) {
248+ crosstests .Diff (t , res ,
249+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .StringVal ("value" )})},
250+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .StringVal ("value" )})},
251+ )
252+ })
253+
254+ t .Run ("change" , func (t * testing.T ) {
255+ crosstests .Diff (t , res ,
256+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .StringVal ("value" )})},
257+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .StringVal ("value1" )})},
258+ )
259+ })
260+
261+ t .Run ("int no change" , func (t * testing.T ) {
262+ crosstests .Diff (t , res ,
263+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .NumberVal (big .NewFloat (1 ))})},
264+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .NumberVal (big .NewFloat (1 ))})},
265+ )
266+ })
267+
268+ t .Run ("type change" , func (t * testing.T ) {
269+ // TODO[pulumi/pulumi-terraform-bridge#3078]
270+ t .Skip (`Error converting tftypes.Number<"1"> (value2) at "AttributeName(\"key\")": can't unmarshal tftypes.Number into *string, expected string` )
271+ crosstests .Diff (t , res ,
272+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .StringVal ("value" )})},
273+ map [string ]cty.Value {"key" : cty .ObjectVal (map [string ]cty.Value {"nested" : cty .NumberVal (big .NewFloat (1 ))})},
274+ )
275+ })
276+ }
277+
228278func TestPFDetailedDiffDynamicTypeWithMigration (t * testing.T ) {
229279 t .Parallel ()
230280
0 commit comments