@@ -6001,6 +6001,112 @@ New Identity: cty.ObjectVal(map[string]cty.Value{"identity":cty.StringVal("chang
60016001 },
60026002 },
60036003 },
6004+ "update-resource-identity-with-empty-prior-identity-identity-may-change" : {
6005+ server : NewGRPCProviderServer (& Provider {
6006+ ResourcesMap : map [string ]* Resource {
6007+ "test" : {
6008+ SchemaVersion : 1 ,
6009+ Schema : map [string ]* Schema {
6010+ "id" : {
6011+ Type : TypeString ,
6012+ Required : true ,
6013+ },
6014+ "test" : {
6015+ Type : TypeString ,
6016+ },
6017+ },
6018+ Identity : & ResourceIdentity {
6019+ Version : 1 ,
6020+ SchemaFunc : func () map [string ]* Schema {
6021+ return map [string ]* Schema {
6022+ "identity_attr_a" : {
6023+ Type : TypeString ,
6024+ RequiredForImport : true ,
6025+ },
6026+ "identity_attr_b" : {
6027+ Type : TypeInt ,
6028+ OptionalForImport : true ,
6029+ },
6030+ }
6031+ },
6032+ },
6033+ ReadContext : func (ctx context.Context , d * ResourceData , meta interface {}) diag.Diagnostics {
6034+ identity , err := d .Identity ()
6035+ if err != nil {
6036+ return diag .FromErr (err )
6037+ }
6038+ err = identity .Set ("identity_attr_a" , "changed" )
6039+ if err != nil {
6040+ return diag .FromErr (err )
6041+ }
6042+ err = identity .Set ("identity_attr_b" , 20 )
6043+ if err != nil {
6044+ return diag .FromErr (err )
6045+ }
6046+
6047+ return nil
6048+ },
6049+ },
6050+ },
6051+ }),
6052+ req : & tfprotov5.ReadResourceRequest {
6053+ TypeName : "test" ,
6054+ CurrentIdentity : & tfprotov5.ResourceIdentityData {
6055+ IdentityData : & tfprotov5.DynamicValue {
6056+ MsgPack : mustMsgpackMarshal (
6057+ cty .Object (map [string ]cty.Type {
6058+ "identity_attr_a" : cty .String ,
6059+ "identity_attr_b" : cty .Number ,
6060+ }),
6061+ cty .ObjectVal (map [string ]cty.Value {
6062+ "identity_attr_a" : cty .NullVal (cty .String ),
6063+ "identity_attr_b" : cty .NullVal (cty .Number ),
6064+ }),
6065+ ),
6066+ },
6067+ },
6068+ CurrentState : & tfprotov5.DynamicValue {
6069+ MsgPack : mustMsgpackMarshal (
6070+ cty .Object (map [string ]cty.Type {
6071+ "test" : cty .String ,
6072+ "id" : cty .String ,
6073+ }),
6074+ cty .ObjectVal (map [string ]cty.Value {
6075+ "test" : cty .StringVal ("hello" ),
6076+ "id" : cty .StringVal ("initial" ),
6077+ }),
6078+ ),
6079+ },
6080+ },
6081+ expected : & tfprotov5.ReadResourceResponse {
6082+ NewState : & tfprotov5.DynamicValue {
6083+ MsgPack : mustMsgpackMarshal (
6084+ cty .Object (map [string ]cty.Type {
6085+ "id" : cty .String ,
6086+ "test" : cty .String ,
6087+ }),
6088+ cty .ObjectVal (map [string ]cty.Value {
6089+ "id" : cty .StringVal ("initial" ),
6090+ "test" : cty .StringVal ("hello" ),
6091+ }),
6092+ ),
6093+ },
6094+ NewIdentity : & tfprotov5.ResourceIdentityData {
6095+ IdentityData : & tfprotov5.DynamicValue {
6096+ MsgPack : mustMsgpackMarshal (
6097+ cty .Object (map [string ]cty.Type {
6098+ "identity_attr_a" : cty .String ,
6099+ "identity_attr_b" : cty .Number ,
6100+ }),
6101+ cty .ObjectVal (map [string ]cty.Value {
6102+ "identity_attr_a" : cty .StringVal ("changed" ),
6103+ "identity_attr_b" : cty .NumberIntVal (20 ),
6104+ }),
6105+ ),
6106+ },
6107+ },
6108+ },
6109+ },
60046110 "does-not-remove-user-data-from-private" : {
60056111 server : NewGRPCProviderServer (& Provider {
60066112 ResourcesMap : map [string ]* Resource {
@@ -7664,6 +7770,140 @@ Planned Identity: cty.ObjectVal(map[string]cty.Value{"identity":cty.StringVal("c
76647770 },
76657771 },
76667772 },
7773+ "update-resource-identity-with-empty-prior-identity-identity-may-change" : {
7774+ server : NewGRPCProviderServer (& Provider {
7775+ ResourcesMap : map [string ]* Resource {
7776+ "test" : {
7777+ SchemaVersion : 1 ,
7778+ Schema : map [string ]* Schema {
7779+ "id" : {
7780+ Type : TypeString ,
7781+ Required : true ,
7782+ },
7783+ "test" : {
7784+ Type : TypeString ,
7785+ },
7786+ },
7787+ Identity : & ResourceIdentity {
7788+ Version : 1 ,
7789+ SchemaFunc : func () map [string ]* Schema {
7790+ return map [string ]* Schema {
7791+ "identity_attr_a" : {
7792+ Type : TypeString ,
7793+ RequiredForImport : true ,
7794+ },
7795+ "identity_attr_b" : {
7796+ Type : TypeInt ,
7797+ OptionalForImport : true ,
7798+ },
7799+ }
7800+ },
7801+ },
7802+ CustomizeDiff : func (ctx context.Context , d * ResourceDiff , meta interface {}) error {
7803+ identity , err := d .Identity ()
7804+ if err != nil {
7805+ return err
7806+ }
7807+ err = identity .Set ("identity_attr_a" , "changed" )
7808+ if err != nil {
7809+ return err
7810+ }
7811+ err = identity .Set ("identity_attr_b" , 20 )
7812+ if err != nil {
7813+ return err
7814+ }
7815+ return nil
7816+ },
7817+ },
7818+ },
7819+ }),
7820+ req : & tfprotov5.PlanResourceChangeRequest {
7821+ TypeName : "test" ,
7822+ PriorState : & tfprotov5.DynamicValue {
7823+ MsgPack : mustMsgpackMarshal (
7824+ cty .Object (map [string ]cty.Type {
7825+ "id" : cty .String ,
7826+ "test" : cty .String ,
7827+ }),
7828+ cty .ObjectVal (map [string ]cty.Value {
7829+ "id" : cty .StringVal ("initial" ),
7830+ "test" : cty .StringVal ("initial" ),
7831+ }),
7832+ ),
7833+ },
7834+ PriorIdentity : & tfprotov5.ResourceIdentityData {
7835+ IdentityData : & tfprotov5.DynamicValue {
7836+ MsgPack : mustMsgpackMarshal (
7837+ cty .Object (map [string ]cty.Type {
7838+ "identity_attr_a" : cty .String ,
7839+ "identity_attr_b" : cty .Number ,
7840+ }),
7841+ cty .ObjectVal (map [string ]cty.Value {
7842+ "identity_attr_a" : cty .NullVal (cty .String ),
7843+ "identity_attr_b" : cty .NullVal (cty .Number ),
7844+ }),
7845+ ),
7846+ },
7847+ },
7848+ ProposedNewState : & tfprotov5.DynamicValue {
7849+ MsgPack : mustMsgpackMarshal (
7850+ cty .Object (map [string ]cty.Type {
7851+ "id" : cty .String ,
7852+ "test" : cty .String ,
7853+ }),
7854+ cty .ObjectVal (map [string ]cty.Value {
7855+ "id" : cty .UnknownVal (cty .String ),
7856+ "test" : cty .StringVal ("initial" ),
7857+ }),
7858+ ),
7859+ },
7860+ Config : & tfprotov5.DynamicValue {
7861+ MsgPack : mustMsgpackMarshal (
7862+ cty .Object (map [string ]cty.Type {
7863+ "id" : cty .String ,
7864+ "test" : cty .String ,
7865+ }),
7866+ cty .ObjectVal (map [string ]cty.Value {
7867+ "id" : cty .NullVal (cty .String ),
7868+ "test" : cty .StringVal ("initial" ),
7869+ }),
7870+ ),
7871+ },
7872+ },
7873+ expected : & tfprotov5.PlanResourceChangeResponse {
7874+ PlannedState : & tfprotov5.DynamicValue {
7875+ MsgPack : mustMsgpackMarshal (
7876+ cty .Object (map [string ]cty.Type {
7877+ "id" : cty .String ,
7878+ "test" : cty .String ,
7879+ }),
7880+ cty .ObjectVal (map [string ]cty.Value {
7881+ "id" : cty .UnknownVal (cty .String ),
7882+ "test" : cty .StringVal ("initial" ),
7883+ }),
7884+ ),
7885+ },
7886+ RequiresReplace : []* tftypes.AttributePath {
7887+ tftypes .NewAttributePath ().WithAttributeName ("id" ),
7888+ },
7889+ PlannedPrivate : []byte (`{"_new_extra_shim":{}}` ),
7890+ UnsafeToUseLegacyTypeSystem : true ,
7891+ PlannedIdentity : & tfprotov5.ResourceIdentityData {
7892+ IdentityData : & tfprotov5.DynamicValue {
7893+ MsgPack : mustMsgpackMarshal (
7894+ cty .Object (map [string ]cty.Type {
7895+ "identity_attr_a" : cty .String ,
7896+ "identity_attr_b" : cty .Number ,
7897+ }),
7898+ cty .ObjectVal (map [string ]cty.Value {
7899+ "identity_attr_a" : cty .StringVal ("changed" ),
7900+ "identity_attr_b" : cty .NumberIntVal (20 ),
7901+ }),
7902+ ),
7903+ },
7904+ },
7905+ },
7906+ },
76677907 "destroy-resource-identity-may-not-change" : {
76687908 server : NewGRPCProviderServer (& Provider {
76697909 ResourcesMap : map [string ]* Resource {
@@ -8910,6 +9150,138 @@ New Identity: cty.ObjectVal(map[string]cty.Value{"identity":cty.StringVal("chang
89109150 },
89119151 },
89129152 },
9153+ "update-resource-identity-with-empty-prior-identity-identity-may-change" : {
9154+ server : NewGRPCProviderServer (& Provider {
9155+ ResourcesMap : map [string ]* Resource {
9156+ "test" : {
9157+ SchemaVersion : 1 ,
9158+ Schema : map [string ]* Schema {
9159+ "id" : {
9160+ Type : TypeString ,
9161+ Required : true ,
9162+ },
9163+ "test" : {
9164+ Type : TypeString ,
9165+ },
9166+ },
9167+ Identity : & ResourceIdentity {
9168+ Version : 1 ,
9169+ SchemaFunc : func () map [string ]* Schema {
9170+ return map [string ]* Schema {
9171+ "identity_attr_a" : {
9172+ Type : TypeString ,
9173+ RequiredForImport : true ,
9174+ },
9175+ "identity_attr_b" : {
9176+ Type : TypeInt ,
9177+ OptionalForImport : true ,
9178+ },
9179+ }
9180+ },
9181+ },
9182+ UpdateContext : func (_ context.Context , rd * ResourceData , _ interface {}) diag.Diagnostics {
9183+ identity , err := rd .Identity ()
9184+ if err != nil {
9185+ return diag .FromErr (err )
9186+ }
9187+ err = identity .Set ("identity_attr_a" , "changed" )
9188+ if err != nil {
9189+ return diag .FromErr (err )
9190+ }
9191+ err = identity .Set ("identity_attr_b" , 20 )
9192+ if err != nil {
9193+ return diag .FromErr (err )
9194+ }
9195+ rd .SetId ("changed" )
9196+ return nil
9197+ },
9198+ },
9199+ },
9200+ }),
9201+ req : & tfprotov5.ApplyResourceChangeRequest {
9202+ TypeName : "test" ,
9203+ PriorState : & tfprotov5.DynamicValue {
9204+ MsgPack : mustMsgpackMarshal (
9205+ cty .Object (map [string ]cty.Type {
9206+ "id" : cty .String ,
9207+ "test" : cty .String ,
9208+ }),
9209+ cty .ObjectVal (map [string ]cty.Value {
9210+ "id" : cty .StringVal ("initial" ),
9211+ "test" : cty .StringVal ("initial" ),
9212+ }),
9213+ ),
9214+ },
9215+ PlannedState : & tfprotov5.DynamicValue {
9216+ MsgPack : mustMsgpackMarshal (
9217+ cty .Object (map [string ]cty.Type {
9218+ "id" : cty .String ,
9219+ "test" : cty .String ,
9220+ }),
9221+ cty .ObjectVal (map [string ]cty.Value {
9222+ "id" : cty .StringVal ("initial" ),
9223+ "test" : cty .StringVal ("initial" ),
9224+ }),
9225+ ),
9226+ },
9227+ PlannedIdentity : & tfprotov5.ResourceIdentityData {
9228+ IdentityData : & tfprotov5.DynamicValue {
9229+ MsgPack : mustMsgpackMarshal (
9230+ cty .Object (map [string ]cty.Type {
9231+ "identity_attr_a" : cty .String ,
9232+ "identity_attr_b" : cty .Number ,
9233+ }),
9234+ cty .ObjectVal (map [string ]cty.Value {
9235+ "identity_attr_a" : cty .NullVal (cty .String ),
9236+ "identity_attr_b" : cty .NullVal (cty .Number ),
9237+ }),
9238+ ),
9239+ },
9240+ },
9241+ Config : & tfprotov5.DynamicValue {
9242+ MsgPack : mustMsgpackMarshal (
9243+ cty .Object (map [string ]cty.Type {
9244+ "id" : cty .String ,
9245+ "test" : cty .String ,
9246+ }),
9247+ cty .ObjectVal (map [string ]cty.Value {
9248+ "id" : cty .NullVal (cty .String ),
9249+ "test" : cty .StringVal ("initial" ),
9250+ }),
9251+ ),
9252+ },
9253+ },
9254+ expected : & tfprotov5.ApplyResourceChangeResponse {
9255+ NewState : & tfprotov5.DynamicValue {
9256+ MsgPack : mustMsgpackMarshal (
9257+ cty .Object (map [string ]cty.Type {
9258+ "id" : cty .String ,
9259+ "test" : cty .String ,
9260+ }),
9261+ cty .ObjectVal (map [string ]cty.Value {
9262+ "id" : cty .StringVal ("changed" ),
9263+ "test" : cty .StringVal ("initial" ),
9264+ }),
9265+ ),
9266+ },
9267+ Private : []uint8 (`{"schema_version":"1"}` ),
9268+ UnsafeToUseLegacyTypeSystem : true ,
9269+ NewIdentity : & tfprotov5.ResourceIdentityData {
9270+ IdentityData : & tfprotov5.DynamicValue {
9271+ MsgPack : mustMsgpackMarshal (
9272+ cty .Object (map [string ]cty.Type {
9273+ "identity_attr_a" : cty .String ,
9274+ "identity_attr_b" : cty .Number ,
9275+ }),
9276+ cty .ObjectVal (map [string ]cty.Value {
9277+ "identity_attr_a" : cty .StringVal ("changed" ),
9278+ "identity_attr_b" : cty .NumberIntVal (20 ),
9279+ }),
9280+ ),
9281+ },
9282+ },
9283+ },
9284+ },
89139285 "destroy-resource-identity-may-change" : {
89149286 server : NewGRPCProviderServer (& Provider {
89159287 ResourcesMap : map [string ]* Resource {
0 commit comments