func()

in internal/provider/plan_data_source.go [190:259]


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

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

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

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

	// Map response body to model
	state = planResourceModel{
		ID:          types.StringValue(sla.Id),
		Href:        types.StringValue(sla.Href),
		Description: types.StringValue(sla.Description),
		Modifydate:  types.Int64Value(sla.Modifydate),
		Syncdate:    types.Int64Value(sla.Syncdate),
		Stale:       types.BoolValue(sla.Stale),
		// Immutable:        types.BoolValue(sla.Immutable),
		Dedupasyncoff:    types.StringValue(sla.Dedupasyncoff),
		Expirationoff:    types.StringValue(sla.Expirationoff),
		Scheduleoff:      types.StringValue(sla.Scheduleoff),
		Logexpirationoff: types.BoolValue(sla.Logexpirationoff),
	}
	state.Application = &ApplicationResourceModel{
		ID:          types.StringValue(sla.Application.Id),
		Href:        types.StringValue(sla.Application.Href),
		Description: types.StringValue(sla.Application.Description),
		Appname:     types.StringValue(sla.Application.Appname),
		Syncdate:    types.Int64Value(sla.Application.Syncdate),
		Apptype:     types.StringValue(sla.Application.Apptype),
		Stale:       types.BoolValue(sla.Application.Stale),
		Name:        types.StringValue(sla.Application.Name),
	}

	state.Slp = &profileResourceRefModel{
		ID:       types.StringValue(sla.Slp.Id),
		Href:     types.StringValue(sla.Slp.Href),
		Stale:    types.BoolValue(sla.Slp.Stale),
		Name:     types.StringValue(sla.Slp.Name),
		Syncdate: types.Int64Value(sla.Slp.Syncdate),
		Cid:      types.StringValue(sla.Slp.Cid),
	}

	state.Slt = &templateResourceRefModel{
		ID:         types.StringValue(sla.Slt.Id),
		Href:       types.StringValue(sla.Slt.Href),
		Sourcename: types.StringValue(sla.Slt.Sourcename),
		Override:   types.StringValue(sla.Slt.Override),
		Stale:      types.BoolValue(sla.Slt.Stale),
	}

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