Hello Community, I'm trying to deploy a 2nd Gen cloud function through cloud build trigger. In cloud build trigger we write gcloud functions deploy with required data, so the issue here is gcloud command does not have any argument to add cloud sql instances directly when creating the cloud function which causing the issue in the CI CD. Client is not happy with this manual updation of cloud sql connection after creating the cloud function where as for cloud run we do have --add-sql-instances argument using which cloud sql connection is added by default when creating the cloud run. I believe this field --add-sql-instances field has to be added for gcloud functions deploy command as well. So the CI CD process will be smoother.
Hi @Gandu_Rohini,
Welcome to Google Cloud Community!
As per GCP's documentation, Cloud Functions (Gen 2) rely on Serverless VPC Access to connect to Cloud SQL. While you can configure this via the Cloud Console or Infrastructure as Code tools, the gcloud functions deploy command does not currently support a direct argument like --add-cloudsql-instances for Gen 2. As a workaround, you can modify your pipeline to run a gcloud command after deploying the functions to update the Cloud Run service with the target database instance. This only needs to be done once per deployment, as the instance will remain linked in future deployments unless you manually detach it.
gcloud run deploy quickstart-function --source . \
--region YOUR_REGION_NAME \
--add-cloudsql-instances INSTANCE_CONNECTION_NAME
You may read through this document for more information on deploying cloud functions.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.