func()

in internal/provider/appliance_data_source.go [138:189]


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

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

	applianceID, convErr := strconv.ParseInt(state.ID.ValueString(), 10, 64)
	if convErr != nil {
		tflog.Error(ctx, "Error parsing appliance ID - "+convErr.Error())
	}
	appliance, res, err := d.client.ApplianceApi.GetCluster(d.authCtx, applianceID, nil)
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read BackupDR Appliance",
			err.Error(),
		)
		return
	}

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

	// Map response body to model
	state = 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),
	}

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