Skip to content

Commit 71dfd7f

Browse files
authored
Merge pull request #44521 from hashicorp/b-framework-identity-schema
Only implement `resource.ResourceWithIdentity` if resource type supports Resource Identity
2 parents 19dc074 + 63a67ac commit 71dfd7f

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

internal/provider/framework/wrap.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -550,25 +550,35 @@ func newWrappedResource(spec *inttypes.ServicePackageFrameworkResource, serviceP
550550

551551
inner, _ := spec.Factory(context.TODO())
552552

553-
if len(spec.Identity.Attributes) > 0 {
554-
interceptors = append(interceptors, newIdentityInterceptor(spec.Identity.Attributes))
555-
if v, ok := inner.(framework.Identityer); ok {
556-
v.SetIdentitySpec(spec.Identity)
553+
if len(spec.Identity.Attributes) == 0 {
554+
return &wrappedResource{
555+
inner: inner,
556+
servicePackageName: servicePackageName,
557+
spec: spec,
558+
interceptors: interceptors,
557559
}
558560
}
559561

562+
interceptors = append(interceptors, newIdentityInterceptor(spec.Identity.Attributes))
563+
if v, ok := inner.(framework.Identityer); ok {
564+
v.SetIdentitySpec(spec.Identity)
565+
}
566+
560567
if spec.Import.WrappedImport {
561568
if v, ok := inner.(framework.ImportByIdentityer); ok {
562569
v.SetImportSpec(spec.Import)
563570
}
564571
// If the resource does not implement framework.ImportByIdentityer,
565572
// it will be caught by `validateResourceSchemas`, so we can ignore it here.
566573
}
567-
return &wrappedResource{
568-
inner: inner,
569-
servicePackageName: servicePackageName,
570-
spec: spec,
571-
interceptors: interceptors,
574+
575+
return &wrappedResourceWithIdentity{
576+
wrappedResource: wrappedResource{
577+
inner: inner,
578+
servicePackageName: servicePackageName,
579+
spec: spec,
580+
interceptors: interceptors,
581+
},
572582
}
573583
}
574584

@@ -788,7 +798,11 @@ func (w *wrappedResource) MoveState(ctx context.Context) []resource.StateMover {
788798
return nil
789799
}
790800

791-
func (w *wrappedResource) IdentitySchema(ctx context.Context, req resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
801+
type wrappedResourceWithIdentity struct {
802+
wrappedResource
803+
}
804+
805+
func (w *wrappedResourceWithIdentity) IdentitySchema(ctx context.Context, req resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
792806
if len(w.spec.Identity.Attributes) > 0 {
793807
resp.IdentitySchema = identity.NewIdentitySchema(w.spec.Identity)
794808
}

0 commit comments

Comments
 (0)