func()

in internal/provider/profile_data_source.go [176:255]


func (d *profileDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {

	var state profileResourceModel
	// Read Terraform configuration data into the model
	resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)

	slp, res, err := d.client.SLAProfileApi.GetSlp(d.authCtx, state.ID.ValueString())
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read BackupDR SLA Profile",
			err.Error(),
		)
		return
	}

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

	// Map response body to model
	slpState := profileResourceModel{
		ID:              types.StringValue(slp.Id),
		Href:            types.StringValue(slp.Href),
		Name:            types.StringValue(slp.Name),
		Description:     types.StringValue(slp.Description),
		Srcid:           types.StringValue(slp.Srcid),
		Clusterid:       types.StringValue(slp.Clusterid),
		Cid:             types.StringValue(slp.Cid),
		Performancepool: types.StringValue(slp.Performancepool),
		Remotenode:      types.StringValue(slp.Remotenode),
		Dedupasyncnode:  types.StringValue(slp.Dedupasyncnode),
		Localnode:       types.StringValue(slp.Localnode),
		Createdate:      types.Int64Value(slp.Createdate),
		Modifydate:      types.Int64Value(slp.Modifydate),
		Syncdate:        types.Int64Value(slp.Syncdate),
		Stale:           types.BoolValue(slp.Stale),
	}

	if slp.Vaultpool != nil {
		slpState.Vaultpool = &profileDiskPoolResourceModel{
			ID:   types.StringValue(slp.Vaultpool.Id),
			Href: types.StringValue(slp.Vaultpool.Href),
			Name: types.StringValue(slp.Vaultpool.Name),
		}

	}
	if slp.Vaultpool2 != nil {
		slpState.Vaultpool2 = &profileDiskPoolResourceModel{
			ID:   types.StringValue(slp.Vaultpool2.Id),
			Href: types.StringValue(slp.Vaultpool2.Href),
			Name: types.StringValue(slp.Vaultpool2.Name),
		}
	}
	if slp.Vaultpool3 != nil {
		slpState.Vaultpool3 = &profileDiskPoolResourceModel{
			ID:   types.StringValue(slp.Vaultpool3.Id),
			Href: types.StringValue(slp.Vaultpool3.Href),
			Name: types.StringValue(slp.Vaultpool3.Name),
		}
	}
	if slp.Vaultpool4 != nil {
		slpState.Vaultpool4 = &profileDiskPoolResourceModel{
			ID:   types.StringValue(slp.Vaultpool4.Id),
			Href: types.StringValue(slp.Vaultpool4.Href),
			Name: types.StringValue(slp.Vaultpool4.Name),
		}
	}

	state = slpState

	// Save data into Terraform state
	resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
	if resp.Diagnostics.HasError() {
		return
	}

}