例如不正确的服务网络配置:xxxx:SERVICE_NETWORKING_NOT_ENABLED

Incorrect Service Networking config for instance: xxxx:SERVICE_NETWORKING_NOT_ENABLED

我正在尝试通过 terraform 在 GCP 中复制一个 SQL 实例。活动实例具有 public IP,但是来自次级项目的子网与托管 SQL 实例的项目共享,并且 SQL 实例与次级项目的网络相关联。

我已经在 ip_configuration 部分正确添加了 private_network 设置(我认为),但是我收到以下错误:

Error: Error, failed to create instance xxxx: googleapi: Error 400: Invalid request: Incorrect Service Networking config for instance: xxxx:xxxxx:SERVICE_NETWORKING_NOT_ENABLED., invalid

当我 google 那个特定错误时,我找不到太多文档,而且我对 Terraform 还比较陌生,所以我希望有人能指出我在这一部分中遗漏的内容我的 Terraform 配置,或其他资源。

resource "google_sql_database_instance" "cloudsql-instance-qa" {
  depends_on       = [google_project_service.project_apis]
  database_version = "MYSQL_5_7"
  name             = "${var.env_shorthand}-${var.resource_name}"
  project          = var.project_id
  region           = var.region

  settings {
    activation_policy = "ALWAYS"
    availability_type = "ZONAL"

    backup_configuration {
      binary_log_enabled             = "true"
      enabled                        = "true"
      point_in_time_recovery_enabled = "false"
      start_time                     = "15:00"
    }

    crash_safe_replication = "false"
    disk_autoresize        = "true"
    disk_size              = "5003"
    disk_type              = "PD_SSD"

    ip_configuration {
      ipv4_enabled    = "true"
      private_network = "projects/gcp-backend/global/networks/default"
      require_ssl     = "false"
    }

    location_preference {
      zone = var.zone
    }

    maintenance_window {
      day  = "7"
      hour = "4"
    }

    pricing_plan     = "PER_USE"
    replication_type = "SYNCHRONOUS"
    tier             = "db-n1-standard-1"
  }
}

如果您看到以下错误:

Error: Error, failed to create instance xxxx: googleapi: Error 400: Invalid request: Incorrect Service Networking config for instance: xxxx:xxxxx:SERVICE_NETWORKING_NOT_ENABLED., invalid

启用服务网络API:

gcloud services enable servicenetworking.googleapis.com --project=[PSM_PROJECT_NUMBER]

Getting Started with the Service Networking API