github.com/alkar/terraform@v0.9.6-0.20170517124458-a4cddf6ebf59/website/source/docs/providers/azurerm/r/virtual_machine_scale_sets.html.markdown (about)

     1  ---
     2  layout: "azurerm"
     3  page_title: "Azure Resource Manager: azurerm_virtual_machine_scale_sets"
     4  sidebar_current: "docs-azurerm-resource-virtualmachine-scale-sets"
     5  description: |-
     6    Create a Virtual Machine scale set.
     7  ---
     8  
     9  # azurerm\_virtual\_machine\_scale\_sets
    10  
    11  Create a virtual machine scale set.
    12  
    13  ~> **Note:** All arguments including the administrator login and password will be stored in the raw state as plain-text.
    14  [Read more about sensitive data in state](/docs/state/sensitive-data.html).
    15  
    16  ## Example Usage
    17  
    18  ```hcl
    19  resource "azurerm_resource_group" "test" {
    20    name     = "acctestrg"
    21    location = "West US"
    22  }
    23  
    24  resource "azurerm_virtual_network" "test" {
    25    name                = "acctvn"
    26    address_space       = ["10.0.0.0/16"]
    27    location            = "West US"
    28    resource_group_name = "${azurerm_resource_group.test.name}"
    29  }
    30  
    31  resource "azurerm_subnet" "test" {
    32    name                 = "acctsub"
    33    resource_group_name  = "${azurerm_resource_group.test.name}"
    34    virtual_network_name = "${azurerm_virtual_network.test.name}"
    35    address_prefix       = "10.0.2.0/24"
    36  }
    37  
    38  resource "azurerm_storage_account" "test" {
    39    name                = "accsa"
    40    resource_group_name = "${azurerm_resource_group.test.name}"
    41    location            = "westus"
    42    account_type        = "Standard_LRS"
    43  
    44    tags {
    45      environment = "staging"
    46    }
    47  }
    48  
    49  resource "azurerm_storage_container" "test" {
    50    name                  = "vhds"
    51    resource_group_name   = "${azurerm_resource_group.test.name}"
    52    storage_account_name  = "${azurerm_storage_account.test.name}"
    53    container_access_type = "private"
    54  }
    55  
    56  resource "azurerm_virtual_machine_scale_set" "test" {
    57    name                = "mytestscaleset-1"
    58    location            = "West US"
    59    resource_group_name = "${azurerm_resource_group.test.name}"
    60    upgrade_policy_mode = "Manual"
    61  
    62    sku {
    63      name     = "Standard_A0"
    64      tier     = "Standard"
    65      capacity = 2
    66    }
    67  
    68    os_profile {
    69      computer_name_prefix = "testvm"
    70      admin_username       = "myadmin"
    71      admin_password       = "Passwword1234"
    72    }
    73  
    74    os_profile_linux_config {
    75      disable_password_authentication = true
    76  
    77      ssh_keys {
    78        path     = "/home/myadmin/.ssh/authorized_keys"
    79        key_data = "${file("~/.ssh/demo_key.pub")}"
    80      }
    81    }
    82  
    83    network_profile {
    84      name    = "TestNetworkProfile"
    85      primary = true
    86  
    87      ip_configuration {
    88        name      = "TestIPConfiguration"
    89        subnet_id = "${azurerm_subnet.test.id}"
    90      }
    91    }
    92  
    93    storage_profile_os_disk {
    94      name           = "osDiskProfile"
    95      caching        = "ReadWrite"
    96      create_option  = "FromImage"
    97      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
    98    }
    99  
   100    storage_profile_image_reference {
   101      publisher = "Canonical"
   102      offer     = "UbuntuServer"
   103      sku       = "14.04.2-LTS"
   104      version   = "latest"
   105    }
   106  }
   107  ```
   108  
   109  ## Example Usage with Managed Disks
   110  
   111  ```
   112  resource "azurerm_resource_group" "test" {
   113    name     = "acctestrg"
   114    location = "West US 2"
   115  }
   116  
   117  resource "azurerm_virtual_network" "test" {
   118    name                = "acctvn"
   119    address_space       = ["10.0.0.0/16"]
   120    location            = "West US 2"
   121    resource_group_name = "${azurerm_resource_group.test.name}"
   122  }
   123  
   124  resource "azurerm_subnet" "test" {
   125    name                 = "acctsub"
   126    resource_group_name  = "${azurerm_resource_group.test.name}"
   127    virtual_network_name = "${azurerm_virtual_network.test.name}"
   128    address_prefix       = "10.0.2.0/24"
   129  }
   130  
   131  resource "azurerm_public_ip" "test" {
   132    name                         = "test"
   133    location                     = "West US 2"
   134    resource_group_name          = "${azurerm_resource_group.test.name}"
   135    public_ip_address_allocation = "static"
   136    domain_name_label            = "${azurerm_resource_group.test.name}"
   137  
   138    tags {
   139      environment = "staging"
   140    }
   141  }
   142  
   143  resource "azurerm_lb" "test" {
   144    name                = "test"
   145    location            = "West US 2"
   146    resource_group_name = "${azurerm_resource_group.test.name}"
   147  
   148    frontend_ip_configuration {
   149      name                 = "PublicIPAddress"
   150      public_ip_address_id = "${azurerm_public_ip.test.id}"
   151    }
   152  }
   153  
   154  resource "azurerm_lb_backend_address_pool" "bpepool" {
   155    resource_group_name = "${azurerm_resource_group.test.name}"
   156    loadbalancer_id     = "${azurerm_lb.test.id}"
   157    name                = "BackEndAddressPool"
   158  }
   159  
   160  resource "azurerm_lb_nat_pool" "lbnatpool" {
   161    count                          = 3
   162    resource_group_name            = "${azurerm_resource_group.test.name}"
   163    name                           = "ssh"
   164    loadbalancer_id                = "${azurerm_lb.test.id}"
   165    protocol                       = "Tcp"
   166    frontend_port_start            = 50000
   167    frontend_port_end              = 50119
   168    backend_port                   = 22
   169    frontend_ip_configuration_name = "PublicIPAddress"
   170  }
   171  
   172  resource "azurerm_virtual_machine_scale_set" "test" {
   173    name                = "mytestscaleset-1"
   174    location            = "West US 2"
   175    resource_group_name = "${azurerm_resource_group.test.name}"
   176    upgrade_policy_mode = "Manual"
   177  
   178    sku {
   179      name     = "Standard_A0"
   180      tier     = "Standard"
   181      capacity = 2
   182    }
   183  
   184    storage_profile_image_reference {
   185      publisher = "Canonical"
   186      offer     = "UbuntuServer"
   187      sku       = "14.04.2-LTS"
   188      version   = "latest"
   189    }
   190  
   191    storage_profile_os_disk {
   192      name              = "myosdisk"
   193      caching           = "ReadWrite"
   194      create_option     = "FromImage"
   195      managed_disk_type = "Standard_LRS"
   196    }
   197  
   198    os_profile {
   199      computer_name_prefix = "testvm"
   200      admin_username       = "myadmin"
   201      admin_password       = "Passwword1234"
   202    }
   203  
   204    os_profile_linux_config {
   205      disable_password_authentication = true
   206  
   207      ssh_keys {
   208        path     = "/home/myadmin/.ssh/authorized_keys"
   209        key_data = "${file("~/.ssh/demo_key.pub")}"
   210      }
   211    }
   212  
   213    network_profile {
   214      name    = "terraformnetworkprofile"
   215      primary = true
   216  
   217      ip_configuration {
   218        name                                   = "TestIPConfiguration"
   219        subnet_id                              = "${azurerm_subnet.test.id}"
   220        load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.bpepool.id}"]
   221        load_balancer_inbound_nat_rules_ids    = ["${element(azurerm_lb_nat_pool.lbnatpool.*.id, count.index)}"]
   222      }
   223    }
   224  
   225    tags {
   226      environment = "staging"
   227    }
   228  }
   229  ```
   230  
   231  ## Argument Reference
   232  
   233  The following arguments are supported:
   234  
   235  * `name` - (Required) Specifies the name of the virtual machine scale set resource. Changing this forces a
   236      new resource to be created.
   237  * `resource_group_name` - (Required) The name of the resource group in which to
   238      create the virtual machine scale set. Changing this forces a new resource to be created.
   239  * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.
   240  * `sku` - (Required) A sku block as documented below.
   241  * `upgrade_policy_mode` - (Required) Specifies the mode of an upgrade to virtual machines in the scale set. Possible values, `Manual` or `Automatic`.
   242  * `overprovision` - (Optional) Specifies whether the virtual machine scale set should be overprovisioned.
   243  * `single_placement_group` - (Optional) Specifies whether the scale set is limited to a single placement group with a maximum size of 100 virtual machines. If set to false, managed disks must be used. Default is true. Changing this forces a
   244      new resource to be created. See [documentation](http://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-placement-groups) for more information.
   245  * `os_profile` - (Required) A Virtual Machine OS Profile block as documented below.
   246  * `os_profile_secrets` - (Optional) A collection of Secret blocks as documented below.
   247  * `os_profile_windows_config` - (Required, when a windows machine) A Windows config block as documented below.
   248  * `os_profile_linux_config` - (Required, when a linux machine) A Linux config block as documented below.
   249  * `network_profile` - (Required) A collection of network profile block as documented below.
   250  * `storage_profile_os_disk` - (Required) A storage profile os disk block as documented below
   251  * `storage_profile_image_reference` - (Optional) A storage profile image reference block as documented below.
   252  * `extension` - (Optional) Can be specified multiple times to add extension profiles to the scale set. Each `extension` block supports the fields documented below.
   253  * `tags` - (Optional) A mapping of tags to assign to the resource.
   254  
   255  
   256  `sku` supports the following:
   257  
   258  * `name` - (Required) Specifies the size of virtual machines in a scale set.
   259  * `tier` - (Optional) Specifies the tier of virtual machines in a scale set. Possible values, `standard` or `basic`.
   260  * `capacity` - (Required) Specifies the number of virtual machines in the scale set.
   261  
   262  `os_profile` supports the following:
   263  
   264  * `computer_name_prefix` - (Required) Specifies the computer name prefix for all of the virtual machines in the scale set. Computer name prefixes must be 1 to 15 characters long.
   265  * `admin_username` - (Required) Specifies the administrator account name to use for all the instances of virtual machines in the scale set.
   266  * `admin_password` - (Required) Specifies the administrator password to use for all the instances of virtual machines in a scale set..
   267  * `custom_data` - (Optional) Specifies custom data to supply to the machine. On linux-based systems, this can be used as a cloud-init script. On other systems, this will be copied as a file on disk. Internally, Terraform will base64 encode this value before sending it to the API. The maximum length of the binary array is 65535 bytes. Changing this forces a new resource to be created.
   268  
   269  `os_profile_secrets` supports the following:
   270  
   271  * `source_vault_id` - (Required) Specifies the key vault to use.
   272  * `vault_certificates` - (Required, on windows machines) A collection of Vault Certificates as documented below
   273  
   274  `vault_certificates` support the following:
   275  
   276  * `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`.
   277  * `certificate_store` - (Required, on windows machines) Specifies the certificate store on the Virtual Machine where the certificate should be added to.
   278  
   279  
   280  `os_profile_windows_config` supports the following:
   281  
   282  * `provision_vm_agent` - (Optional) Indicates whether virtual machine agent should be provisioned on the virtual machines in the scale set.
   283  * `enable_automatic_upgrades` - (Optional) Indicates whether virtual machines in the scale set are enabled for automatic updates.
   284  * `winrm` - (Optional) A collection of WinRM configuration blocks as documented below.
   285  * `additional_unattend_config` - (Optional) An Additional Unattended Config block as documented below.
   286  
   287  `winrm` supports the following:
   288  
   289  * `protocol` - (Required) Specifies the protocol of listener
   290  * `certificate_url` - (Optional) Specifies URL of the certificate with which new Virtual Machines is provisioned.
   291  
   292  `additional_unattend_config` supports the following:
   293  
   294  * `pass` - (Required) Specifies the name of the pass that the content applies to. The only allowable value is `oobeSystem`.
   295  * `component` - (Required) Specifies the name of the component to configure with the added content. The only allowable value is `Microsoft-Windows-Shell-Setup`.
   296  * `setting_name` - (Required) Specifies the name of the setting to which the content applies. Possible values are: `FirstLogonCommands` and `AutoLogon`.
   297  * `content` - (Optional) Specifies the base-64 encoded XML formatted content that is added to the unattend.xml file for the specified path and component.
   298  
   299  `os_profile_linux_config` supports the following:
   300  
   301  * `disable_password_authentication` - (Required) Specifies whether password authentication should be disabled. Changing this forces a new resource to be created.
   302  * `ssh_keys` - (Optional) Specifies a collection of `path` and `key_data` to be placed on the virtual machine.
   303  
   304  ~> _**Note:** Please note that the only allowed `path` is `/home/<username>/.ssh/authorized_keys` due to a limitation of Azure_
   305  
   306  
   307  `network_profile` supports the following:
   308  
   309  * `name` - (Required) Specifies the name of the network interface configuration.
   310  * `primary` - (Required) Indicates whether network interfaces created from the network interface configuration will be the primary NIC of the VM.
   311  * `ip_configuration` - (Required) An ip_configuration block as documented below
   312  
   313  `ip_configuration` supports the following:
   314  
   315  * `name` - (Required) Specifies name of the IP configuration.
   316  * `subnet_id` - (Required) Specifies the identifier of the subnet.
   317  * `load_balancer_backend_address_pool_ids` - (Optional) Specifies an array of references to backend address pools of load balancers. A scale set can reference backend address pools of one public and one internal load balancer. Multiple scale sets cannot use the same load balancer.
   318  * `load_balancer_inbound_nat_rules_ids` - (Optional) Specifies an array of references to inbound NAT rules for load balancers.
   319  
   320  `storage_profile_os_disk` supports the following:
   321  
   322  * `name` - (Required) Specifies the disk name.
   323  * `vhd_containers` - (Optional) Specifies the vhd uri. Cannot be used when `image` or `managed_disk_type` is specified.
   324  * `managed_disk_type` - (Optional) Specifies the type of managed disk to create. Value you must be either `Standard_LRS` or `Premium_LRS`. Cannot be used when `vhd_containers` or `image` is specified.
   325  * `create_option` - (Required) Specifies how the virtual machine should be created. The only possible option is `FromImage`.
   326  * `caching` - (Optional) Specifies the caching requirements. Possible values include: `None` (default), `ReadOnly`, `ReadWrite`.
   327  * `image` - (Optional) Specifies the blob uri for user image. A virtual machine scale set creates an os disk in the same container as the user image.
   328                         Updating the osDisk image causes the existing disk to be deleted and a new one created with the new image. If the VM scale set is in Manual upgrade mode then the virtual machines are not updated until they have manualUpgrade applied to them.
   329                         When setting this field `os_type` needs to be specified. Cannot be used when `vhd_containers`, `managed_disk_type` or `storage_profile_image_reference ` are specified.
   330  * `os_type` - (Optional) Specifies the operating system Type, valid values are windows, linux.
   331  
   332  `storage_profile_image_reference` supports the following:
   333  
   334  * `publisher` - (Required) Specifies the publisher of the image used to create the virtual machines
   335  * `offer` - (Required) Specifies the offer of the image used to create the virtual machines.
   336  * `sku` - (Required) Specifies the SKU of the image used to create the virtual machines.
   337  * `version` - (Optional) Specifies the version of the image used to create the virtual machines.
   338  
   339  `extension` supports the following:
   340  
   341  * `name` - (Required) Specifies the name of the extension.
   342  * `publisher` - (Required) The publisher of the extension, available publishers can be found by using the Azure CLI.
   343  * `type` - (Required) The type of extension, available types for a publisher can be found using the Azure CLI.
   344  * `type_handler_version` - (Required) Specifies the version of the extension to use, available versions can be found using the Azure CLI.
   345  * `auto_upgrade_minor_version` - (Optional) Specifies whether or not to use the latest minor version available.
   346  * `settings` - (Required) The settings passed to the extension, these are specified as a JSON object in a string.
   347  * `protected_settings` - (Optional) The protected_settings passed to the extension, like settings, these are specified as a JSON object in a string.
   348  
   349  ## Attributes Reference
   350  
   351  The following attributes are exported:
   352  
   353  * `id` - The virtual machine scale set ID.
   354  
   355  
   356  ## Import
   357  
   358  Virtual Machine Scale Sets can be imported using the `resource id`, e.g.
   359  
   360  ```
   361  terraform import azurerm_virtual_machine_scale_set.scaleset1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Compute/virtualMachineScaleSets/scaleset1
   362  ```