@@ -661,6 +661,7 @@ func (n *NodeAbstractResourceInstance) refresh(ctx EvalContext, deposedKey state
661
661
diags = diags .Append (n .validateIdentityKnown (resp .Identity ))
662
662
diags = diags .Append (n .validateIdentity (resp .Identity ))
663
663
diags = diags .Append (n .validateIdentityDidNotChange (state , resp .Identity ))
664
+ diags = diags .Append (n .validateIdentityMatchesSchema (resp .Identity , schema .Identity ))
664
665
}
665
666
if resp .Deferred != nil {
666
667
deferred = resp .Deferred
@@ -1114,6 +1115,7 @@ func (n *NodeAbstractResourceInstance) plan(
1114
1115
// If the identity is not known we can not validate it did not change
1115
1116
if ! diags .HasErrors () {
1116
1117
diags = diags .Append (n .validateIdentityDidNotChange (currentState , plannedIdentity ))
1118
+ diags = diags .Append (n .validateIdentityMatchesSchema (plannedIdentity , schema .Identity ))
1117
1119
}
1118
1120
}
1119
1121
@@ -2637,6 +2639,7 @@ func (n *NodeAbstractResourceInstance) apply(
2637
2639
if ! resp .NewIdentity .IsNull () {
2638
2640
diags = diags .Append (n .validateIdentityKnown (resp .NewIdentity ))
2639
2641
diags = diags .Append (n .validateIdentity (resp .NewIdentity ))
2642
+ diags = diags .Append (n .validateIdentityMatchesSchema (resp .NewIdentity , schema .Identity ))
2640
2643
if ! change .Action .IsReplace () {
2641
2644
diags = diags .Append (n .validateIdentityDidNotChange (state , resp .NewIdentity ))
2642
2645
}
@@ -2935,6 +2938,28 @@ func (n *NodeAbstractResourceInstance) validateIdentity(newIdentity cty.Value) (
2935
2938
return diags
2936
2939
}
2937
2940
2941
+ func (n * NodeAbstractResourceInstance ) validateIdentityMatchesSchema (newIdentity cty.Value , identitySchema * configschema.Object ) (diags tfdiags.Diagnostics ) {
2942
+ if identitySchema == nil {
2943
+ return diags
2944
+ }
2945
+ newType := newIdentity .Type ()
2946
+ currentType := identitySchema .ImpliedType ()
2947
+ if errs := newType .TestConformance (currentType ); len (errs ) > 0 {
2948
+ for _ , err := range errs {
2949
+ diags = diags .Append (tfdiags .Sourceless (
2950
+ tfdiags .Error ,
2951
+ "Provider produced an identity that doesn't match the schema" ,
2952
+ fmt .Sprintf (
2953
+ "Provider %q returned an identity for %s that doesn't match the identity schema: %s. \n \n This is a bug in the provider, which should be reported in the provider's own issue tracker." ,
2954
+ n .ResolvedProvider .Provider , n .Addr , tfdiags .FormatError (err ),
2955
+ ),
2956
+ ))
2957
+ }
2958
+ }
2959
+
2960
+ return diags
2961
+ }
2962
+
2938
2963
func resourceInstancePrevRunAddr (ctx EvalContext , currentAddr addrs.AbsResourceInstance ) addrs.AbsResourceInstance {
2939
2964
table := ctx .MoveResults ()
2940
2965
return table .OldAddr (currentAddr )
0 commit comments