Skip to content

Commit

Permalink
Update framework wrappers methods support
Browse files Browse the repository at this point in the history
  • Loading branch information
paaanic committed Oct 9, 2024
1 parent 43af91a commit 4e04372
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
)

var (
_ datasource.DataSource = &DataSourceWrapper{}
_ datasource.DataSource = (*DataSourceWrapper)(nil)
_ datasource.DataSourceWithConfigValidators = (*DataSourceWrapper)(nil)
_ datasource.DataSourceWithValidateConfig = (*DataSourceWrapper)(nil)
)

func NewDataSourceWrapper(dataSource datasource.DataSource, dataSourceJSON jsonschema.ResourceJSON) *DataSourceWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import (
)

var (
_ resource.Resource = &ResourceWrapper{}
_ resource.Resource = (*ResourceWrapper)(nil)
_ resource.ResourceWithConfigValidators = (*ResourceWrapper)(nil)
_ resource.ResourceWithConfigure = (*ResourceWrapper)(nil)
_ resource.ResourceWithImportState = (*ResourceWrapper)(nil)
_ resource.ResourceWithModifyPlan = (*ResourceWrapper)(nil)
_ resource.ResourceWithMoveState = (*ResourceWrapper)(nil)
_ resource.ResourceWithUpgradeState = (*ResourceWrapper)(nil)
_ resource.ResourceWithValidateConfig = (*ResourceWrapper)(nil)
)

func NewResourceWrapper(resource resource.Resource, resourceJSON jsonschema.ResourceJSON) *ResourceWrapper {
Expand Down Expand Up @@ -79,9 +86,22 @@ func (rw *ResourceWrapper) ModifyPlan(ctx context.Context, req resource.ModifyPl
}
}

func (rw *ResourceWrapper) MoveState(ctx context.Context) []resource.StateMover {
if rs, ok := rw.resource.(resource.ResourceWithMoveState); ok {
return rs.MoveState(ctx)
}
return nil
}

func (rw *ResourceWrapper) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
if rs, ok := rw.resource.(resource.ResourceWithUpgradeState); ok {
return rs.UpgradeState(ctx)
}
return make(map[int64]resource.StateUpgrader, 0)
}

func (rw *ResourceWrapper) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
if rs, ok := rw.resource.(resource.ResourceWithValidateConfig); ok {
rs.ValidateConfig(ctx, req, resp)
}
}

0 comments on commit 4e04372

Please sign in to comment.