【发布时间】:2021-06-06 17:23:06
【问题描述】:
我正在尝试通过 terraform 在 GCP 中复制 SQL 实例。活动实例具有公共 IP,但辅助项目的子网与托管 SQL 实例的项目共享,并且 SQL 实例与辅助项目的网络相关联。
我在ip_configuration 部分中正确添加了private_network 设置(我认为),但是我收到以下错误:
错误:错误,未能创建实例 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"
}
}
【问题讨论】:
-
您同时定义了公共 IP 地址 (
ipv4_enabled = "true") 和私有 IP 地址 (private_network = "projects/gcp-backend/global/networks/default")。使用其中一种,但不能同时使用。 -
@JohnHanley 我将
ipv4_enalbed设置为false,但仍然遇到同样的错误。我需要在其他地方更新设置吗?当前的活动/工作实例既是公共 IP 也是私有 IP,它与辅助项目中的网络相关联。 -
您是否尝试在不同的项目中指定网络?
-
@JohnHanley 是的,这是另一个项目中的默认网络
-
我认为您还有一个问题。您是否启用了“服务网络 API”? console.cloud.google.com/apis/library/…
标签: google-cloud-platform terraform google-cloud-sql terraform-provider-gcp google-vpc