Reputation: 18600
In GCP, I'd like to start a VM through the Instance Scheduler on one day/time, and stop it on another day/time.
I thought I could create two schedulers to accomplish this, but this is not possible, as I receive this error message on the attempt to attach the VM to the second created scheduler:
Invalid resource usage: 'Instance already has instance schedule policy attached. Attaching multiple policies is not supported.'.
How can I accomplish stopping the VM on a different day than what it is starting at? (Ideally through the GCP Console)
Here's a screenshot of the VM Start configured.
Upvotes: 1
Views: 1314
Reputation: 2323
Instance schedules let you start and stop VM instances at specified times automatically. Each VM instance can only follow one instance schedule, but you can attach each instance schedule to up to 1,000 VM instances. You can only attach an instance schedule to VM instances that are located in the same region as the instance schedule.
So, if you want to start the vm at a specific day and time of a month and stop the vm on another specific day and time of the month, you can achieve this using cron expressions while creating the instance schedule.
To enable cron expressions, click the Use CRON expression toggle at the top of the pane while creating the instance schedule.
Enter a Start CRON expression, Stop CRON expression, or both.
In the Start CRON expression field, enter a cron expression that describes when to start VM instances.
In the Stop CRON expression field, enter a cron expression that describes when to stop VM instances
In the Initiate date field, type or click date_range to select the date and time when you want this instance schedule to begin. If omitted, the schedule is effective immediately.
In the End date field, type or click date_range to select the date and time when you want this instance schedule to end. If omitted, the schedule is effective indefinitely.
The following table defines the fields of a cron expression and the supported values for each field.
Minute | Hour | Day of the month | Month | Day of the week |
---|---|---|---|---|
0-59 | 0-23 | 1-31 | 1-12 (where 29-31 are only effective for relevant months) | 0-6 or SUN-SAT (Sunday-Saturday), where 0=SUN, 1=MON, … 6=SAT |
For example , if you want to start the vm on April 30 and stop the vm on May 5, you can specify the cron expression as follows
VM Start expression : 30 10 30 4 *
VM Stop expression : 30 10 5 5 *
Here * indicates that if the day-of-the-month field, month field, and day-of-the-week field are all set to *, the schedule repeats every day.
When you write a cron expression, consider the following:
Whitespace is used to separate the fields of a cron expression. Remember to not add extra whitespace in a field that is using special characters.
Below is the reference screenshot to configure the instance schedule using cron expression:
You can verify if the instance schedule runs successfully by checking the audit logs for the instance schedule resource policy and the attached VM instance. You might need to wait for up to 15 minutes after the scheduled time for each operation.
Refer to the link for information on instance schedule and cron expression
Upvotes: 2