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