in today's world automated systems are super important for any business and one of these
systems is the automatic start and shutdown of virtual machines in azure using logic apps for
the auto start and auto shutdown of VMS has several benefits you can save time and effort
by automating the process you can save a lot by ensuring VMS are only running when they are needed
with this feature you can have greater flexibility in scheduling the start and shutdown of VMS and
the best part is that it integrates with the other Azure services like Azure Automation and
Azure run books so Azure logic apps is a really cool cloud-based service that helps you create
automated workflows and integrate with all kinds of different services in this video I'm going to
show you how easy it is to use logic apps to automatically start and shut down of VMS in
Azure let's get started so I've already logged into Azure portal I will type logic apps in the
search bar and I will select that click on the add button to create a new logic app and I'm going to
select my pay as you go subscription I will select my Resource Group Resource Group 1 I will give a
name to logic app I will call this as TB logic app one and it should be unique in azurewebsites.net
domain next you need to select your region so I'm going to keep East US selected next up you need
to select the plan type for this demo I'm going to select consumption plan type which is best for
entry level pay only as much as your workflow runs there's another plan which is standard
which suits best for Enterprise level serverless application with event-based scaling and network
isolation so if I select standard plan type I get more options such as pricing plan publishing
options hosting options networking options and monitoring options but I'm going to select the
plan type consumption for consumption plan type you can enable log analytics if you have one I
don't have one and that is the reason why enable log analytics option is disabled for the zone
redundancy I will keep disabled selected which will make the logic apps not to use availability
Zone I will click on next tags if you would like to specify any tagging you can do that I will skip
this and click next review press create now you can review your selections and click on create
make sure the logic app is created all right this is done next I will create a workflow to
Auto Stop the VMS so I will go to logic apps by clicking on go to resource click on logic app
designer on the left side scroll down and select a blank logic app under templates type schedule
in the search bar and select that I will select recurrence trigger and add it to the workflow
now you need to configure the recurrence trigger with the desired interval and frequency so I will
specify one for the interval and for the frequency I will select week this means the workflow runs
the days which I am going to specify now you also have other options for the frequencies
such as month day hour minute second and you can edit custom value I will select week now if you
want to run this workflow every day just change the frequency parameter today with interval one
I'll select week again now if you want to set up a different schedule for weekend then you have to
create another logic app with different schedule so one logic app for weekdays and another one
for weekends you can also specify a Time Zone by selecting add new parameter I'll select time zone
and I will select IST Indian Standard time all right and I'll click on add new parameter and
I'll select on these days and now I will select Monday Tuesday Wednesday Thursday and Friday so
this will run only during weekdays now I'm going to select add new parameter and I'll select at
these hours so I will specify 22 select add new parameter and I'll say at these minutes and I'll
say zero so now you can see a preview which says runs at 22 on Monday Tuesday Wednesday Thursday
Friday every week so this defines my schedule next I'm going to add a new Step first thing I
will add dallocate VM by typing in the search box I will select de-allocate because it will stop the
VM and then deallocate the virtual machine as it will stop incurring costs to your virtual machine
so I'll select deallocate virtual machine next you need to select your tenant so you can see you have
three options you can simply click on sign in and of course sign in with your own Azure credential
you can also use a service principle by using the option connect with service principle or you can
use managed identity by using the option connect with managed identity using a service principle
or managed identity is strongly recommended but you need to make sure to assign permission to
allow the service principle or managed identity to manage your virtual machines you can use the
built-in role virtual machine contributor and assign it to the service principle or managed
identity but for this demo I'm going to use my own credential so I'm going to click on sign in
and I will select my account I will now select my subscription pay as you go and
I'll also select my Resource Group Resource Group 1 and I will select the virtual machine
which I'm going to Auto Stop in my case it is vm1 now to add more virtual machine just click
on the plus sign between the recurrence block and the deallocate virtual machine block so a pop-up
will appear with the option add a parallel Branch select that now a new parallel task
will open and you can do the same for the other virtual machine I'm going to cancel this I will
click on save to save the workflow and that's it the logic app is saved so it is configured
to Auto Stop the VM vm1 at 22 PM but on weekdays only all right now you can set up the auto start
of the VMS using the same logic app so I'm going to click on plus new Step button type schedule
expand it and scroll down a little select schedule click on delay schedule under actions so now here
you need to specify X number of hours after the first recurrence to execute another task
in other words I will wait for 12 hours after I have executed the first recurrence task which
is to deallocate virtual machine so the 12 hours would be 9 am the next day morning for the unit
I'm going to select hour now I'm going to add another step by clicking plus new step to add
the action start virtual machine I will select that under actions now I'm going to select my
subscription pay as you go and the resource Group Resource Group 1 and the virtual machine vm1 I
will click save to save the workflow and that's it the logic app is saved so it is configured to Auto
Stop the VM vm1 at 22 PM every day but on weekdays only after that it will wait for 12 hours and auto
start the VM vm1 at 9 00 am the next day morning but again only on weekdays all right this is it
this is how you create Azure logic apps and use it to automatically start and shutdown of virtual
machines I hope you like this video for more videos like these please subscribe to my channel