除了@AndrewL 在他的解决方案中提供的原因之外,似乎还有另一个可能的原因。
简短回答:
当我尝试通过 Terraform 将新的 GCP 项目与我们的结算帐户相关联时,我遇到了同样的错误。我们的计费帐户有 5 个项目的默认限制(我们已经遇到过),这阻止了新帐户的关联并生成了Error 400: Precondition check failed., failedPreconditionerror
消息。为了解决这个问题,我必须先删除/删除一个已经关联的项目,然后才能添加一个新项目。
长答案:
这是我在 Terraform 中遇到的错误消息(敏感数据和 ID 已编辑):
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.
我的结算帐户最多有 5 个项目。作为测试,我删除了其中一个项目,然后再次运行 Terraform。然后它成功地将新项目添加到计费帐户。为了仔细检查,我尝试将另一个新项目添加到计费帐户(将金额推至 6),然后再次收到相同的错误消息。
直接删除相关项目之一也可以。
理所当然地,为您的结算帐户的关联项目请求增加限制也将解决此问题。