Terraform to connect VM instance with Cloud SQL in GCP

I am able to write a terraform script to create VPC, Subnetwork and VM instance in Google cloud.
Able to write a script to create Cloud SQL and then ‘mysql’ instance.
Now I want to connect the VM instance to mysql. For that in mysql, at the connections tab, in the ip address, i have to mention the external IP of the vm instance in order to connect. How to write a terraform script on that?