func()

in internal/provider/cloudcredentials_data_source.go [124:176]


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

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

	ccs, res, err := d.client.DefaultApi.ListCredentials(d.authCtx)
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read BackupDR CloudCredentials",
			err.Error(),
		)
		return
	}

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

	var finalList = []cloudCredentialResourceModel{}
	// Map response body to model
	for _, cc := range ccs.Items {
		ccState := cloudCredentialResourceModel{
			ID:             types.StringValue(cc.Id),
			Href:           types.StringValue(cc.Href),
			Stale:          types.BoolValue(cc.Stale),
			ClusterID:      types.Int64Value(cc.ClusterId),
			Serviceaccount: types.StringValue(cc.Serviceaccount),
			Projectid:      types.StringValue(cc.Projectid),
			Region:         types.StringValue(cc.Region),
			Name:           types.StringValue(cc.Name),
			Usedefaultsa:   types.BoolValue(cc.Usedefaultsa),
			Immutable:      types.BoolValue(cc.Immutable),
			Cloudtype:      types.StringValue(cc.Cloudtype),
			Domain:         types.StringValue(cc.Domain),
			SrcID:          types.Int64Value(cc.SrcId),
			Endpoint:       types.StringValue(cc.Endpoint),
			Clientid:       types.StringValue(cc.Clientid),
		}
		finalList = append(finalList, ccState)
	}

	state.Items = finalList

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