Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions internal/provider/framework/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,25 +550,35 @@ func newWrappedResource(spec *inttypes.ServicePackageFrameworkResource, serviceP

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

if len(spec.Identity.Attributes) > 0 {
interceptors = append(interceptors, newIdentityInterceptor(spec.Identity.Attributes))
if v, ok := inner.(framework.Identityer); ok {
v.SetIdentitySpec(spec.Identity)
if len(spec.Identity.Attributes) == 0 {
return &wrappedResource{
inner: inner,
servicePackageName: servicePackageName,
spec: spec,
interceptors: interceptors,
}
}

interceptors = append(interceptors, newIdentityInterceptor(spec.Identity.Attributes))
if v, ok := inner.(framework.Identityer); ok {
v.SetIdentitySpec(spec.Identity)
}

if spec.Import.WrappedImport {
if v, ok := inner.(framework.ImportByIdentityer); ok {
v.SetImportSpec(spec.Import)
}
// If the resource does not implement framework.ImportByIdentityer,
// it will be caught by `validateResourceSchemas`, so we can ignore it here.
}
return &wrappedResource{
inner: inner,
servicePackageName: servicePackageName,
spec: spec,
interceptors: interceptors,

return &wrappedResourceWithIdentity{
wrappedResource: wrappedResource{
inner: inner,
servicePackageName: servicePackageName,
spec: spec,
interceptors: interceptors,
},
}
}

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

func (w *wrappedResource) IdentitySchema(ctx context.Context, req resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
type wrappedResourceWithIdentity struct {
wrappedResource
}

func (w *wrappedResourceWithIdentity) IdentitySchema(ctx context.Context, req resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
if len(w.spec.Identity.Attributes) > 0 {
resp.IdentitySchema = identity.NewIdentitySchema(w.spec.Identity)
}
Expand Down
Loading