Reputation: 1
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?
Upvotes: 0
Views: 4865
Reputation: 1
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.
Upvotes: 5