@@ -728,11 +728,7 @@ func (r *Resource) ShimInstanceStateFromValue(state cty.Value) (*terraform.Insta
728728
729729 // We now rebuild the state through the ResourceData, so that the set indexes
730730 // match what helper/schema expects.
731- var identity map [string ]* Schema
732- if r .Identity != nil {
733- identity = r .Identity .Schema
734- }
735- data , err := schemaMapWithIdentity {r .SchemaMap (), identity }.Data (s , nil )
731+ data , err := schemaMapWithIdentity {r .SchemaMap (), r .Identity .SchemaMap ()}.Data (s , nil )
736732 if err != nil {
737733 return nil , err
738734 }
@@ -905,11 +901,7 @@ func (r *Resource) Apply(
905901 s * terraform.InstanceState ,
906902 d * terraform.InstanceDiff ,
907903 meta interface {}) (* terraform.InstanceState , diag.Diagnostics ) {
908- var identity map [string ]* Schema
909- if r .Identity != nil {
910- identity = r .Identity .Schema
911- }
912- schema := schemaMapWithIdentity {r .SchemaMap (), identity }
904+ schema := schemaMapWithIdentity {r .SchemaMap (), r .Identity .SchemaMap ()}
913905 data , err := schema .Data (s , d )
914906 if err != nil {
915907 return s , diag .FromErr (err )
@@ -1033,12 +1025,8 @@ func (r *Resource) SimpleDiff(
10331025 c * terraform.ResourceConfig ,
10341026 meta interface {}) (* terraform.InstanceDiff , error ) {
10351027
1036- var identity map [string ]* Schema
1037- if r .Identity != nil {
1038- identity = r .Identity .Schema
1039- }
10401028 // TODO: figure out if it makes sense to be able to set identity in CustomizeDiff at all
1041- instanceDiff , err := schemaMapWithIdentity {r .SchemaMap (), identity }.Diff (ctx , s , c , r .CustomizeDiff , meta , false )
1029+ instanceDiff , err := schemaMapWithIdentity {r .SchemaMap (), r . Identity . SchemaMap () }.Diff (ctx , s , c , r .CustomizeDiff , meta , false )
10421030 if err != nil {
10431031 return instanceDiff , err
10441032 }
@@ -1127,11 +1115,7 @@ func (r *Resource) RefreshWithoutUpgrade(
11271115 }
11281116 }
11291117
1130- var identity map [string ]* Schema
1131- if r .Identity != nil {
1132- identity = r .Identity .Schema
1133- }
1134- schema := schemaMapWithIdentity {r .SchemaMap (), identity }
1118+ schema := schemaMapWithIdentity {r .SchemaMap (), r .Identity .SchemaMap ()}
11351119
11361120 if r .Exists != nil {
11371121 // Make a copy of data so that if it is modified it doesn't
@@ -1442,7 +1426,7 @@ func (r *Resource) Data(s *terraform.InstanceState) *ResourceData {
14421426func (r * Resource ) TestResourceData () * ResourceData {
14431427 return & ResourceData {
14441428 schema : r .SchemaMap (),
1445- identitySchema : r .Identity .Schema ,
1429+ identitySchema : r .Identity .SchemaMap () ,
14461430 }
14471431}
14481432
@@ -1489,11 +1473,11 @@ func (r *ResourceIdentity) InternalIdentityValidate() error {
14891473 return fmt .Errorf (`The resource identity is empty` )
14901474 }
14911475
1492- if len (r .Schema ) == 0 {
1476+ if len (r .SchemaMap () ) == 0 {
14931477 return fmt .Errorf (`The resource identity schema is empty` )
14941478 }
14951479
1496- for k , v := range r .Schema {
1480+ for k , v := range r .SchemaMap () {
14971481 if ! v .OptionalForImport && ! v .RequiredForImport {
14981482 return fmt .Errorf (`OptionalForImport or RequiredForImport must be set for resource identity` )
14991483 }
0 commit comments