[创建数据库用户时,GCP部署管理器“ ResourceErrorCode”:“ 400”
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[创建数据库用户时,GCP部署管理器“ ResourceErrorCode”:“ 400”相关的知识,希望对你有一定的参考价值。
我正在尝试使用Deployment Manager,并且每次尝试部署带有DB和2个用户的SQL实例时,都会进行尝试;有些任务失败了。在大多数情况下,他们是用户:
conf.yaml:
resources:
- name: mycloudsql
type: gcp-types/sqladmin-v1beta4:instances
properties:
name: mycloudsql-01
backendType: SECOND_GEN
instanceType: CLOUD_SQL_INSTANCE
databaseVersion: mysql_5_7
region: europe-west6
settings:
tier: db-f1-micro
locationPreference:
zone: europe-west6-a
activationPolicy: ALWAYS
dataDiskSizeGb: 10
- name: mydjangodb
type: gcp-types/sqladmin-v1beta4:databases
properties:
name: django-db-01
instance: $(ref.mycloudsql.name)
charset: utf8
- name: sqlroot
type: gcp-types/sqladmin-v1beta4:users
properties:
name: root
host: "%"
instance: $(ref.mycloudsql.name)
password: root
- name: sqluser
type: gcp-types/sqladmin-v1beta4:users
properties:
name: user
instance: $(ref.mycloudsql.name)
password: user
错误:
PS C:\Users\user\Desktop\Python\GCP> gcloud --project=sound-catalyst-263911 deployment-manager deployments create dm-sql-test-11 --config conf.yaml
The fingerprint of the deployment is TZ_wYom9Q64Hno6X0bpv9g==
Waiting for create [operation-1589869946223-5a5fa71623bc9-1912fcb9-bc59aafc]...failed.
ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1589869946223-5a5fa71623bc9-1912fcb9-bc59aafc]: errors:
- code: RESOURCE_ERROR
location: /deployments/dm-sql-test-11/resources/sqluser
message: '"ResourceType":"gcp-types/sqladmin-v1beta4:users","ResourceErrorCode":"400","ResourceErrorMessage":"code":400,"message":"Precondition
check failed.","status":"FAILED_PRECONDITION","statusMessage":"Bad Request","requestPath":"https://www.googleapis.com/sql/v1beta4/projects/sound-catalyst-263911/instances/mycloudsql-01/users","httpMethod":"POST"'
- code: RESOURCE_ERROR
location: /deployments/dm-sql-test-11/resources/sqlroot
message: '"ResourceType":"gcp-types/sqladmin-v1beta4:users","ResourceErrorCode":"400","ResourceErrorMessage":"code":400,"message":"Precondition
check failed.","status":"FAILED_PRECONDITION","statusMessage":"Bad Request","requestPath":"https://www.googleapis.com/sql/v1beta4/projects/sound-catalyst-263911/instances/mycloudsql-01/users","httpMethod":"POST"'
没有说先决条件失败是什么,还是我错过了什么?
答案
尽管似乎在YAML中使用引用符号来处理依赖关系,但在Deployment Manager开始创建用户时似乎尚未完成数据库的安装。这就是为什么您收到“ FAILED_PRECONDITION”错误的原因。
作为解决方法,您可以将部署分为两部分:
- 创建CloudSQL实例和数据库;
- 创建用户。
这看起来不优雅,但可以。
或者,您可以考虑使用Terraform。幸运的是,Cloud Shell实例提供了预安装的Terraform。这里有用于Cloud SQL的示例Terraform代码,例如以下示例:
CloudSQL deployment with Terraform
以上是关于[创建数据库用户时,GCP部署管理器“ ResourceErrorCode”:“ 400”的主要内容,如果未能解决你的问题,请参考以下文章
Google 部署管理器 Cloud Scheduler 类型
当没有数据上传到 GCP 中的 BigQuery 表时创建警报
管理员或 GCP 中的用户登录时出现 Windows 2012 R2 RDS 黑屏