github.com/pmcatominey/terraform@v0.7.0-rc2.0.20160708105029-1401a52a5cc5/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown (about) 1 --- 2 layout: "azurerm" 3 page_title: "Azure Resource Manager: azurerm_virtual_machine" 4 sidebar_current: "docs-azurerm-resource-virtualmachine" 5 description: |- 6 Create a Virtual Machine. 7 --- 8 9 # azurerm\_virtual\_machine 10 11 Create a virtual machine. 12 13 ## Example Usage 14 15 ``` 16 resource "azurerm_resource_group" "test" { 17 name = "acctestrg" 18 location = "West US" 19 } 20 21 resource "azurerm_virtual_network" "test" { 22 name = "acctvn" 23 address_space = ["10.0.0.0/16"] 24 location = "West US" 25 resource_group_name = "${azurerm_resource_group.test.name}" 26 } 27 28 resource "azurerm_subnet" "test" { 29 name = "acctsub" 30 resource_group_name = "${azurerm_resource_group.test.name}" 31 virtual_network_name = "${azurerm_virtual_network.test.name}" 32 address_prefix = "10.0.2.0/24" 33 } 34 35 resource "azurerm_network_interface" "test" { 36 name = "acctni" 37 location = "West US" 38 resource_group_name = "${azurerm_resource_group.test.name}" 39 40 ip_configuration { 41 name = "testconfiguration1" 42 subnet_id = "${azurerm_subnet.test.id}" 43 private_ip_address_allocation = "dynamic" 44 } 45 } 46 47 resource "azurerm_storage_account" "test" { 48 name = "accsa" 49 resource_group_name = "${azurerm_resource_group.test.name}" 50 location = "westus" 51 account_type = "Standard_LRS" 52 53 tags { 54 environment = "staging" 55 } 56 } 57 58 resource "azurerm_storage_container" "test" { 59 name = "vhds" 60 resource_group_name = "${azurerm_resource_group.test.name}" 61 storage_account_name = "${azurerm_storage_account.test.name}" 62 container_access_type = "private" 63 } 64 65 resource "azurerm_virtual_machine" "test" { 66 name = "acctvm" 67 location = "West US" 68 resource_group_name = "${azurerm_resource_group.test.name}" 69 network_interface_ids = ["${azurerm_network_interface.test.id}"] 70 vm_size = "Standard_A0" 71 72 storage_image_reference { 73 publisher = "Canonical" 74 offer = "UbuntuServer" 75 sku = "14.04.2-LTS" 76 version = "latest" 77 } 78 79 storage_os_disk { 80 name = "myosdisk1" 81 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 82 caching = "ReadWrite" 83 create_option = "FromImage" 84 } 85 86 os_profile { 87 computer_name = "hostname" 88 admin_username = "testadmin" 89 admin_password = "Password1234!" 90 } 91 92 os_profile_linux_config { 93 disable_password_authentication = false 94 } 95 96 tags { 97 environment = "staging" 98 } 99 } 100 ``` 101 102 ## Example Usage with additional Empty DataDisk 103 104 ``` 105 resource "azurerm_resource_group" "test" { 106 name = "acctestrg" 107 location = "West US" 108 } 109 110 resource "azurerm_virtual_network" "test" { 111 name = "acctvn" 112 address_space = ["10.0.0.0/16"] 113 location = "West US" 114 resource_group_name = "${azurerm_resource_group.test.name}" 115 } 116 117 resource "azurerm_subnet" "test" { 118 name = "acctsub" 119 resource_group_name = "${azurerm_resource_group.test.name}" 120 virtual_network_name = "${azurerm_virtual_network.test.name}" 121 address_prefix = "10.0.2.0/24" 122 } 123 124 resource "azurerm_network_interface" "test" { 125 name = "acctni" 126 location = "West US" 127 resource_group_name = "${azurerm_resource_group.test.name}" 128 129 ip_configuration { 130 name = "testconfiguration1" 131 subnet_id = "${azurerm_subnet.test.id}" 132 private_ip_address_allocation = "dynamic" 133 } 134 } 135 136 resource "azurerm_storage_account" "test" { 137 name = "accsa" 138 resource_group_name = "${azurerm_resource_group.test.name}" 139 location = "westus" 140 account_type = "Standard_LRS" 141 142 tags { 143 environment = "staging" 144 } 145 } 146 147 resource "azurerm_storage_container" "test" { 148 name = "vhds" 149 resource_group_name = "${azurerm_resource_group.test.name}" 150 storage_account_name = "${azurerm_storage_account.test.name}" 151 container_access_type = "private" 152 } 153 154 resource "azurerm_virtual_machine" "test" { 155 name = "acctvm" 156 location = "West US" 157 resource_group_name = "${azurerm_resource_group.test.name}" 158 network_interface_ids = ["${azurerm_network_interface.test.id}"] 159 vm_size = "Standard_A0" 160 161 storage_image_reference { 162 publisher = "Canonical" 163 offer = "UbuntuServer" 164 sku = "14.04.2-LTS" 165 version = "latest" 166 } 167 168 storage_os_disk { 169 name = "myosdisk1" 170 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 171 caching = "ReadWrite" 172 create_option = "FromImage" 173 } 174 175 storage_data_disk { 176 name = "datadisk0" 177 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/datadisk0.vhd" 178 disk_size_gb = "1023" 179 create_option = "empty" 180 lun = 0 181 } 182 183 os_profile { 184 computer_name = "hostname" 185 admin_username = "testadmin" 186 admin_password = "Password1234!" 187 } 188 189 os_profile_linux_config { 190 disable_password_authentication = false 191 } 192 193 tags { 194 environment = "staging" 195 } 196 } 197 ``` 198 199 ## Argument Reference 200 201 The following arguments are supported: 202 203 * `name` - (Required) Specifies the name of the virtual machine resource. Changing this forces a 204 new resource to be created. 205 * `resource_group_name` - (Required) The name of the resource group in which to 206 create the virtual machine. 207 * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. 208 * `plan` - (Optional) A plan block as documented below. 209 * `availability_set_id` - (Optional) The Id of the Availablity Set in which to create the virtual machine 210 * `vm_size` - (Required) Specifies the [size of the virtual machine](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-size-specs/). 211 * `storage_image_reference` - (Optional) A Storage Image Reference block as documented below. 212 * `storage_os_disk` - (Required) A Storage OS Disk block as referenced below. 213 * `storage_data_disk` - (Optional) A list of Storage Data disk blocks as referenced below. 214 * `os_profile` - (Required) An OS Profile block as documented below. 215 * `os_profile_windows_config` - (Required, when a windows machine) A Windows config block as documented below. 216 * `os_profile_linux_config` - (Required, when a linux machine) A Linux config block as documented below. 217 * `os_profile_secrets` - (Optional) A collection of Secret blocks as documented below. 218 * `network_interface_ids` - (Required) Specifies the list of resource IDs for the network interfaces associated with the virtual machine. 219 * `tags` - (Optional) A mapping of tags to assign to the resource. 220 221 For more information on the different example configurations, please check out the [azure documentation](https://msdn.microsoft.com/en-us/library/mt163591.aspx#Anchor_2) 222 223 `Plan` supports the following: 224 225 * `name` - (Required) Specifies the name of the image from the marketplace. 226 * `publisher` - (Optional) Specifies the publisher of the image. 227 * `product` - (Optional) Specifies the product of the image from the marketplace. 228 229 `storage_image_reference` supports the following: 230 231 * `publisher` - (Required) Specifies the publisher of the image used to create the virtual machine 232 * `offer` - (Required) Specifies the offer of the image used to create the virtual machine. 233 * `sku` - (Required) Specifies the SKU of the image used to create the virtual machine. 234 * `version` - (Optional) Specifies the version of the image used to create the virtual machine. 235 236 `storage_os_disk` supports the following: 237 238 * `name` - (Required) Specifies the disk name. 239 * `vhd_uri` - (Required) Specifies the vhd uri. 240 * `create_option` - (Required) Specifies how the virtual machine should be created. Possible values are `attach` and `FromImage`. 241 * `caching` - (Optional) Specifies the caching requirements. 242 * `image_uri` - (Optional) Specifies the image_uri in the form publisherName:offer:skus:version. `image_uri` can also specify the [VHD uri](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-deploy-templates/#create-a-custom-vm-image) of a custom VM image to clone. When cloning a custom disk image the `os_type` documented below becomes required. 243 * `os_type` - (Optional) Specifies the operating system Type, valid values are windows, linux. 244 245 `storage_data_disk` supports the following: 246 247 * `name` - (Required) Specifies the name of the data disk. 248 * `vhd_uri` - (Required) Specifies the uri of the location in storage where the vhd for the virtual machine should be placed. 249 * `create_option` - (Required) Specifies how the data disk should be created. 250 * `disk_size_gb` - (Required) Specifies the size of the data disk in gigabytes. 251 * `lun` - (Required) Specifies the logical unit number of the data disk. 252 253 `os_profile` supports the following: 254 255 * `computer_name` - (Optional) Specifies the name of the virtual machine. 256 * `admin_username` - (Required) Specifies the name of the administrator account. 257 * `admin_password` - (Required) Specifies the password of the administrator account. 258 * `custom_data` - (Optional) Specifies a base-64 encoded string of custom data. The base-64 encoded string is decoded to a binary array that is saved as a file on the Virtual Machine. The maximum length of the binary array is 65535 bytes. 259 260 ~> **NOTE:** `admin_password` must be between 6-72 characters long and must satisfy at least 3 of password complexity requirements from the following: 261 1. Contains an uppercase character 262 2. Contains a lowercase character 263 3. Contains a numeric digit 264 4. Contains a special character 265 266 `os_profile_windows_config` supports the following: 267 268 * `provision_vm_agent` - (Optional) 269 * `enable_automatic_upgrades` - (Optional) 270 * `winrm` - (Optional) A collection of WinRM configuration blocks as documented below. 271 * `additional_unattend_config` - (Optional) An Additional Unattended Config block as documented below. 272 273 `winrm` supports the following: 274 275 * `protocol` - (Required) Specifies the protocol of listener 276 * `certificate_url` - (Optional) Specifies URL of the certificate with which new Virtual Machines is provisioned. 277 278 `additional_unattend_config` supports the following: 279 280 * `pass` - (Required) Specifies the name of the pass that the content applies to. The only allowable value is `oobeSystem`. 281 * `component` - (Required) Specifies the name of the component to configure with the added content. The only allowable value is `Microsoft-Windows-Shell-Setup`. 282 * `setting_name` - (Required) Specifies the name of the setting to which the content applies. Possible values are: `FirstLogonCommands` and `AutoLogon`. 283 * `content` - (Optional) Specifies the base-64 encoded XML formatted content that is added to the unattend.xml file for the specified path and component. 284 285 `os_profile_linux_config` supports the following: 286 287 * `disable_password_authentication` - (Required) Specifies whether password authentication should be disabled. 288 * `ssh_keys` - (Optional) Specifies a collection of `path` and `key_data` to be placed on the virtual machine. 289 290 ~> **Note:** Please note that the only allowed `path` is `/home/<username>/.ssh/authorized_keys` due to a limitation of Azure_ 291 292 `os_profile_secrets` supports the following: 293 294 * `source_vault_id` - (Required) Specifies the key vault to use. 295 * `vault_certificates` - (Required, on windows machines) A collection of Vault Certificates as documented below 296 297 `vault_certificates` support the following: 298 299 * `certificate_url` - (Required) It is the Base64 encoding of a JSON Object that which is encoded in UTF-8 of which the contents need to be `data`, `dataType` and `password`. 300 * `certificate_store` - (Required, on windows machines) Specifies the certificate store on the Virtual Machine where the certificate should be added to. 301 302 ## Attributes Reference 303 304 The following attributes are exported: 305 306 * `id` - The virtual machine ID.