in internal/provider/host_resource.go [473:583]
func (r *hostResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Retrieve values from plan
var plan vcenterHostRest
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
reqVcenterHost := backupdr.HostRest{
Hostname: plan.Hostname.ValueString(),
Hosttype: plan.Hosttype.ValueString(),
Friendlypath: plan.Friendlypath.ValueString(),
Ipaddress: plan.Ipaddress.ValueString(),
}
if plan.Hypervisoragent != nil {
reqVcenterHost.Hypervisoragent = &backupdr.AgentRest{
Username: plan.Hypervisoragent.Username.ValueString(),
Password: plan.Hypervisoragent.Password.ValueString(),
}
}
reqVcenterHost.Sources = append(reqVcenterHost.Sources, backupdr.HostRest{
Clusterid: plan.ApplianceClusterID.ValueString(),
})
// Generate API request body from plan
reqBody := backupdr.HostApiUpdateHostOpts{
Body: optional.NewInterface(reqVcenterHost),
}
// Update vCenter Host
respObject, res, err := r.client.HostApi.UpdateHost(r.authCtx, plan.ID.ValueString(), &reqBody)
if err != nil {
resp.Diagnostics.AddError(
"Error updating vCenter Host",
"Could not updating vCenter Host, unexpected error: "+err.Error(),
)
return
}
if res.StatusCode != 200 {
resp.Diagnostics.AddError(
"Unable to Update vCenter Host ",
"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.Agents = types.BoolValue(respObject.Stale)
plan.Modifydate = types.Int64Value(respObject.Modifydate)
plan.Autoupgrade = types.StringValue(respObject.Autoupgrade)
plan.CertRevoked = types.BoolValue(respObject.CertRevoked)
plan.Clusterid = types.StringValue(respObject.Clusterid)
plan.Dbauthentication = types.BoolValue(respObject.Dbauthentication)
plan.Diskpref = types.StringValue(respObject.Diskpref)
plan.Friendlypath = types.StringValue(respObject.Friendlypath)
plan.Hasagent = types.BoolValue(respObject.Hasagent)
plan.Hostname = types.StringValue(respObject.Hostname)
plan.Hosttype = types.StringValue(respObject.Hosttype)
plan.Ipaddress = types.StringValue(respObject.Ipaddress)
plan.IsClusterNode = types.BoolValue(respObject.IsClusterNode)
plan.Isclusterhost = types.BoolValue(respObject.Isclusterhost)
plan.IsShadowHost = types.BoolValue(respObject.IsShadowHost)
plan.Isesxhost = types.BoolValue(respObject.Isesxhost)
plan.Isproxyhost = types.BoolValue(respObject.Isproxyhost)
plan.Isvcenterhost = types.BoolValue(respObject.Isvcenterhost)
plan.Isvm = types.BoolValue(respObject.Isvm)
plan.Maxjobs = types.Int64Value(int64(respObject.Maxjobs))
plan.Name = types.StringValue(respObject.Name)
plan.Originalhostid = types.StringValue(respObject.Originalhostid)
plan.PkiState = types.StringValue(respObject.PkiState)
plan.Sourcecluster = types.StringValue(respObject.Sourcecluster)
plan.Srcid = types.StringValue(respObject.Srcid)
plan.Svcname = types.StringValue(respObject.Svcname)
plan.Transport = types.StringValue(respObject.Transport)
plan.Uniquename = types.StringValue(respObject.Uniquename)
plan.Zone = types.StringValue(respObject.Zone)
plan.Hypervisoragent.Haspassword = types.BoolValue(respObject.Hypervisoragent.Haspassword)
plan.Hypervisoragent.Agenttype = types.StringValue(respObject.Hypervisoragent.Agenttype)
plan.Hypervisoragent.Hasalternatekey = types.BoolValue(respObject.Hypervisoragent.Hasalternatekey)
// plan.Agents = []AgentRest{{
// Agenttype: types.StringValue(respObject.Agents[0].Agenttype),
// Hasalternatekey: types.BoolValue(respObject.Agents[0].Hasalternatekey),
// Haspassword: types.BoolValue(respObject.Agents[0].Haspassword),
// Username: types.StringValue(respObject.Agents[0].Username),
// Password: types.StringNull(),
// }}
// plan.Sources[0].ID = types.StringValue(respObject.Sources[0].Id)
// plan.Sources[0].Href = types.StringValue(respObject.Sources[0].Href)
// plan.Appliance, _ = types.ObjectValue(ClusterRestRef{
// // Clusterid: types.StringValue(respObject.Appliance.Clusterid),
// ID: types.StringValue(respObject.Appliance.Id),
// Href: types.StringValue(respObject.Appliance.Href),
// })
diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}