func()

in internal/provider/plan_resource.go [355:447]


func (r *planResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
	// Retrieve values from plan
	var plan planResourceModel
	diags := req.Plan.Get(ctx, &plan)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	reqSla := backupdr.SlaRest{
		Id:               plan.ID.ValueString(),
		Description:      plan.Description.ValueString(),
		Logexpirationoff: plan.Logexpirationoff.ValueBool(),
		Dedupasyncoff:    plan.Dedupasyncoff.ValueString(),
		Expirationoff:    plan.Expirationoff.ValueString(),
	}

	if plan.Slp != nil {
		reqSla.Slp = &backupdr.SlpRest{
			Id: plan.Slp.ID.ValueString(),
		}
	}

	if plan.Slt != nil {
		reqSla.Slt = &backupdr.SltRest{
			Id: plan.Slt.ID.ValueString(),
		}
	}

	// Generate API request body from plan
	reqBody := backupdr.SLAApiUpdateSlaOpts{
		Body: optional.NewInterface(reqSla),
	}

	// Update existing order
	respObject, res, err := r.client.SLAApi.UpdateSla(r.authCtx, plan.ID.ValueString(), &reqBody)
	if err != nil {
		resp.Diagnostics.AddError(
			"Error Updating SLA ",
			"An unexpected error occurred when updating the BackupDR SLA , unexpected error: "+err.Error(),
		)
		return
	}

	if res.StatusCode != 200 {
		resp.Diagnostics.AddError(
			"Unable to Update SLA ",
			"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,
		)
	}

	// Map response body to schema and populate Computed attribute values
	plan.ID = types.StringValue(respObject.Id)
	plan.Href = types.StringValue(respObject.Href)
	plan.Stale = types.BoolValue(respObject.Stale)
	plan.Modifydate = types.Int64Value(respObject.Modifydate)
	plan.Syncdate = types.Int64Value(respObject.Syncdate)

	plan.Expirationoff = types.StringValue(respObject.Expirationoff)
	plan.Dedupasyncoff = types.StringValue(respObject.Dedupasyncoff)
	plan.Logexpirationoff = types.BoolValue(respObject.Logexpirationoff)
	plan.Scheduleoff = types.StringValue(respObject.Scheduleoff)

	plan.Application.Appname = types.StringValue(respObject.Application.Appname)
	plan.Application.Apptype = types.StringValue(respObject.Application.Apptype)
	plan.Application.Description = types.StringValue(respObject.Application.Description)
	plan.Application.Href = types.StringValue(respObject.Application.Href)
	plan.Application.Name = types.StringValue(respObject.Application.Name)
	plan.Application.Stale = types.BoolValue(respObject.Application.Stale)
	plan.Application.Syncdate = types.Int64Value(respObject.Application.Syncdate)
	plan.Application.Href = types.StringValue(respObject.Application.Href)
	plan.Application.Href = types.StringValue(respObject.Application.Href)

	plan.Slp.Href = types.StringValue(respObject.Slp.Href)
	plan.Slp.Cid = types.StringValue(respObject.Slp.Cid)
	plan.Slp.Name = types.StringValue(respObject.Slp.Name)
	plan.Slp.Stale = types.BoolValue(respObject.Slp.Stale)
	plan.Slp.Syncdate = types.Int64Value(respObject.Slp.Syncdate)

	plan.Slt.Href = types.StringValue(respObject.Slt.Href)
	plan.Slt.Name = types.StringValue(respObject.Slt.Name)
	plan.Slt.Override = types.StringValue(respObject.Slt.Override)
	plan.Slt.Sourcename = types.StringValue(respObject.Slt.Sourcename)
	plan.Slt.Stale = types.BoolValue(respObject.Slt.Stale)

	diags = resp.State.Set(ctx, plan)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}
}