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

发布于 2025-01-26 21:25:41 字数 711 浏览 4 评论 0原文

GCP 上,我试图使用使用 此Terraform Code 以下:

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"
}

但是我得到了这个错误:

错误:错误,无法创建实例pg_instance:googleapi:错误400:无效请求:instance name(pg_instance)。,无效

On GCP, I'm trying to create a Cloud SQL instance with this Terraform code below:

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"
}

But I got this error:

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

Are there any mistakes for my Terraform code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2025-02-02 21:25:41

对于,云SQL实例名称仅允许小写字母,数字和连字符,它必须以字母开始。

因此,对此进行更改:

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

对此:

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

此外,在 gui 上,您可以在下面在下面看到此消息,例如,空白为例如ID(Terraform中的“名称”)

使用小写字母,数字和连字符。从字母开始。

For a Cloud SQL instance name, only lowercase letters, numbers, and hyphens are allowed and it must start with a letter.

So, change this:

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

To this:

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

In addition, on GUI, you can see this message below under the blank for instance ID("name" in Terraform):

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

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文