I am trying to implement a GCP instance group which will autoscale up and down as per the CPU usage. But there is an issue as my vm which is generated needs to have access to the sql database of GCP so is there any ways where i could use a startup script to add this vm's public ip to sql db connections? If this is not done the app would not be working as expected as the user will not be able to login to the VM
I think there are 2 options:
You may want to use the Cloud SQL proxy. When using the proxy you don't need to be allowing the external IPs of the VM instances.
You can configure a private IP for the Cloud SQL instance so you can connect to the instance using this IP. With this approach you don't need to allow any IP since privates IPs (RFC1918) are allowed by default, i.e, the internal IPs of the VMs.
You may to read about these 2 options and choose the better option for you.