in internal/provider/diskpool_resource.go [502:595]
func (r *diskpoolResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Retrieve values from state
var state diskPoolResourceModel
diags := req.Plan.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
reqDiskpool := backupdr.DiskPoolRest{
Name: state.Name.ValueString(),
Pooltype: state.Pooltype.ValueString(),
Cluster: &backupdr.ClusterRest{Clusterid: state.ApplianceClusterID.ValueString()},
}
for _, prop := range state.Properties {
reqDiskpool.Properties = append(reqDiskpool.Properties, backupdr.KeyValueRest{
Key: prop.Key.ValueString(),
Value: prop.Value.ValueString(),
})
}
// Generate API request body from state
reqBody := backupdr.DiskPoolApiUpdateDiskPoolOpts{
Body: optional.NewInterface(reqDiskpool),
}
// Update existing order
respObject, res, err := r.client.DiskPoolApi.UpdateDiskPool(r.authCtx, state.ID.ValueString(), &reqBody)
if err != nil {
resp.Diagnostics.AddError(
"Error Updating DiskPool",
"An unexpected error occurred when updating the BackupDR DiskPool, unexpected error: "+err.Error(),
)
return
}
if res.StatusCode != 200 {
resp.Diagnostics.AddError(
"Unable to Update Diskpool",
"An unexpected error occurred when updating the BackupDR DiskPool. "+
"BackupDR Client Error: "+res.Status,
)
}
// Map response body to schema and populate Computed attribute values
state.ID = types.StringValue(respObject.Id)
state.Href = types.StringValue(respObject.Href)
state.Syncdate = types.Int64Value(respObject.Syncdate)
state.Stale = types.BoolValue(respObject.Stale)
state.Usedefaultsa = types.BoolValue(respObject.Usedefaultsa)
state.Immutable = types.BoolValue(respObject.Immutable)
state.Metadataonly = types.BoolValue(respObject.Metadataonly)
state.State = types.StringValue(respObject.State)
state.Srcid = types.StringValue(respObject.Srcid)
state.Status = types.StringValue(respObject.Status)
state.Mdiskgrp = types.StringValue(respObject.Mdiskgrp)
state.Pooltypedisplayname = types.StringValue(respObject.Pooltypedisplayname)
state.Srcid = types.StringValue(respObject.Srcid)
state.Warnpct = types.Int64Value(int64(respObject.Warnpct))
state.Modifydate = types.Int64Value(respObject.Modifydate)
state.Safepct = types.Int64Value(int64(respObject.Safepct))
state.Udsuid = types.Int64Value(int64(respObject.Udsuid))
state.FreeMb = types.Int64Value(respObject.FreeMb)
state.UsageMb = types.Int64Value(respObject.UsageMb)
state.CapacityMb = types.Int64Value(respObject.CapacityMb)
state.Pct = types.Float64Value(respObject.Pct)
state.ApplianceClusterID = types.StringValue(respObject.Cluster.Clusterid)
// state.Cluster.Href = types.StringValue(respObject.Cluster.Href)
// state.Cluster.ID = types.StringValue(respObject.Cluster.Id)
// state.Cluster.Clusterid = types.StringValue(respObject.Cluster.Clusterid)
// state.Cluster.Serviceaccount = types.StringValue(respObject.Cluster.Serviceaccount)
// state.Cluster.Zone = types.StringValue(respObject.Cluster.Zone)
// state.Cluster.Region = types.StringValue(respObject.Cluster.Region)
// state.Cluster.Projectid = types.StringValue(respObject.Cluster.Projectid)
// state.Cluster.Version = types.StringValue(respObject.Cluster.Version)
// state.Cluster.Name = types.StringValue(respObject.Cluster.Name)
// state.Cluster.Type = types.StringValue(respObject.Cluster.Type_)
// state.Cluster.Ipaddress = types.StringValue(respObject.Cluster.Ipaddress)
// state.Cluster.Publicip = types.StringValue(respObject.Cluster.Publicip)
// state.Cluster.Secureconnect = types.BoolValue(respObject.Cluster.Secureconnect)
// state.Cluster.PkiBootstrapped = types.BoolValue(respObject.Cluster.PkiBootstrapped)
// state.Cluster.Supportstatus = types.StringValue(respObject.Cluster.Supportstatus)
// state.Cluster.Syncdate = types.Int64Value(respObject.Cluster.Syncdate)
// state.Cluster.Stale = types.BoolValue(respObject.Cluster.Stale)
diags = resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}