-
Notifications
You must be signed in to change notification settings - Fork 2
VM Template
The VM template object allows you to specify the configuration to deploy 1 or more VMs. This is where you can state how many of a VM type you require, what provisioners to use, firewall rules to create, as well as the OS type (unless defined globally).
All VM templates are defined within the "template" array at the root of the JSON template file, and requires a "type" value of "vm":
{
"template": [
{
"type": "vm"
}
]
}Below are the properties that are used in defining the VM template object
| Name | Type | Required | Description |
|---|---|---|---|
| append | boolean | no | Whether or not to append the creation of new VMs (see below for example) |
| count | int | yes | The number of VMs to deploy for the template; must be greater than or equal to 1 |
| drives | Drive object | no | Defines additional unmanaged data disks to create and partition drives for the current VM |
| firewall | firewall object | no | The local inbound/outbound firewall rules for the current VM template |
| os | OS object | no (when global os object defined) |
The local OS object for this VM template. Note: not required if a global OS object is present and appropriate |
| port | int | no | The port the VMs are to be load balancer against. Note: Only required if count > 1 and useLoadBalancer is true or not supplied |
| provisioners | string array | no | A string array of provisioner keys, that will be run in order given to provisioner each VM |
| tag | string | yes | The tag-name of this VM template. ie, if core then VMs deployed will have the name [rg-name]-core[index]
|
| useAvailabilitySet | boolean | no |
Default: true. Whether or not the VMs should be placed into an Availability Set |
| type | string | yes | Specifies the type of template object, can be either vmor vpn
|
| useLoadBalancer | boolean | no |
Default: true. Whether or not the VMs should be load balanced |
| usePublicIP | boolean | no | Whether or not the VMs should have a public IP address |
The following are a couple of simple examples of VM templates.
The following VM template will deploy 1 VM, with remoting enabled and the RDP port open. It will also have a public IP address.
If you want more than 1 VM, just increase the count value!
{
"template": [
{
"type": "vm",
"tag": "example",
"count": 1,
"usePublicIP": true,
"provisioners": [ "remoting" ],
"os": {
"size": "Standard_DS1_v2",
"type": "Windows",
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"skus": "2016-Datacenter"
},
"firewall": {
"rdp|in": true
}
}
],
"provisioners": {
"remoting": "dsc: @{remoting}"
}
}The following VM template will deploy 3 VMs. They will all have IIS and .NET installed, with the HTTP port allowed outbound. All of the VMs will also be automatically load balanced for you.
Remember: when load balancing the
"port"property is required
{
"template": [
{
"type": "vm",
"tag": "web",
"count": 3,
"port": 80,
"usePublicIP": true,
"provisioners": [ "web-server" ],
"os": {
"size": "Standard_DS1_v2",
"type": "Windows",
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"skus": "2016-Datacenter"
},
"firewall": {
"http|out": true
}
}
],
"provisioners": {
"web-server": "dsc: @{web-server}"
}
}Try navigating to
http://<public-ip>, and you'll see the default IIS webpage
With Fogg it is possible to append the creation of new VMs, rather than always updating the same VMs.
For example, if your VM's template has a count of 1 then normally when you run Fogg the second time it will just re-use and update that VM. However, if that same template has the append property set to true then Fogg will create 1 new additional VM with the same configuration instead - rather than updating the previous one. This is useful for test environments where you need to spin-up VMs to run tests, and then deallocate/remove the previous VMs. And yes, if you set count to 2 while using append, Fogg will create 2 additional VMs.
{
"template": [
{
"type": "vm",
"tag": "append",
"count": 1,
"append": true,
"usePublicIP": true,
"provisioners": [ "remoting" ],
"os": {
"size": "Standard_DS1_v2",
"type": "Windows",
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"skus": "2016-Datacenter"
},
"firewall": {
"rdp|in": true
}
}
],
"provisioners": {
"remoting": "dsc: @{remoting}"
}
}Running this under a Resource Group example-rg once will give you a VM called example-append1. Running it again will create a new example-append2 VM, then example-append3 and so-on-forth.
Fogg allows you to create VMs with additional drives, rather than just the default C/D drives. An example of creating a VM with a 250GB F: drive for Logs is as follows:
{
"template": [
{
"type": "vm",
"tag": "drives",
"count": 1,
"usePublicIP": true,
"provisioners": [ "remoting" ],
"os": {
"size": "Standard_DS1_v2",
"type": "Windows",
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"skus": "2016-Datacenter"
},
"firewall": {
"rdp|in": true
},
"drives": [
{
"lun": 1,
"name": "Logs",
"letter": "F",
"size": 250,
"caching": "ReadOnly"
}
]
}
],
"provisioners": {
"remoting": "dsc: @{remoting}"
}
}For more information on the Drives object for VMs, click here