Can't add private IP (VPC) to new Google Cloud SQL instance with gcloud
Asked Answered
P

1

6

I've being trying to create a new CloudSQL instance with a private IP attached from the get go. The only thing documentation hints me is to add a VPC network. I'm trying to add the default one.

First I'm enabling the correct APIs / services to my project:

gcloud services enable servicenetworking.googleapis.com servicemanagement.googleapis.com --project=my-project

Then I'm trying to create the CloudSQL instance:

gcloud beta sql instances create cloudsql-instance-name --region=europe-west1 --project=my-project --network=projects/my-project/global/networks/default

However this gives me this non descriptive error:

ERROR: (gcloud.beta.sql.instances.create) [INTERNAL_ERROR] Failed to create subnetwork. Please create Service Networking connection with service 'servicenetworking.googleapis.com' from consumer project '1234567890' network 'default' again.

Two questions:

  1. Is this the correct way to add a private IP to an instance upon creation? Or are there other ways?
  2. Why is it giving me this error and how can I resolve?

Thanks!

Peale answered 9/7, 2019 at 17:12 Comment(0)
T
7

You need to create an "Allocated IP ranges for services" and a "Private connections to services" inside the VPC that you want to have CloudSQL Instance. (In your case is "default" VPC). Once you have both you should be able to create the MYSQL Instance.

Turnspit answered 11/7, 2019 at 10:43 Comment(2)
Could You please tell more details about this. I mean why should we want to create allocated-ip range and private connections for cloud sql which is a google provided serviceHectoliter
@YokeshT this diagram explains why you need to create allocated-ip range and private connections: cloud.google.com/vpc/docs/…Trucker

© 2022 - 2024 — McMap. All rights reserved.