0

I understand that VM's in Azure will be charged if it just exists and even if we dont use it.

To Minimize cost I want to automate the VM creation and deletion so that VM is not available/idle when not n use.

I want the VM to be deleted after my usage session/scheduled time (just VM only, drives can be intact in storage account) and similarly next time when I want to start using VM, i want to create it and attach the storage (drives) to VM.

I want to automate (e.g Create/Delete on pre-scheduled time or just in one click) this creation and deletion with minimal intervention/user interaction.

How to achieve this? Any pointers to articles?

Venkatesh Muniyandi
  • 5,132
  • 2
  • 37
  • 40
  • I think you might have misunderstood the VM pricing model - if you have a running VM, you're charged per hour whether you're using it or not (e.g. sitting at 0% or 100% CPU - same cost). A stopped VM doesn't cost anything, aside from storage cost for the OS and data disks. – David Makogon Aug 03 '16 at 11:13

2 Answers2

2

One good way would be to create an Azure Automation job to do what you're trying to achieve :

You could choose your approach as you'd please; using classical PowerShell commands to set up / tear down your environment or use the Resource manager to do this.

You could for instance create two runbooks; one for creating / starting the VM and one for tearing down or stopping the VM. Just listing that it could be an option of shutting down the VM only if the other costs (storage, network etc) are acceptable. If not; tear it down and rebuild it again (easiest way would be to use resource manager / template (ARM) to provision this).

If you choose to go for using Azure automation you could schedule the runbooks on specific times or events (e.g. by using Azure Scheduler).

Some links that'll help you:

Hope this helps, point you in the right direction:)

Harald F.
  • 4,505
  • 24
  • 29
1

Azure VMs are not charged if they are stopped . Typically if you are using couple of VMs you can make it a habit of going to the portal and stop them or run a powershell script to achieve the same. If you are looking at something like a work environment with multiple VMS and say you need them to started at 9 am and stopped at 9 pm you need to use azure automation runbooks and schedule them.

First you create runbooks for starting and stopping VMs in a given subscription and add the required commandlets( PS) and then create a schedule and link the schedule with the appropriate runbook.

https://azure.microsoft.com/en-in/documentation/articles/automation-solution-startstopvm-graphical/

https://azure.microsoft.com/en-in/documentation/articles/automation-scheduling-a-runbook/

https://blogs.endjin.com/2016/03/using-azure-automation-to-run-vms-during-office-hours-only-using-graphical-runbooks/

I believe you can achieve it via function apps (which can be scheduled)also. But I have not tried it. https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-timer/

Aravind
  • 4,125
  • 1
  • 28
  • 39