func()

in internal/tfimport/importer/google_billing_budget.go [75:103]


func (i *BillingBudget) getBudgets(billingAccount string) (budgets []*billingbudgets.GoogleCloudBillingBudgetsV1beta1Budget, err error) {
	ctx := context.Background()
	service, err := billingbudgets.NewService(ctx)
	if err != nil {
		return budgets, err
	}

	budgetsService := billingbudgets.NewBillingAccountsBudgetsService(service)

	// For the format, see:
	// https://github.com/googleapis/google-api-go-client/blob/7c0994ebca7fbbc06ddfb19a468563437f8ec040/billingbudgets/v1beta1/billingbudgets-gen.go#L1252-L1258
	listCall := budgetsService.List(fmt.Sprintf("billingAccounts/%v", billingAccount))

	// Do the call repeatedly, as long as there are more pages.
	for {
		resp, err := listCall.Do()
		if err != nil {
			return budgets, err
		}
		budgets = append(budgets, resp.Budgets...)
		if resp.NextPageToken == "" {
			// No more pages, break out.
			break
		}
		listCall.PageToken(resp.NextPageToken)
	}

	return budgets, nil
}