8

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

我已private_network在该部分中正确添加了设置(我认为)ip_configuration,但是出现以下错误:

错误:错误,未能创建实例 xxxx:googleapi:错误 400:无效请求:服务网络配置不正确,例如:xxxx:xxxxx:SERVICE_NETWORKING_NOT_ENABLED.,无效

当我用谷歌搜索该特定错误时,我找不到太多文档,而且我对 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"
  }
}
4

1 回答 1

18

如果您看到以下错误:

错误:错误,未能创建实例 xxxx:googleapi:错误 400:无效请求:服务网络配置不正确,例如:xxxx:xxxxx:SERVICE_NETWORKING_NOT_ENABLED.,无效

启用服务网络 API:

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

服务网络 API 入门

于 2021-03-08T22:06:10.417 回答