hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.28k stars 1.72k forks source link

Missing API creates inconsistent state around billing account attachment #3457

Closed andor44 closed 5 years ago

andor44 commented 5 years ago

Community Note

Terraform Version

Terraform v0.11.13
+ provider.google v2.4.0
+ provider.google-beta v2.4.0

Affected Resource(s)

Terraform Configuration Files

resource "google_project" "foo_project" {
  name                = "foo"
  project_id          = "foo"
  org_id              = "${var.organization_id}"
  billing_account     = "${var.billing_account_id}"
  auto_create_network = false
}

Debug Output

Can provide if needed

Panic Output

No panic

Expected Behavior

If no billing account is attached to the project a re-plan would try to modify it.

Actual Behavior

I had Cloud Resource Manager API enabled so I could create the project, but not Cloud Billing API so the billing account could not be attached. I received the following error:

* google_project.foo_project: Error setting billing account "xxx-xxx-xx" for project "projects/foo-project": googleapi: Error 403: Cloud Billing API has not been used in project [redacted] before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=[redacted] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured

After enabling the above API running plan again shows 0 pending changes, and the project has no billing account attached.

Steps to Reproduce

  1. Create a "management" project. Enable Cloud Resource Manager API in it.
  2. Create a service account in the management project, give it permissions to create projects and to attach billing accounts.
  3. Try to create a project with above service account with a specific billing account
  4. Project will be created, billing account won't be attached.
  5. Enable Cloud Billing API on management project.
  6. Run terraform plan, observe no changes planned.
andor44 commented 5 years ago

I was too quick on the trigger here: the billing account actually is being changed properly. I had tried to incorrectly use -target on my project which was causing no changes to be planned.

gokeefe commented 5 years ago

Thank you for this. I was experiencing a similar issue and thought the error was indicating that the billing_account couldn't be set because the cloudbilling api was not enabled yet, but now I realize it's because cloudbilling wasn't enabled on my 'management' project.

ghost commented 5 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!