Hello community.
I would like to start this topic again, as solutions I have found so far do not solve my problem.
I am in the middle of migrating resources of custom provider from SDKv2 to Plugin Framework.
Remote system supports explicit unset of the value by providing a magic none
value for the field and returns an empty string ""
during subsequent reads.
In the SDKv2 it was mitigated with StateFunc
for resource field:
StateFunc: func(i interface{}) string {
v := i.(string)
if v == "none" {
return ""
}
return v
},
However, in PluginFramework it is not there, so I tried to mutate the state before saving in Update
resource (just one of use-cases, when resource created with empty string in the field and then use ānoneā which should produce the same state):
func (r *resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var terraformPlan terraformModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &terraformPlan)...)
planned := terraformPlan.NextPool.ValueString()
if planned == "none" {
terraformPlan.Field = tftypes.StringValue("")
}
resp.Diagnostics.Append(resp.Plan.Set(ctx, &terraformPlan)...)
}
but this approach results in error during tests:
value was "none" but now ""
I will try to implement a custom type to handle this issue, but it sounds overwhelming to do so just to silent normalization of a string.
Would appreciate any link to reference/similar implementation of this case.