func()

in internal/provider/appliances_data_source.go [128:181]


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

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

	appliances, res, err := d.client.ApplianceApi.ListClusters(d.authCtx, nil)
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read BackupDR Appliances",
			err.Error(),
		)
		return
	}

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

	var apps = []appliancesResourceModel{}
	// Map response body to model
	for _, appliance := range appliances.Items {
		applianceState := appliancesResourceModel{
			ID:              types.StringValue(appliance.Id),
			Href:            types.StringValue(appliance.Href),
			Stale:           types.BoolValue(appliance.Stale),
			Clusterid:       types.StringValue(appliance.Clusterid),
			Serviceaccount:  types.StringValue(appliance.Serviceaccount),
			Ipaddress:       types.StringValue(appliance.Ipaddress),
			Projectid:       types.StringValue(appliance.Projectid),
			Region:          types.StringValue(appliance.Region),
			Name:            types.StringValue(appliance.Name),
			Version:         types.StringValue(appliance.Version),
			Publicip:        types.StringValue(appliance.Publicip),
			Type:            types.StringValue(appliance.Type_),
			Zone:            types.StringValue(appliance.Zone),
			Secureconnect:   types.BoolValue(appliance.Secureconnect),
			Supportstatus:   types.StringValue(appliance.Supportstatus),
			PkiBootstrapped: types.BoolValue(appliance.PkiBootstrapped),
		}
		apps = append(apps, applianceState)
	}

	state.Items = apps

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