in internal/provider/profile_resource.go [334:477]
func (r *profileResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Retrieve values from plan
var plan profileResourceModel
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
reqSlp := backupdr.SlpRest{
Name: plan.Name.ValueString(),
Description: plan.Description.ValueString(),
Cid: plan.Cid.ValueString(),
Performancepool: plan.Performancepool.ValueString(),
Remotenode: plan.Remotenode.ValueString(),
Localnode: plan.Localnode.ValueString(),
}
if plan.Vaultpool != nil {
reqSlp.Vaultpool = &backupdr.DiskPoolRest{
Id: plan.Vaultpool.ID.ValueString(),
}
} else {
reqSlp.Vaultpool = &backupdr.DiskPoolRest{
Id: "0",
}
}
if plan.Vaultpool2 != nil {
reqSlp.Vaultpool2 = &backupdr.DiskPoolRest{
Id: plan.Vaultpool2.ID.ValueString(),
}
} else {
reqSlp.Vaultpool2 = &backupdr.DiskPoolRest{
Id: "0",
}
}
if plan.Vaultpool3 != nil {
reqSlp.Vaultpool3 = &backupdr.DiskPoolRest{
Id: plan.Vaultpool3.ID.ValueString(),
}
} else {
reqSlp.Vaultpool3 = &backupdr.DiskPoolRest{
Id: "0",
}
}
if plan.Vaultpool4 != nil {
reqSlp.Vaultpool4 = &backupdr.DiskPoolRest{
Id: plan.Vaultpool4.ID.ValueString(),
}
} else {
reqSlp.Vaultpool4 = &backupdr.DiskPoolRest{
Id: "0",
}
}
// Generate API request body from plan
reqBody := backupdr.SLAProfileApiUpdateSlpOpts{
Body: optional.NewInterface(reqSlp),
}
// Update existing order
respObject, res, err := r.client.SLAProfileApi.UpdateSlp(r.authCtx, plan.ID.ValueString(), &reqBody)
if err != nil {
resp.Diagnostics.AddError(
"Error Updating SLA Profile",
"An unexpected error occurred when updating the BackupDR SLA Profile, unexpected error: "+err.Error(),
)
return
}
if res.StatusCode != 200 {
resp.Diagnostics.AddError(
"Unable to Update SLA Profile",
"An unexpected error occurred when creating the BackupDR API client. "+
"If the error is not clear, please contact the provider developers.\n\n"+
"BackupDR Client Error: "+res.Status,
)
}
// Update resource state with updated items and timestamp
plan.Dedupasyncnode = types.StringValue(respObject.Dedupasyncnode)
plan.Remotenode = types.StringValue(respObject.Remotenode)
plan.Localnode = types.StringValue(respObject.Localnode)
plan.Performancepool = types.StringValue(respObject.Performancepool)
// Map response body to schema and populate Computed attribute values
plan.ID = types.StringValue(respObject.Id)
plan.Href = types.StringValue(respObject.Href)
plan.Clusterid = types.StringValue(respObject.Clusterid)
plan.Srcid = types.StringValue(respObject.Srcid)
plan.Stale = types.BoolValue(respObject.Stale)
plan.Createdate = types.Int64Value(respObject.Createdate)
plan.Modifydate = types.Int64Value(respObject.Modifydate)
plan.Syncdate = types.Int64Value(respObject.Syncdate)
if respObject.Vaultpool != nil || plan.Vaultpool != nil {
if plan.Vaultpool.ID.ValueString() != "0" {
plan.Vaultpool.Name = types.StringValue(respObject.Vaultpool.Name)
plan.Vaultpool.Href = types.StringValue(respObject.Vaultpool.Href)
} else {
plan.Vaultpool.Name = types.StringNull()
plan.Vaultpool.Href = types.StringNull()
}
}
if respObject.Vaultpool2 != nil || plan.Vaultpool2 != nil {
if plan.Vaultpool2.ID.ValueString() != "0" {
plan.Vaultpool2.Name = types.StringValue(respObject.Vaultpool2.Name)
plan.Vaultpool2.Href = types.StringValue(respObject.Vaultpool2.Href)
} else {
plan.Vaultpool2.Name = types.StringNull()
plan.Vaultpool2.Href = types.StringNull()
}
}
if respObject.Vaultpool3 != nil || plan.Vaultpool3 != nil {
if plan.Vaultpool3.ID.ValueString() != "0" {
plan.Vaultpool3.Name = types.StringValue(respObject.Vaultpool3.Name)
plan.Vaultpool3.Href = types.StringValue(respObject.Vaultpool3.Href)
} else {
plan.Vaultpool3.Name = types.StringNull()
plan.Vaultpool3.Href = types.StringNull()
}
}
if respObject.Vaultpool4 != nil || plan.Vaultpool4 != nil {
if plan.Vaultpool4.ID.ValueString() != "0" {
plan.Vaultpool4.Name = types.StringValue(respObject.Vaultpool4.Name)
plan.Vaultpool4.Href = types.StringValue(respObject.Vaultpool4.Href)
} else {
plan.Vaultpool4.Name = types.StringNull()
plan.Vaultpool4.Href = types.StringNull()
}
}
diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}