github.com/jrasell/terraform@v0.6.17-0.20160523115548-2652f5232949/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 ## Argument Reference 103 104 The following arguments are supported: 105 106 * `name` - (Required) Specifies the name of the virtual machine resource. Changing this forces a 107 new resource to be created. 108 * `resource_group_name` - (Required) The name of the resource group in which to 109 create the virtual machine. 110 * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. 111 * `plan` - (Optional) A plan block as documented below. 112 * `availability_set_id` - (Optional) The Id of the Availablity Set in which to create the virtual machine 113 * `vm_size` - (Required) Specifies the [size of the virtual machine](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-size-specs/). 114 * `storage_image_reference` - (Optional) A Storage Image Reference block as documented below. 115 * `storage_os_disk` - (Required) A Storage OS Disk block as referenced below. 116 * `storage_data_disk` - (Optional) A list of Storage Data disk blocks as referenced below. 117 * `os_profile` - (Required) An OS Profile block as documented below. 118 * `os_profile_windows_config` - (Required, when a windows machine) A Windows config block as documented below. 119 * `os_profile_linux_config` - (Required, when a linux machine) A Linux config block as documented below. 120 * `os_profile_secrets` - (Optional) A collection of Secret blocks as documented below. 121 * `network_interface_ids` - (Required) Specifies the list of resource IDs for the network interfaces associated with the virtual machine. 122 * `tags` - (Optional) A mapping of tags to assign to the resource. 123 124 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) 125 126 `Plan` supports the following: 127 128 * `name` - (Required) Specifies the name of the image from the marketplace. 129 * `publisher` - (Optional) Specifies the publisher of the image. 130 * `product` - (Optional) Specifies the product of the image from the marketplace. 131 132 `storage_image_reference` supports the following: 133 134 * `publisher` - (Required) Specifies the publisher of the image used to create the virtual machine 135 * `offer` - (Required) Specifies the offer of the image used to create the virtual machine. 136 * `sku` - (Required) Specifies the SKU of the image used to create the virtual machine. 137 * `version` - (Optional) Specifies the version of the image used to create the virtual machine. 138 139 `storage_os_disk` supports the following: 140 141 * `name` - (Required) Specifies the disk name. 142 * `vhd_uri` - (Required) Specifies the vhd uri. 143 * `create_option` - (Required) Specifies how the virtual machine should be created. Possible values are `attach` and `FromImage`. 144 * `caching` - (Optional) Specifies the caching requirements. 145 * `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. 146 * `os_type` - (Optional) Specifies the operating system Type, valid values are windows, linux. 147 148 `storage_data_disk` supports the following: 149 150 * `name` - (Required) Specifies the name of the data disk. 151 * `vhd_uri` - (Required) Specifies the uri of the location in storage where the vhd for the virtual machine should be placed. 152 * `create_option` - (Required) Specifies how the data disk should be created. 153 * `disk_size_gb` - (Required) Specifies the size of the data disk in gigabytes. 154 * `lun` - (Required) Specifies the logical unit number of the data disk. 155 156 `os_profile` supports the following: 157 158 * `computer_name` - (Optional) Specifies the name of the virtual machine. 159 * `admin_username` - (Required) Specifies the name of the administrator account. 160 * `admin_password` - (Required) Specifies the password of the administrator account. 161 * `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. 162 163 ~> **NOTE:** `admin_password` must be between 6-72 characters long and must satisfy at least 3 of password complexity requirements from the following: 164 1. Contains an uppercase character 165 2. Contains a lowercase character 166 3. Contains a numeric digit 167 4. Contains a special character 168 169 `os_profile_windows_config` supports the following: 170 171 * `provision_vm_agent` - (Optional) 172 * `enable_automatic_upgrades` - (Optional) 173 * `winrm` - (Optional) A collection of WinRM configuration blocks as documented below. 174 * `additional_unattend_config` - (Optional) An Additional Unattended Config block as documented below. 175 176 `winrm` supports the following: 177 178 * `protocol` - (Required) Specifies the protocol of listener 179 * `certificate_url` - (Optional) Specifies URL of the certificate with which new Virtual Machines is provisioned. 180 181 `additional_unattend_config` supports the following: 182 183 * `pass` - (Required) Specifies the name of the pass that the content applies to. The only allowable value is `oobeSystem`. 184 * `component` - (Required) Specifies the name of the component to configure with the added content. The only allowable value is `Microsoft-Windows-Shell-Setup`. 185 * `setting_name` - (Required) Specifies the name of the setting to which the content applies. Possible values are: `FirstLogonCommands` and `AutoLogon`. 186 * `content` - (Optional) Specifies the base-64 encoded XML formatted content that is added to the unattend.xml file for the specified path and component. 187 188 `os_profile_linux_config` supports the following: 189 190 * `disable_password_authentication` - (Required) Specifies whether password authentication should be disabled. 191 * `ssh_keys` - (Optional) Specifies a collection of `path` and `key_data` to be placed on the virtual machine. 192 193 ~> **Note:** Please note that the only allowed `path` is `/home/<username>/.ssh/authorized_keys` due to a limitation of Azure_ 194 195 `os_profile_secrets` supports the following: 196 197 * `source_vault_id` - (Required) Specifies the key vault to use. 198 * `vault_certificates` - (Required, on windows machines) A collection of Vault Certificates as documented below 199 200 `vault_certificates` support the following: 201 202 * `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`. 203 * `certificate_store` - (Required, on windows machines) Specifies the certificate store on the Virtual Machine where the certificate should be added to. 204 205 ## Attributes Reference 206 207 The following attributes are exported: 208 209 * `id` - The virtual machine ID.