Module version
Use-cases
In plugin SDK, it is prevalent to call Read() at the end of Create()/Update() in the resource implementation. This is avoid code duplication for APIs that doesn't return the full model in its "create" response.
I'd like to continue this pattern in the framework.
Attempted Solutions
I manually convert to and from the tfsdk.ReadResource{Request|Response}, as below:
func (r resourceFoo) Create(ctx context.Context, req tfsdk.CreateResourceRequest, resp *tfsdk.CreateResourceResponse) {
//...
rreq := tfsdk.ReadResourceRequest{
State: resp.State,
ProviderMeta: req.ProviderMeta,
}
rresp := tfsdk.ReadResourceResponse{
State: resp.State,
Diagnostics: resp.Diagnostics,
}
r.Read(ctx, rreq, &rresp)
*resp = tfsdk.CreateResourceResponse{
State: rresp.State,
Diagnostics: rresp.Diagnostics,
}
}
Full example can be found here: https://github.com/magodo/terraform-provider-demo/blob/41121592396989284faad906d3943fcd084b4272/demo/resource_foo.go#L124-L137
Proposal
Apparently, above solution is not ideal. Propose there can be some builtin utilities to allow users to do that.
Module version
Use-cases
In plugin SDK, it is prevalent to call
Read()at the end ofCreate()/Update()in the resource implementation. This is avoid code duplication for APIs that doesn't return the full model in its "create" response.I'd like to continue this pattern in the framework.
Attempted Solutions
I manually convert to and from the
tfsdk.ReadResource{Request|Response}, as below:Full example can be found here: https://github.com/magodo/terraform-provider-demo/blob/41121592396989284faad906d3943fcd084b4272/demo/resource_foo.go#L124-L137
Proposal
Apparently, above solution is not ideal. Propose there can be some builtin utilities to allow users to do that.