func()

in internal/provider/host_resource.go [391:471]


func (r *hostResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
	// Get current state
	var state vcenterHostRest
	diags := req.State.Get(ctx, &state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	// Get refreshed values
	respObject, _, err := r.client.HostApi.GetHost(r.authCtx, state.ID.ValueString(), nil)
	if err != nil {
		resp.Diagnostics.AddError(
			"Error Reading vCenter Host",
			"Could not read vCenter Host with ID "+state.ID.ValueString()+": "+err.Error(),
		)
		return
	}

	// Overwrite items with refreshed state
	// Map response body to schema and populate Computed attribute values
	state.ID = types.StringValue(respObject.Id)
	state.Href = types.StringValue(respObject.Href)
	// plan.Agents = types.BoolValue(respObject.Stale)
	state.Modifydate = types.Int64Value(respObject.Modifydate)
	state.Autoupgrade = types.StringValue(respObject.Autoupgrade)
	state.CertRevoked = types.BoolValue(respObject.CertRevoked)
	state.Clusterid = types.StringValue(respObject.Clusterid)
	state.Dbauthentication = types.BoolValue(respObject.Dbauthentication)
	state.Diskpref = types.StringValue(respObject.Diskpref)
	state.Friendlypath = types.StringValue(respObject.Friendlypath)
	state.Hasagent = types.BoolValue(respObject.Hasagent)
	state.Hostname = types.StringValue(respObject.Hostname)
	state.Hosttype = types.StringValue(respObject.Hosttype)
	state.Ipaddress = types.StringValue(respObject.Ipaddress)
	state.IsClusterNode = types.BoolValue(respObject.IsClusterNode)
	state.Isclusterhost = types.BoolValue(respObject.Isclusterhost)
	state.IsShadowHost = types.BoolValue(respObject.IsShadowHost)
	state.Isesxhost = types.BoolValue(respObject.Isesxhost)
	state.Isproxyhost = types.BoolValue(respObject.Isproxyhost)
	state.Isvcenterhost = types.BoolValue(respObject.Isvcenterhost)
	state.Isvm = types.BoolValue(respObject.Isvm)
	state.Maxjobs = types.Int64Value(int64(respObject.Maxjobs))
	state.Name = types.StringValue(respObject.Name)
	state.Originalhostid = types.StringValue(respObject.Originalhostid)
	state.PkiState = types.StringValue(respObject.PkiState)
	state.Sourcecluster = types.StringValue(respObject.Sourcecluster)
	state.Srcid = types.StringValue(respObject.Srcid)
	state.Svcname = types.StringValue(respObject.Svcname)
	state.Transport = types.StringValue(respObject.Transport)
	state.Uniquename = types.StringValue(respObject.Uniquename)
	state.Zone = types.StringValue(respObject.Zone)

	state.Hypervisoragent.Haspassword = types.BoolValue(respObject.Hypervisoragent.Haspassword)
	state.Hypervisoragent.Agenttype = types.StringValue(respObject.Hypervisoragent.Agenttype)
	state.Hypervisoragent.Hasalternatekey = types.BoolValue(respObject.Hypervisoragent.Hasalternatekey)

	// state.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(),
	// }}

	// state.Sources[0].ID = types.StringValue(respObject.Sources[0].Id)
	// state.Sources[0].Href = types.StringValue(respObject.Sources[0].Href)

	// state.Appliance = &ClusterRestRef{
	// 	// Clusterid: types.StringValue(respObject.Appliance.Clusterid),
	// 	ID:   types.StringValue(respObject.Appliance.Id),
	// 	Href: types.StringValue(respObject.Appliance.Href),
	// }

	// Set refreshed state
	diags = resp.State.Set(ctx, &state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}
}