(Terraform) 错误 400:无效请求:实例名称 (pg_instance)., 无效

(Terraform) Error 400: Invalid request: instance name (pg_instance)., invalid

GCP 上,我正在尝试使用 此 Terraform 创建 云 SQL 实例代码如下:

resource "google_sql_database_instance" "postgres" {
    name                = "pg_instance"
    database_version    = "POSTGRES_13"
    region              = "asia-northeast1"
    deletion_protection = false

    settings {
        tier      = "db-f1-micro"
        disk_size = 10
    }
}

resource "google_sql_user" "users" {
    name     = "postgres"
    instance = google_sql_database_instance.postgres.name
    password = "admin"
}

但是我得到了这个错误:

Error: Error, failed to create instance pg_instance: googleapi: Error 400: Invalid request: instance name (pg_instance)., invalid

我的 Terraform 代码有没有错误?

对于a Cloud SQL实例名称只允许使用小写字母、数字和连字符,并且必须以字母开头.

所以,改变这个:

name = "pg_instance"
       # Underscore "_" is not allowed

为此:

name = "pg-instance"
       # Hyphen "-" is allowed

此外,在 GUI 上,您可以在 实例 ID(Terraform 中的“名称”) 的空白下方看到此消息:

Use lowercase letters, numbers, and hyphens. Start with a letter.