You can use Private Service Connect to connect to either a primary
Cloud SQL instance or any of its
read replicas
from multiple Virtual Private Cloud (VPC) networks that belong to different
groups, teams, projects, or organizations.
Before you begin
Support for using Private Service Connect with a Cloud SQL
instance is available for
gcloud CLI versions 416.0.0 and later.
To use DNS automation or a global write endpoint DNS name, you need to enable the
Cloud DNS API.
User roles
The following table provides information about the roles required to use Private Service Connect with a Cloud SQL instance:
Grants full control over the VPC network that initiates a connection to a Cloud SQL instance. You can create and manage IP addresses, firewall rules, service connection policies, and Private Service Connect endpoints.
If you use Private Service Connect to connect to a Cloud SQL instance from multiple VPC networks, then each network has its own administrator.
Private Service Connect endpoints are internal IP addresses in a
consumer VPC network, which clients in that network can access
directly. Clients can use these endpoints to connect to Cloud SQL
instances.
To have Cloud SQL create the Private Service Connect endpoint
automatically, do the following:
Create a service connection policy
in your VPC network. With this policy, you can provision
Private Service Connect endpoints automatically.
Create a Cloud SQL instance
with Private Service Connect enabled for the instance, and configure
the instance to create Private Service Connect endpoints automatically.
A service connection policy lets you authorize a specified service class to create a Private Service Connect endpoint in your consumer VPC network. You can use the service connection policy to let Cloud SQL create Private Service Connect endpoints automatically.
You can create a service connection policy by using the Google Cloud console, gcloud CLI, or the API.
You can create an instance with Private Service Connect enabled for
the instance and configure the instance to create endpoints automatically by
using gcloud CLI or the API.
gcloud
To create an instance with Private Service Connect enabled for the instance, use the gcloud sql instances create command:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
REGION_NAME: the region name for the instance.
ALLOWED_PROJECTS: a comma-separated list of allowed project IDs or numbers from where Private Service Connect endpoints can connect to Cloud SQL instances.
If a project isn't contained in this list, then you can't create Private Service Connect endpoints in the project to connect to the instance.
AVAILABILITY_TYPE: enables high availability for the instance. For this parameter, specify one of the following values:
REGIONAL: enables high availability and is recommended for production instances. The instance fails over to another zone within your selected region.
ZONAL: provides no failover capability. This is the default value.
DATABASE_VERSION: the database version for the instance (for example, MYSQL_8_0).
CONSUMER_NETWORK: the path to the VPC network from where Private Service Connect endpoints need to be created. For example: projects/my-host-project/global/networks/default.
CONSUMER_PROJECT: the project where the Private Service Connect endpoint is created. If you're using a Shared VPC network, then this can be either the host project or the service project.
Any projects that you specify in the auto-connection parameters are added to your allowed projects automatically. Optionally, for any projects where you want to create Private Service Connect endpoints manually, you can add these projects to your list of allowed projects.
REST
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
INSTANCE_NAME: the name of the instance.
REGION_NAME: the region name for the instance.
AVAILABILITY_TYPE: enables high availability for the instance. For this parameter, specify one of the following values:
REGIONAL: enables high availability and is recommended for production instances. The instance fails over to another zone within your selected region.
ZONAL: provides no failover capability. This is the default value.
ALLOWED_PROJECTS: a comma-separated list of allowed project IDs or numbers from where Private Service Connect endpoints can connect to Cloud SQL instances.
If a project isn't contained in this list, then you can't create Private Service Connect endpoints in the project to connect to the instance.
MACHINE_TYPE: the machine type for the instance.
CONSUMER_NETWORK: the VPC network where you want to allow automatic creation of Private Service Connect endpoints.
PARENT_PROJECT: the project that contains the network CONSUMER_NETWORK. If you don't specify a different project in CONSUMER_PROJECT, endpoints are automatically created in PARENT_PROJECT
CONSUMER_PROJECT: Optional. Only specify this if CONSUMER_NETWORK is a Shared VPC network and you want to allow automatic creation of Private Service Connect endpoints in a service project.
Any projects that you specify in the auto-connection parameters are added to your allowed projects automatically. Optionally, for any projects where you want to create Private Service Connect endpoints manually, you can add these projects to your list of allowed projects.
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances
When you enable the DNS automation feature, Cloud SQL automatically provisions
and manages DNS records for the per-instance
DNS name in your authorized consumer VPC networks. With DNS automation enabled on
a Cloud SQL Enterprise Plus edition instance, you can also enable a global write endpoint DNS name that always
automatically resolves to the IP address of the current primary instance. See
DNS names and records
for more information.
gcloud
You can enable DNS
Automation for instances that also have these parameters set:
--enable-private-service-connect
--allowed-psc-projects=...
--psc-auto-connections=...
Use the gcloud CLI beta sql instances create command to enable the feature.
These are the parameters that you use to enable DNS automation and a Global
Cluster Write Endpoint:
--enable-psc-auto-dns
Indicates whether Private Service Connect DNS automation is
enabled for this instance. Defaults to disabled for new instances
when Private Service Connect is enabled using
--enable-private-service-connect.
When DNS automation is enabled, Cloud SQL provisions a universal
DNS record across all networks configured with Private Service Connect
auto-connections.
--enable-psc-write-endpoint-dns
Indicates whether Private Service Connect write endpoint DNS
automation is enabled for this instance. This feature is only supported
for Enterprise Plus instances in which --enable-psc-auto-dns
is also set, and it defaults to disabled when a new instance
is created.
With write endpoint DNS automation enabled, Cloud SQL provisions a
Global Cluster Write Endpoint across all networks that are
configured with Private Service Connect auto-connections. This
universal global DNS record always points to the cluster's primary instance,
which enables seamless application failover without requiring any
client-side connection-string updates.
You can enable or disable Private Service Connect auto connections
to existing instances. Cloud SQL automatically provisions or cleans up the
associated DNS records in the respective networks.
Enabling DNS automation using --enable-psc-auto-dns requires that
Private Service Connect be enabled, and enabling write endpoint DNS
automation using --enable-psc-write-endpoint-dns requires that DNS automation
be enabled in an Enterprise Plus instance.
To return just the DNS name, you can add the following at the end of the
command:
| cut -d, -f3
Troubleshooting
If DNS is not correctly provisioned, you can retry provisioning it by
doing the following:
Disable DNS automation and global write endpoint DNS name
Re-enable DNS automation
Retrieve the endpoint
By retrieving the internal IP address, which is the Private Service Connect endpoint for an instance, you can use this endpoint to connect to the instance.
gcloud
To view information about an instance, including the IP address that's the Private Service Connect endpoint for the instance, use the gcloud sql instances describe command:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
In the response, note the value that appears next to the pscConfig:pscAutoConnections:ipAddress field. This value is the internal IP address that's also the Private Service Connect endpoint for the instance.
REST
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
The following fields exist for instances that have Private Service Connect enabled for them:
allowedConsumerProjects: a list of the allowed projects for the instance. You can create Private Service Connect endpoints from any VPC networks in these projects to the service attachment of the instance.
pscAutoConnections: the allowed VPC network, the status of the service connection policy, and the status of the IP address that's the endpoint for the instance.
pscEnabled: whether an instance has Private Service Connect enabled for it.
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
REGION_NAME: the region name for the instance.
ALLOWED_PROJECTS: a comma-separated list of allowed project IDs or numbers from where Private Service Connect endpoints can connect to Cloud SQL instances.
If a project isn't contained in this list, then you can't create Private Service Connect endpoints in the project to connect to the instance.
AVAILABILITY_TYPE: enable high availability for the instance. For this parameter, specify one of the following values:
REGIONAL: enables high availability and is recommended for production instances. The instance fails over to another zone within your selected region.
ZONAL: provides no failover capability. This is the default value.
Set the default Google Cloud project
where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform
configuration file.
Prepare the directory
Each Terraform configuration file must have its own directory (also
called a root module).
In Cloud Shell, create a directory and a new
file within that directory. The filename must have the
.tf extension—for example main.tf. In this
tutorial, the file is referred to as main.tf.
mkdir DIRECTORY && cd DIRECTORY && touch main.tf
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created main.tf.
Optionally, copy the code from GitHub. This is recommended
when the Terraform snippet is part of an end-to-end solution.
Review and modify the sample parameters to apply to your environment.
Save your changes.
Initialize Terraform. You only need to do this once per directory.
terraform init
Optionally, to use the latest Google provider version, include the -upgrade
option:
terraform init -upgrade
Apply the changes
Review the configuration and verify that the resources that Terraform is going to create or
update match your expectations:
terraform plan
Make corrections to the configuration as necessary.
Apply the Terraform configuration by running the following command and entering yes
at the prompt:
terraform apply
Wait until Terraform displays the "Apply complete!" message.
Open your Google Cloud project to view
the results. In the Google Cloud console, navigate to your resources in the UI to make sure
that Terraform has created or updated them.
REST
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
INSTANCE_NAME: the name of the instance.
REGION_NAME: the region name for the instance.
AVAILABILITY_TYPE: enables high availability for the instance. For this parameter, specify one of the following values:
REGIONAL: enables high availability and is recommended for production instances. The instance fails over to another zone within your selected region.
ZONAL: provides no failover capability. This is the default value.
ALLOWED_PROJECTS: a comma-separated list of allowed project IDs or numbers from where Private Service Connect endpoints can connect to Cloud SQL instances.
If a project isn't contained in this list, then you can't create Private Service Connect endpoints in the project to connect to the instance.
MACHINE_TYPE: the machine type for the instance.
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances
After creating a Cloud SQL instance with Private Service Connect enabled, get the service attachment URI and use it to create the Private Service Connect endpoint.
gcloud
To view summary information about an instance with Private Service Connect enabled, such as the pscServiceAttachmentLink field which displays the URI that points to the service attachment of the instance, use the gcloud sql instances describe command:
The pscServiceAttachmentLink field displays the URI that points to the service attachment of the instance.
Create a Private Service Connect endpoint
You can reserve an internal IP address for the Private Service Connect endpoint and create an endpoint with that address. To create the endpoint, you need the service attachment URI and the projects that are allowed for the instance.
gcloud
To reserve an internal IP address for the Private Service Connect endpoint, use the gcloud compute addresses create command:
ADDRESS_NAME: the name of the internal IP address.
PROJECT_ID: the ID or project number of the Google Cloud project for the endpoint.
REGION_NAME: the region name for the endpoint.
SUBNET_URI: the subnet name for the IP address. The format is: projects/SUBNET_PROJECT_ID/regions/REGION_NAME/subnetworks/SUBNET_NAME.
If the subnet is in a Shared VPC network, then we recommend that the SUBNET_PROJECT_ID is the host project.
INTERNAL_IP_ADDRESS: the IP address to reserve. This IP address must be within the subnet's primary IP range. The IP address can be an RFC 1918 address or a subnet with non-RFC ranges. If you don't want to specify the IP address because you want Google Cloud to reserve an available IP address in the subnet, then omit this flag.
In the response, verify that a RESERVED status appears for the IP address.
To create the Private Service Connect endpoint and point it to the Cloud SQL service attachment, use the gcloud compute forwarding-rules create command:
NETWORK_URI: the URI of the VPC network for the endpoint. The format is:
projects/NETWORK_PROJECT_ID/global/networks/NETWORK_NAME.
If you want to use a Shared VPC network, then specify the host project as the NETWORK_PROJECT_ID.
SERVICE_ATTACHMENT_URI: the URI of the service attachment
Use the following sample to create an IPv4 Private Service Connect endpoint.
resource "google_compute_address" "default" {
name = "psc-compute-address-${google_sql_database_instance.default.name}"
region = "us-central1"
address_type = "INTERNAL"
subnetwork = "default" # Replace value with the name of the subnet here.
address = "10.128.0.43" # Replace value with the IP address to reserve.
}
data "google_sql_database_instance" "default" {
name = resource.google_sql_database_instance.default.name
}
resource "google_compute_forwarding_rule" "default" {
name = "psc-forwarding-rule-${google_sql_database_instance.default.name}"
region = "us-central1"
network = "default"
ip_address = google_compute_address.default.self_link
load_balancing_scheme = ""
target = data.google_sql_database_instance.default.psc_service_attachment_link
allow_psc_global_access = true
}
Use the following sample to create an IPv6 Private Service Connect endpoint.
Set the default Google Cloud project
where you want to apply your Terraform configurations.
You only need to run this command once per project, and you can run it in any directory.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
Environment variables are overridden if you set explicit values in the Terraform
configuration file.
Prepare the directory
Each Terraform configuration file must have its own directory (also
called a root module).
In Cloud Shell, create a directory and a new
file within that directory. The filename must have the
.tf extension—for example main.tf. In this
tutorial, the file is referred to as main.tf.
mkdir DIRECTORY && cd DIRECTORY && touch main.tf
If you are following a tutorial, you can copy the sample code in each section or step.
Copy the sample code into the newly created main.tf.
Optionally, copy the code from GitHub. This is recommended
when the Terraform snippet is part of an end-to-end solution.
Review and modify the sample parameters to apply to your environment.
Save your changes.
Initialize Terraform. You only need to do this once per directory.
terraform init
Optionally, to use the latest Google provider version, include the -upgrade
option:
terraform init -upgrade
Apply the changes
Review the configuration and verify that the resources that Terraform is going to create or
update match your expectations:
terraform plan
Make corrections to the configuration as necessary.
Apply the Terraform configuration by running the following command and entering yes
at the prompt:
terraform apply
Wait until Terraform displays the "Apply complete!" message.
Open your Google Cloud project to view
the results. In the Google Cloud console, navigate to your resources in the UI to make sure
that Terraform has created or updated them.
REST
Reserve an internal IP address for the Private Service Connect endpoint.
Verify that the IP address is reserved.
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the Private Service Connect endpoint
REGION_NAME: the name of the region
ADDRESS_NAME: the name of the IP address
HTTP method and URL:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/addresses/ADDRESS_NAME
To send your request, expand one of these options:
In the response, verify that an ACCEPTED status appears for the pscConnectionStatus field. The endpoint can connect to the service attachment.
Connect to a Cloud SQL instance
You can connect to a Cloud SQL instance with Private Service Connect enabled by using an internal IP address, a DNS record, the Cloud SQL Auth Proxy, the Cloud SQL Language Connectors, or other Google Cloud applications.
Configure DNS manually
If you haven't enabled
DNS automation
to create and manage DNS records for you
automatically, you can create a DNS managed zone and a DNS record manually, to
provide a consistent way of using the Cloud SQL Auth Proxy to connect from different
networks. The instance lookup API response provides a suggested DNS name that
you can use to create the DNS record in a
private DNS zone in the corresponding
VPC network.
gcloud
To view summary information about a Cloud SQL instance, including the DNS name of the instance, use the gcloud sql instances describe command:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance
In the response, verify that the DNS name appears. This name has the following pattern: INSTANCE_UID.PROJECT_DNS_LABEL.REGION_NAME.sql.goog.. For example: 1a23b4cd5e67.1a2b345c6d27.us-central1.sql.goog..
If you want to use a custom DNS name to connect to a Cloud SQL instance instead of using the predefined DNS name in this section, then configure the custom subject alternative name (SAN) setting while creating the instance. The custom DNS name that you insert into the custom SAN setting is added to the SAN field of the server certificate of the instance. This lets you use the custom DNS name with hostname validation securely.
For more information about configuring the custom SAN setting, see Create instances.
To create a private DNS zone, use the gcloud dns managed-zones create command. This zone is associated with the VPC network that's used to connect to the Cloud SQL instance through the Private Service Connect endpoint.
DNS_RECORD: the name of the DNS record. This record is set to the DNS name that you retrieved from the Cloud SQL instance earlier in this procedure (for example, 1a23b4cd5e67.1a2b345c6d27.us-central1.sql.goog.).
RRSET_TYPE: the resource record type of the DNS record set. If
the internal IP address that you reserved
for the Private Service Connect endpoint is IPv4, then specify
A for this parameter. Otherwise, if the IP address for the
endpoint is IPv6, then specify AAAA.
RR_DATA: the IP address allocated for the Private Service Connect endpoint (for example, 198.51.100.5). You can also enter multiple values such as rrdata1 rrdata2 rrdata3 (for example, 10.1.2.3 10.2.3.4 10.3.4.5).
REST
Get the DNS name of a Cloud SQL instance.
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance
INSTANCE_NAME: the name of the instance
HTTP method and URL:
GET https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/instances/INSTANCE_NAME
To send your request, expand one of these options:
The dnsName field displays the DNS name of the Cloud SQL instance. DNS names always end with a period (.).
Create a private DNS zone. This zone is associated with the VPC network that's used to connect to the Cloud SQL instance through the Private Service Connect endpoint.
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the DNS zone
ZONE_NAME: the name of the zone
DESCRIPTION: a description of the zone (for example, a DNS zone for the Cloud SQL instance)
DNS_NAME: the name of the DNS suffix for the zone, such as REGION_NAME.sql.goog. (where REGION_NAME is the region name for the zone)
NETWORK_NAME: the name of the VPC network
HTTP method and URL:
POST https://dns.googleapis.com/dns/v1/projects/PROJECT_ID/managedZones
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the DNS zone.
ZONE_NAME: the name of the zone.
DNS_RECORD: the name of the DNS record. This record is set to the DNS name that you retrieved from the Cloud SQL instance earlier in this procedure (for example, 1a23b4cd5e67.1a2b345c6d27.us-central1.sql.goog.).
RRSET_TYPE: the resource record type of the DNS record set. If
the internal IP address that you reserved
for the Private Service Connect endpoint is IPv4, then specify
A for this parameter. Otherwise, if the IP address for the
endpoint is IPv6, then specify AAAA.
TTL: the time to live (TTL) for the record set in the number of seconds (for example, 300).
RR_DATA: the IP address allocated for the Private Service Connect endpoint (for example, 198.51.100.5). You can also enter multiple values such as rrdata1 rrdata2 rrdata3 (for example, 10.1.2.3 10.2.3.4 10.3.4.5).
HTTP method and URL:
POST https://dns.googleapis.com/dns/v1/projects/PROJECT_ID/managedZones/ZONE_NAME
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the endpoint
REGION_NAME: the region name for the endpoint
SERVICE_ATTACHMENT_PROJECT_ID: the ID or project number of the Google Cloud project that contains the service attachment
SERVICE_ATTACHMENT_NAME: the name of the service attachment for the Cloud SQL instance
HTTP method and URL:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/forwardingRules?target="https://www.googleapis.com/compute/v1/projects/SERVICE_ATTACHMENT_PROJECT_ID/regions/REGION_NAME/serviceAttachments/SERVICE_ATTACHMENT_NAME"
To send your request, expand one of these options:
The internal IP address is the value that's associated with the IPAddress field.
To connect to the Cloud SQL instance, use the internal IP address.
mysql--host=IP_ADDRESS--user=USERNAME-p
Make the following replacements:
IP_ADDRESS: the endpoint's IP address
USERNAME: the name of the user that's connecting to the instance
Connect using the Cloud SQL Auth Proxy
The Cloud SQL Auth Proxy is a connector that provides secure access to an instance with Private Service Connect enabled without a need for authorized networks or for configuring SSL.
To allow Cloud SQL Auth Proxy client connections, set up a DNS record which matches the recommended DNS name that's provided for the instance. The DNS record is a mapping between a DNS resource and a domain name.
If you're connecting through Private Service Connect, then Cloud SQL Auth Proxy
version v2.5.0
or later is required.
Download and install the Cloud SQL Auth Proxy
To connect to instances with Private Service Connect enabled, you must download and install the binary for the Cloud SQL Auth Proxy. The binary that you download depends on the operating system, and whether it uses a 32-bit or 64-bit kernel. Most newer hardware uses a 64-bit kernel.
If you're unsure whether your machine is running a 32-bit or 64-bit kernel, then use the uname -a command for Linux or macOS. For Windows, see the Windows documentation.
Start the Cloud SQL Auth Proxy
The Cloud SQL Auth Proxy supports connections to instances with Private Service Connect enabled. For more information, see Start the Cloud SQL Auth Proxy.
View summary information about a Cloud SQL instance, including the connection name of the instance.
The connection name is in the format of PROJECT_ID:REGION_NAME:INSTANCE_NAME.
Copy the instance connection name.
Launch the Cloud SQL Auth Proxy:
./cloud-sql-proxyINSTANCE_CONNECTION_NAME--psc
Replace INSTANCE_CONNECTION_NAME with the instance connection name that you copied in the previous step.
Connect using the Cloud SQL Language Connectors
The Cloud SQL Language Connectors are
libraries that provide secure access to a Cloud SQL instance with
Private Service Connect enabled without a need for authorized networks
or for configuring SSL.
To allow connections with Cloud SQL Language Connectors, set up a DNS record
which matches the recommended DNS name that's provided for the
instance. The DNS record is a mapping between a DNS resource and a domain name.
The Cloud SQL Language Connectors support Private Service Connect connections
through the PSC IP type within their respective libraries.
Connect from App Engine Standard, Cloud Run, or Cloud Run functions
To connect to Cloud SQL instances with Private Service Connect enabled, you can use App Engine Standard or Cloud Run.
In these supported serverless environments, both the Cloud SQL Language Connectors and direct TCP connections by using an IP address and port number are supported. For direct TCP connections, this is the IP address that you reserve when you create the Private Service Connect endpoint. You can specify the IP address as the address for the database host.
If you create a DNS record for the endpoint, then you can specify this record for the host.
Connect from BigQuery
To access data in Cloud SQL and make queries against this
data over an internal IP connection, use the --enable-google-private-path parameter . This parameter is valid only if:
You use the --no-assign-ip parameter.
You use the --network parameter to specify the name of the
VPC network that you want to use to create an internal connection.
Configure outbound connectivity for your Cloud SQL instance
You can configure your Private Service Connect-enabled
Cloud SQL instance to have outbound connectivity with your network
using a Private Service Connect interface and a
network attachment. For more information
about how Private Service Connect outbound connectivity works
and its limitations, see
Private Service Connect outbound connectivity overview.
To use outbound connectivity with your Cloud SQL instance,
you need to:
Create
or update a
network attachment. This network attachment is used by the Cloud SQL
instance to connect to your network's Private Service Connect
interface.
The network attachment must be in the same region as your Cloud SQL
instance, and be
set up to automatically accept connections
using a list from Private Service Connect
interfaces.
Get the Cloud SQL tenant project ID.
Use the gcloud sql instances describe
command to retrieve details about the instance. You can find the tenant
project ID in the service attachment URL shown in the output:
To test inbound connectivity to a Cloud SQL instance with Private Service Connect enabled, set the IP address of the Private Service Connect endpoint to be the destination IP address.
CONNECTIVITY_TEST_NAME: the name of the connectivity test.
SOURCE_INSTANCE: the URI for the Compute Engine instance where the source IP address is located (for example, projects/myproject/zones/myzone/instances/myinstance).
DESTINATION_CLOUD_SQL_INSTANCE: the URL for the Cloud SQL instance (for example, projects/myproject/instances/myinstance).
DESTINATION_NETWORK: the URI for the VPC network where the destination IP address is located (for example, projects/myproject/global/networks/mynetwork).
DESTINATION_PORT: the port number reserved for the instance. For Cloud SQL for MySQL instances, the port number is 3306.
REST
Before using any of the request data,
make the following replacements:
PROJECT_ID: the ID or project number of the Google Cloud project that contains the instance.
CONNECTIVITY_TEST_NAME: the name of the connectivity test.
SOURCE_IP_ADDRESS: the IP address of the source Compute Engine instance.
SOURCE_INSTANCE: the URI for the Compute Engine instance where the source IP address is located (for example, projects/myproject/zones/myzone/instances/myinstance).
SOURCE_NETWORK: the URI for the VPC network where the source IP address is located (for example, projects/myproject/global/networks/mynetwork).
DESTINATION_IP_ADDRESS: the IP address of the destination Cloud SQL instance.
DESTINATION_PORT: the port number reserved for the instance. For Cloud SQL for MySQL instances, the port number is 3306.
DESTINATION_NETWORK: the URI for the VPC network where the destination IP address is located (for example, projects/myproject/global/networks/mynetwork).
HTTP method and URL:
POST https://networkmanagement.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/connectivityTests?testId=CONNECTIVITY_TEST_NAME
You can set up to 20 Private Service Connect endpoints that connect
to the service attachment of a Cloud SQL instance with
Private Service Connect enabled.
If you need to connect from more VPC networks, then use Private Service Connect
endpoint propagation through NCC. For more information,
see Private Service Connect endpoint propagation.
--no-assign-ip: use this flag because instances with Private Service Connect enabled aren't supported to use other connectivity types such as external IP connections
You can't use the gcloud sql connect command, Cloud Shell, Cloud Build, Database Migration Service, or Datastream to connect to Cloud SQL instances with Private Service Connect enabled.
If your network project contains instances that use the old
Cloud SQL network architecture, then you can't create a
Private Service Connect instance. Cloud SQL provides tools
to help you upgrade your instances from the old network architecture to the
new network architecture. For more information or to check the network
architecture of the Cloud SQL instances in your project and perform
any necessary upgrades, see
Upgrade an instance to the new network architecture.
Troubleshoot
This section contains information about issues associated with Cloud SQL instances with Private Service Connect enabled along with steps for troubleshooting the issues.
Issue
Troubleshooting
The service attachment of the instance doesn't accept the Private Service Connect endpoint.
Verify that the status of the endpoint is ACCEPTED. If the status is PENDING, then the instance isn't allowing the Google Cloud project that contains the endpoint. Make sure that the network project in which the endpoint is created is allowed. For more information, see Edit an instance with Private Service Connect enabled.
ERROR: (gcloud.compute.forwarding-rules.create) Could not fetch resource: The resource 'projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_NAME' was not found
This error message can occur when reserving a static internal IP address for the Private Service Connect endpoint.
Make sure the subnet specified exists in the project specified by the URI. If you want to create an endpoint in a service project but use a subnet from a Shared VPC network,
you need to specify the subnet by its URI and use the host project's project ID in the URI.
For more information, see Create the endpoint manually.
ERROR: (gcloud.compute.forwarding-rules.create) Could not fetch resource:
- The resource 'projects/PROJECT_ID/global/networks/NETWORK_NAME' was not found
This error message can occur when you create a Private Service Connect endpoint manually.
Make sure the network specified exists in the project specified by the URI. If you want to create an endpoint in a service project but use a Shared VPC network,
you need to specify the network by its URI and use the host project's project ID in the URI.
For more information, see Create the endpoint manually.
Invalid consumer network status for PSC auto connection.
The consumer network is either not configured correctly, or not
configured at all, and therefore, no endpoint is available to connect to. To
connect to the endpoint, you'll need to check the status of the endpoint,
and fix the error before trying to connect again.
To check the status of an endpoint,
see Retrive the endpoint.
The status of the endpoint can be one of the following:
CONNECTION_POLICY_MISSING: there is no matching service
connection policy on the consumer network. Service connection policies
are configured by network, by region. To reconfigure the network,
see Update a service connection policy.
CONSUMER_INSTANCE_PROJECT_NOT_ALLOWLISTED: there is a
matching service connection policy, but the
Service
instance scope field in the policy is not configured to allow
connection to this Cloud SQL instance. Update the policy to
configure the value of the Service instance scope field
(--producer-instance-location) with the project, folder, or
organization where the Cloud SQL instance resides. To reconfigure
the service connection policy, see
Update a service connection policy.
POLICY_LIMIT_REACHED: the service connection policy
has reached its endpoint limit. To resolve, you'll need to increase the
endpoint limit by
updating the service connection policy.
No permission to create a service connection policy.
You don't have the required permissions to create a service
connection policy. To create a service connection policy, you need the
Compute Network Admin IAM role. For more information,
see Roles and permissions.
If your external network is unable to accept connections from
the Private Service Connect interface,
then the connection policies on your network attachment may not be
configured correctly.
Network attachments need to be configured to either
accept all connections automatically, or configured manually
with a list of accepted connections.
For more information, see Connection policies.
Use the following command to verify the accepted connections
in your network attachment:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-07-22 UTC."],[],[]]