Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect Service Networking config for instance: xxxx:SERVICE_NETWORKING_NOT_ENABLED

I'm trying to replicate a SQL instance in GCP via terraform. The active instance has a public IP, however subnets from a secondary project are shared with the project hosing the SQL instance, and the SQL instance is associated with the secondary project's network.

I've added the private_network setting properly (I think) in the ip_configuration section, however I'm getting the following error:

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

I can't find much documentation when I google that particular error, and I'm relatively new to Terraform, so I'm hoping someone can point out what I'm missing from either this section of my Terraform config, or another resource altogether.

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"
  }
}
like image 234
NealR Avatar asked Mar 08 '21 20:03

NealR


1 Answers

If you see the following error:

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

Enable the Service Networking API:

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

Getting Started with the Service Networking API

like image 51
John Hanley Avatar answered Oct 10 '22 10:10

John Hanley