in internal/tfimport/importer/google_billing_budget.go [31:73]
func (i *BillingBudget) ImportID(rc terraform.ResourceChange, pcv ConfigMap, interactive bool) (string, error) {
// Can't import if not interactive, since budget names are system-generated and will never be in the plan.
if !interactive {
return "", &InsufficientInfoErr{[]string{"budget"}, "Budget name is system-generated and will never be in the plan"}
}
billingAccountI, err := fromConfigValues("billing_account", rc.Change.After, pcv)
if err != nil {
return "", err
}
billingAccount := fmt.Sprintf("%s", billingAccountI)
// The name is not set, it is autogenerated by the system.
// Try to find existing budgets to offer as choices.
budgets, err := i.getBudgets(billingAccount)
if err != nil {
return "", err
}
if len(budgets) <= 0 {
// There are no budgets, just return that it doesn't exist so it can be created.
return "", &DoesNotExistErr{rc.Address}
}
// Present the choices, if any.
// Format the budgets more nicely.
budgetsLines := []string{"Name|Display Name"}
for _, budget := range budgets {
budgetsLines = append(budgetsLines, fmt.Sprintf("%v|%v", budget.Name, budget.DisplayName))
}
prompt := fmt.Sprintf("Found the following budgets in billing account %v (copy the full value from the \"Name\" column):\n%s", billingAccount, columnize.SimpleFormat(budgetsLines))
// Get the value from the user
budget, err := fromUser(os.Stdin, "budget", prompt)
if err != nil {
return "", err
}
// From https://github.com/googleapis/google-api-go-client/blob/7c0994ebca7fbbc06ddfb19a468563437f8ec040/billingbudgets/v1beta1/billingbudgets-gen.go#L249
// Values are of the form `billingAccounts/{billingAccountId}/budgets/{budgetId}`.
return fmt.Sprintf("%v", budget), nil
}