Open pikesley opened 4 years ago
@pikesley couple of things going on here, let me try to break it down
1) Terraform provider needs the Project variable to be set in one of the ways (env. variable, provider config, resource config) in order to run. Although this billing API call doesn't require the project id, the validation happens before the API call to check project id value is set. Project id is validated once API call is made.
2) Cloud console only shows the displayName
attribute on the UI. However in order to export the billing_budget
resource we need the name attribute. To get the actual name of the billing budget resource please use the following api then use the import command. Please let me know if it helps.
terraform import -provider=google-beta google_billing_budget.default {{name}}
API - https://cloud.google.com/billing/docs/reference/budget/rest/v1beta1/billingAccounts.budgets/list
Sample Response -
{
"budgets": [
{
"name": "billingAccounts/01xxx-8xxx-xxxx/budgets/xxxxxx",
"displayName": "myBudget",
"budgetFilter": {
"projects": [
"projects/xxxx",
"projects/xxxx"
],
"creditTypesTreatment": "INCLUDE_ALL_CREDITS"
},
"amount": {
"specifiedAmount": {
"currencyCode": "USD",
"units": "1000"
}
},
"thresholdRules": [
{
"thresholdPercent": 0.5,
"spendBasis": "CURRENT_SPEND"
},
{
"thresholdPercent": 1,
"spendBasis": "CURRENT_SPEND"
},
{
"thresholdPercent": 0.9,
"spendBasis": "FORECASTED_SPEND"
}
],
"allUpdatesRule": {},
"etag": "7eb9ad05e3b62f43"
}
@venkykuberan could we warm up this topic a little bit? In general there are multiple problems around importing (or just reading) budget resources:
budget
field anymore, so while the import technically succeeds, none of the budget attributes gets mapped into the terraform resource in the state file - so you won't be able to get a clean statebilling_account
attribute, however, this is a required resource attribute in terraform. In order to make it possible to get a clean state, I think the resource read logic should somehow map the billing account ID (contained by the resource ID) into the terraform resource's billing_account
attribute.I was dumb enough not to recognize that the provider code is mostly generated, so I issued a PR last night for the .go
code that fixes these issues. Obviously, it cannot be merged, but it might be helpful for you to understand the problems around budgets, you can find it here: https://github.com/hashicorp/terraform-provider-google-beta/pull/2660
Let me know what do you think!
Similar issue for google_bigquery_data_transfer_config
resource
https://github.com/hashicorp/terraform-provider-google/issues/10788#issuecomment-1059394979
Community Note
modular-magician
user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot
, a community member has claimed the issue already.Terraform Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
Expected Behavior
We have an existing Billing Budget and we expected to be able to import it into Terraform (using these instructions)
Actual Behavior
The import fails with in a confusing way.
Steps to Reproduce
I configured the
resource
as shown above (with a legitbilling_account
id) and then:which feels wrong - why does a Billing Budget need a project?
Anyway, I then tried setting the
GOOGLE_PROJECT
var, but I found that I could set it to any string - Terraform does not seem to care as long as it exists:The actual project ID it threw up (which I've replaced there with 123412341234) is the ID for our
terraform-admin
project, but this choice seems to be entirely arbitrary - after all, I setGOOGLE_PROJECT=foo
Important Factoids
I tried changing the underlying Gcloud context with
gcloud config set project
to see if this made any difference, but got the same result.This may be down to us misunderstanding how this is supposed to work, but the fact it requires
GOOGLE_PROJECT
to be set, but then doesn't care what it's set to, definitely smells like a bug.b/301412737