func()

in internal/provider/diskpool_resource.go [413:500]


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

	// Get refreshed values
	respObject, res, err := r.client.DiskPoolApi.GetDiskPool(r.authCtx, state.ID.ValueString())
	if err != nil {
		resp.Diagnostics.AddError(
			"Error Reading DiskPool",
			"Could not read DiskPool with ID "+state.ID.ValueString()+": "+err.Error(),
		)
		return
	}

	if res.StatusCode != 200 {
		resp.Diagnostics.AddError(
			"Unable to Read BackupDR DiskPool",
			res.Status,
		)
	}

	// Overwrite items with refreshed state
	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)

	// Set state to fully populated data
	// state.Cluster = &ClusterRest{
	// 	ID:              types.StringValue(respObject.Cluster.Id),
	// 	Href:            types.StringValue(respObject.Cluster.Href),
	// 	Serviceaccount:  types.StringValue(respObject.Cluster.Serviceaccount),
	// 	Zone:            types.StringValue(respObject.Cluster.Zone),
	// 	Region:          types.StringValue(respObject.Cluster.Region),
	// 	Projectid:       types.StringValue(respObject.Cluster.Projectid),
	// 	Version:         types.StringValue(respObject.Cluster.Version),
	// 	Name:            types.StringValue(respObject.Cluster.Name),
	// 	Type:            types.StringValue(respObject.Cluster.Type_),
	// 	Ipaddress:       types.StringValue(respObject.Cluster.Ipaddress),
	// 	Publicip:        types.StringValue(respObject.Cluster.Publicip),
	// 	Secureconnect:   types.BoolValue(respObject.Cluster.Secureconnect),
	// 	PkiBootstrapped: types.BoolValue(respObject.Cluster.PkiBootstrapped),
	// 	Supportstatus:   types.StringValue(respObject.Cluster.Supportstatus),
	// 	Syncdate:        types.Int64Value(respObject.Cluster.Syncdate),
	// 	Stale:           types.BoolValue(respObject.Cluster.Stale),
	// }

	// state.Vaultprops = &VaultPropsRest{
	// 	Bucket:      types.StringValue(respObject.Vaultprops.Bucket),
	// 	Compression: types.BoolValue(respObject.Vaultprops.Compression),
	// 	Region:      types.StringValue(respObject.Vaultprops.Region),
	// 	ID:          types.StringValue(respObject.Vaultprops.Id),
	// 	Href:        types.StringValue(respObject.Vaultprops.Href),
	// 	Syncdate:    types.Int64Value(respObject.Vaultprops.Syncdate),
	// 	Stale:       types.BoolValue(respObject.Vaultprops.Stale),
	// }

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