func()

in internal/provider/template_data_source.go [212:312]


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

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

	slt, res, err := d.client.SLATemplateApi.GetSlt(d.authCtx, state.ID.ValueString())
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read BackupDR SLATemplate",
			err.Error(),
		)
		return
	}

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

	// Map response body to model
	sltState := templateResourceModel{
		ID:          types.StringValue(slt.Id),
		Href:        types.StringValue(slt.Href),
		Name:        types.StringValue(slt.Name),
		Description: types.StringValue(slt.Description),
		OptionHref:  types.StringValue(slt.OptionHref),
		PolicyHref:  types.StringValue(slt.PolicyHref),
		Sourcename:  types.StringValue(slt.Sourcename),
		Override:    types.StringValue(slt.Override),
	}

	// Fetch Policies for the given SLT
	sltID, _ := strconv.Atoi(state.ID.ValueString())
	sltPolicies, res, err := d.client.SLATemplateApi.ListPolicies(d.authCtx, int64(sltID))
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read BackupDR SLATemplate Policies",
			err.Error(),
		)
		return
	}

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

	for _, pol := range sltPolicies.Items {
		sltState.Policies = append(sltState.Policies, policyRestModel{
			ID:                types.StringValue(pol.Id),
			Name:              types.StringValue(pol.Name),
			Description:       types.StringValue(pol.Description),
			Priority:          types.StringValue(pol.Priority),
			Rpom:              types.StringValue(pol.Rpom),
			Rpo:               types.StringValue(pol.Rpo),
			Exclusiontype:     types.StringValue(pol.Exclusiontype),
			Starttime:         types.StringValue(pol.Starttime),
			Endtime:           types.StringValue(pol.Endtime),
			Selection:         types.StringValue(pol.Selection),
			Scheduletype:      types.StringValue(pol.Scheduletype),
			Exclusion:         types.StringValue(pol.Exclusion),
			Reptype:           types.StringValue(pol.Reptype),
			Retention:         types.StringValue(pol.Retention),
			Retentionm:        types.StringValue(pol.Retentionm),
			Encrypt:           types.StringValue(pol.Encrypt),
			Repeatinterval:    types.StringValue(pol.Repeatinterval),
			Exclusioninterval: types.StringValue(pol.Exclusioninterval),
			PolicyType:        types.StringValue(pol.PolicyType),
			Truncatelog:       types.StringValue(pol.Truncatelog),
			Verifychoice:      types.StringValue(pol.Verifychoice),
			Op:                types.StringValue(pol.Op),
			Href:              types.StringValue(pol.Href),

			Remoteretention: types.Int64Value(int64(pol.Remoteretention)),
			Targetvault:     types.Int64Value(int64(pol.Targetvault)),
			Sourcevault:     types.Int64Value(int64(pol.Sourcevault)),

			Iscontinuous: types.BoolValue(pol.Iscontinuous),
			Verification: types.BoolValue(pol.Verification),
		})
	}

	sltState.Managedbyagm = types.BoolValue(slt.Managedbyagm)
	sltState.Usedbycloudapp = types.BoolValue(slt.Usedbycloudapp)

	state = sltState

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

}