FAILED_PRECONDITION when trying to create a new Google API project

亡梦爱人 提交于 2019-11-30 16:27:43

Make sure that the Google Developers Console is on for the user that is trying to create the project.

Admin.google.com > Apps > Additional Google services > Google Developers Console and turn on for any org or user that needs it.

Looks like there's another possible cause, in addition to the one that @AndrewL provided in his solution.

Short answer:
I ran into the same error when I attempted to associate a new GCP project with our billing account via Terraform. Our billing account has a default limit of 5 projects (which we had already met), and this blocked the association of new accounts and generated the Error 400: Precondition check failed., failedPreconditionerror message. To fix, I had to remove/delete one of the already associated projects before I could add a new one.

Long answser:
Here is the error message I encountered in Terraform (sensitive data and IDs redacted):

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  ~ module.<MY MODULE PATH>.project
      billing_account: "" => "<MY BILLING ACCOUNT ID>"


Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.<MY MODULE PATH>.project: Modifying... (ID: <MY PROJECT ID>)
  billing_account: "" => "<MY BILLING ACCOUNT ID>"

Error: Error applying plan:

1 error(s) occurred:

* module.<MY MODULE PATH>.project: 1 error(s) occurred:

* google_project.project: Error setting billing account "<MY BILLING ACCOUNT ID>" for project "projects/<MY PROJECT ID>": googleapi: Error 400: Precondition check failed., failedPrecondition

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

My billing account was at its maximum of 5 projects. As a test, I removed one of the projects and then ran Terraform again. It then successfully added the new project to the billing account. To double check, I attempted to add yet another new project to the billing account (to push the amount to 6) and then received the same error message again.

Straight up deleting one of the associated projects also works.

It stands to reason that requesting a limit increase for your billing account's associated projects will also fix this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!