Recently I started working on GCP, and for one of my POC I wanted cloud SQL. As this was POC I did not want it to run 24×7 and was trying to find a way to auto shutdown at a particular time to save cost. I don’t think there is any in-built option for that. However, GCP cloud scheduler has an option to call http request at a scheduled interval. This is good, as cloud SQL allows to have some management operation done through rest calls.
New I AM Service Account
For Scheduler to successfully run shutdown operation, it needs to be associated with associated with a service account with proper roles. So let’s create a new service account.
- Navigate to I am and then click on service account. You’re screen might look like this.
- now let’s put some name and description. I normally put service at the start of the name, but it’s not necessary.
- After this, we need to associate proper role to this account. For this we are going to choose Clod SQL Admin
- For this purpose we don’t need to associate any user to this service account.
New Scheduler
- Navigate to scheduler and click on create job . And fill the name, description, frequency and Timezone.
- For this choose Target Type as HTTP. Your url should be as mentioned below.
URL: https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
Method: Patch
Auth Header: Add OAuth Token
Service Account: service-mange-cloud-sql (one we created in above step, if your name is different please choose that)
Body:
{ "settings": { "activationPolicy": "NEVER" } }
- In the next step you can configure retry, I am keeping it default for simplicity.
- one successfully created you should be able to see your job on scheduler home page. Here you can test your job as well.
Be First to Comment