[MS] provider/azurerm: Virtual Machine Scale Sets with managed disk support (#13717)

* added vmss with managed disk support

* Update vmss docs

* update vmss test

* added vmss managed disk import test

* update vmss tests

* remove unused test resources

* reverting breaking changes on storage_os_disk and storage_image_reference

* updated vmss tests and documentation

* updated vmss flatten osdisk

* updated vmss resource and import test

* update name in vmss osdisk

* update vmss test to include a blank name

* update vmss test to include a blank name
This commit is contained in:
Sertaç Özercan 2017-05-12 05:58:00 -07:00 committed by Paul Stack
parent 15a5a84cd1
commit e0cd380814
5 changed files with 715 additions and 352 deletions

View File

@ -31,6 +31,29 @@ func TestAccAzureRMVirtualMachineScaleSet_importBasic(t *testing.T) {
}) })
} }
func TestAccAzureRMVirtualMachineScaleSet_importBasic_managedDisk(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk, ri, ri, ri, ri, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccAzureRMVirtualMachineScaleSet_importLinux(t *testing.T) { func TestAccAzureRMVirtualMachineScaleSet_importLinux(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test" resourceName := "azurerm_virtual_machine_scale_set.test"

View File

@ -266,6 +266,14 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString, Set: schema.HashString,
}, },
"load_balancer_inbound_nat_rules_ids": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
}, },
}, },
}, },
@ -297,9 +305,21 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Set: schema.HashString, Set: schema.HashString,
}, },
"managed_disk_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"storage_profile_os_disk.vhd_containers"},
ValidateFunc: validation.StringInSlice([]string{
string(compute.PremiumLRS),
string(compute.StandardLRS),
}, true),
},
"caching": { "caching": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Optional: true,
Computed: true,
}, },
"os_type": { "os_type": {
@ -708,6 +728,14 @@ func flattenAzureRmVirtualMachineScaleSetNetworkProfile(profile *compute.Virtual
config["load_balancer_backend_address_pool_ids"] = schema.NewSet(schema.HashString, addressPools) config["load_balancer_backend_address_pool_ids"] = schema.NewSet(schema.HashString, addressPools)
} }
if properties.LoadBalancerInboundNatPools != nil {
inboundNatPools := make([]interface{}, 0, len(*properties.LoadBalancerInboundNatPools))
for _, rule := range *properties.LoadBalancerInboundNatPools {
inboundNatPools = append(inboundNatPools, *rule.ID)
}
config["load_balancer_inbound_nat_rules_ids"] = schema.NewSet(schema.HashString, inboundNatPools)
}
ipConfigs = append(ipConfigs, config) ipConfigs = append(ipConfigs, config)
} }
@ -735,7 +763,11 @@ func flattenAzureRMVirtualMachineScaleSetOsProfile(profile *compute.VirtualMachi
func flattenAzureRmVirtualMachineScaleSetStorageProfileOSDisk(profile *compute.VirtualMachineScaleSetOSDisk) []interface{} { func flattenAzureRmVirtualMachineScaleSetStorageProfileOSDisk(profile *compute.VirtualMachineScaleSetOSDisk) []interface{} {
result := make(map[string]interface{}) result := make(map[string]interface{})
if profile.Name != nil {
result["name"] = *profile.Name result["name"] = *profile.Name
}
if profile.Image != nil { if profile.Image != nil {
result["image"] = *profile.Image.URI result["image"] = *profile.Image.URI
} }
@ -748,6 +780,10 @@ func flattenAzureRmVirtualMachineScaleSetStorageProfileOSDisk(profile *compute.V
result["vhd_containers"] = schema.NewSet(schema.HashString, containers) result["vhd_containers"] = schema.NewSet(schema.HashString, containers)
} }
if profile.ManagedDisk != nil {
result["managed_disk_type"] = string(profile.ManagedDisk.StorageAccountType)
}
result["caching"] = profile.Caching result["caching"] = profile.Caching
result["create_option"] = profile.CreateOption result["create_option"] = profile.CreateOption
result["os_type"] = profile.OsType result["os_type"] = profile.OsType
@ -838,8 +874,8 @@ func resourceArmVirtualMachineScaleSetStorageProfileOsDiskHash(v interface{}) in
m := v.(map[string]interface{}) m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["name"].(string))) buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
if m["image"] != nil { if m["vhd_containers"] != nil {
buf.WriteString(fmt.Sprintf("%s-", m["image"].(string))) buf.WriteString(fmt.Sprintf("%s-", m["vhd_containers"].(*schema.Set).List()))
} }
return hashcode.String(buf.String()) return hashcode.String(buf.String())
@ -961,6 +997,18 @@ func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *
ipConfiguration.LoadBalancerBackendAddressPools = &resources ipConfiguration.LoadBalancerBackendAddressPools = &resources
} }
if v := ipconfig["load_balancer_inbound_nat_rules_ids"]; v != nil {
rules := v.(*schema.Set).List()
rulesResources := make([]compute.SubResource, 0, len(rules))
for _, m := range rules {
id := m.(string)
rulesResources = append(rulesResources, compute.SubResource{
ID: &id,
})
}
ipConfiguration.LoadBalancerInboundNatPools = &rulesResources
}
ipConfigurations = append(ipConfigurations, ipConfiguration) ipConfigurations = append(ipConfigurations, ipConfiguration)
} }
@ -1037,9 +1085,11 @@ func expandAzureRMVirtualMachineScaleSetsStorageProfileOsDisk(d *schema.Resource
osDiskConfig := osDiskConfigs[0].(map[string]interface{}) osDiskConfig := osDiskConfigs[0].(map[string]interface{})
name := osDiskConfig["name"].(string) name := osDiskConfig["name"].(string)
image := osDiskConfig["image"].(string) image := osDiskConfig["image"].(string)
vhd_containers := osDiskConfig["vhd_containers"].(*schema.Set).List()
caching := osDiskConfig["caching"].(string) caching := osDiskConfig["caching"].(string)
osType := osDiskConfig["os_type"].(string) osType := osDiskConfig["os_type"].(string)
createOption := osDiskConfig["create_option"].(string) createOption := osDiskConfig["create_option"].(string)
managedDiskType := osDiskConfig["managed_disk_type"].(string)
osDisk := &compute.VirtualMachineScaleSetOSDisk{ osDisk := &compute.VirtualMachineScaleSetOSDisk{
Name: &name, Name: &name,
@ -1052,18 +1102,40 @@ func expandAzureRMVirtualMachineScaleSetsStorageProfileOsDisk(d *schema.Resource
osDisk.Image = &compute.VirtualHardDisk{ osDisk.Image = &compute.VirtualHardDisk{
URI: &image, URI: &image,
} }
} else { }
if len(vhd_containers) > 0 {
var vhdContainers []string var vhdContainers []string
containers := osDiskConfig["vhd_containers"].(*schema.Set).List() for _, v := range vhd_containers {
for _, v := range containers {
str := v.(string) str := v.(string)
vhdContainers = append(vhdContainers, str) vhdContainers = append(vhdContainers, str)
} }
osDisk.VhdContainers = &vhdContainers osDisk.VhdContainers = &vhdContainers
} }
return osDisk, nil managedDisk := &compute.VirtualMachineScaleSetManagedDiskParameters{}
if managedDiskType != "" {
if name == "" {
osDisk.Name = nil
managedDisk.StorageAccountType = compute.StorageAccountTypes(managedDiskType)
osDisk.ManagedDisk = managedDisk
} else {
return nil, fmt.Errorf("[ERROR] Conflict between `name` and `managed_disk_type` (please set name to blank)")
}
}
//BEGIN: code to be removed after GH-13016 is merged
if image != "" && managedDiskType != "" {
return nil, fmt.Errorf("[ERROR] Conflict between `image` and `managed_disk_type` (only one or the other can be used)")
}
if len(vhd_containers) > 0 && managedDiskType != "" {
return nil, fmt.Errorf("[ERROR] Conflict between `vhd_containers` and `managed_disk_type` (only one or the other can be used)")
}
//END: code to be removed after GH-13016 is merged
return osDisk, nil
} }
func expandAzureRmVirtualMachineScaleSetStorageProfileImageReference(d *schema.ResourceData) (*compute.ImageReference, error) { func expandAzureRmVirtualMachineScaleSetStorageProfileImageReference(d *schema.ResourceData) (*compute.ImageReference, error) {
@ -1137,22 +1209,22 @@ func expandAzureRmVirtualMachineScaleSetOsProfileWindowsConfig(d *schema.Resourc
if v := osProfileConfig["winrm"]; v != nil { if v := osProfileConfig["winrm"]; v != nil {
winRm := v.(*schema.Set).List() winRm := v.(*schema.Set).List()
if len(winRm) > 0 { if len(winRm) > 0 {
winRmListners := make([]compute.WinRMListener, 0, len(winRm)) winRmListeners := make([]compute.WinRMListener, 0, len(winRm))
for _, winRmConfig := range winRm { for _, winRmConfig := range winRm {
config := winRmConfig.(map[string]interface{}) config := winRmConfig.(map[string]interface{})
protocol := config["protocol"].(string) protocol := config["protocol"].(string)
winRmListner := compute.WinRMListener{ winRmListener := compute.WinRMListener{
Protocol: compute.ProtocolTypes(protocol), Protocol: compute.ProtocolTypes(protocol),
} }
if v := config["certificate_url"].(string); v != "" { if v := config["certificate_url"].(string); v != "" {
winRmListner.CertificateURL = &v winRmListener.CertificateURL = &v
} }
winRmListners = append(winRmListners, winRmListner) winRmListeners = append(winRmListeners, winRmListener)
} }
config.WinRM = &compute.WinRMConfiguration{ config.WinRM = &compute.WinRMConfiguration{
Listeners: &winRmListners, Listeners: &winRmListeners,
} }
} }
} }

View File

@ -3,6 +3,7 @@ package azurerm
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"regexp"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/acctest"
@ -55,6 +56,24 @@ func TestAccAzureRMVirtualMachineScaleSet_linuxUpdated(t *testing.T) {
}) })
} }
func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk, ri, ri, ri, ri, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
),
},
},
})
}
func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) { func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) {
ri := acctest.RandInt() ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basic, ri, ri, ri, ri, ri, ri, ri, ri) config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basic, ri, ri, ri, ri, ri, ri, ri, ri)
@ -151,6 +170,24 @@ func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions(t *testing.T) {
}) })
} }
func TestAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict, ri, ri, ri, ri, ri, ri, ri)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
ExpectError: regexp.MustCompile("Conflict between `vhd_containers`"),
//Use below code instead once GH-13019 has been merged
//ExpectError: regexp.MustCompile("conflicts with storage_profile_os_disk.0.vhd_containers"),
},
},
})
}
func testCheckAzureRMVirtualMachineScaleSetExists(name string) resource.TestCheckFunc { func testCheckAzureRMVirtualMachineScaleSetExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API // Ensure we have enough information in state to look up in API
@ -341,13 +378,13 @@ func testCheckAzureRMVirtualMachineScaleSetExtension(name string) resource.TestC
var testAccAzureRMVirtualMachineScaleSet_basic = ` var testAccAzureRMVirtualMachineScaleSet_basic = `
resource "azurerm_resource_group" "test" { resource "azurerm_resource_group" "test" {
name = "acctestRG-%d" name = "acctestRG-%d"
location = "West US" location = "West US 2"
} }
resource "azurerm_virtual_network" "test" { resource "azurerm_virtual_network" "test" {
name = "acctvn-%d" name = "acctvn-%d"
address_space = ["10.0.0.0/16"] address_space = ["10.0.0.0/16"]
location = "West US" location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
} }
@ -360,7 +397,7 @@ resource "azurerm_subnet" "test" {
resource "azurerm_network_interface" "test" { resource "azurerm_network_interface" "test" {
name = "acctni-%d" name = "acctni-%d"
location = "West US" location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
ip_configuration { ip_configuration {
@ -373,7 +410,7 @@ resource "azurerm_network_interface" "test" {
resource "azurerm_storage_account" "test" { resource "azurerm_storage_account" "test" {
name = "accsa%d" name = "accsa%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "westus" location = "West US 2"
account_type = "Standard_LRS" account_type = "Standard_LRS"
tags { tags {
@ -390,12 +427,12 @@ resource "azurerm_storage_container" "test" {
resource "azurerm_virtual_machine_scale_set" "test" { resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d" name = "acctvmss-%d"
location = "West US" location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual" upgrade_policy_mode = "Manual"
sku { sku {
name = "Standard_A0" name = "Standard_D1_v2"
tier = "Standard" tier = "Standard"
capacity = 2 capacity = 2
} }
@ -409,7 +446,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
network_profile { network_profile {
name = "TestNetworkProfile-%d" name = "TestNetworkProfile-%d"
primary = true primary = true
ip_configuration { ip_configuration {
name = "TestIPConfiguration" name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}" subnet_id = "${azurerm_subnet.test.id}"
@ -426,7 +462,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
storage_profile_image_reference { storage_profile_image_reference {
publisher = "Canonical" publisher = "Canonical"
offer = "UbuntuServer" offer = "UbuntuServer"
sku = "14.04.2-LTS" sku = "16.04-LTS"
version = "latest" version = "latest"
} }
} }
@ -438,98 +474,82 @@ func testAccAzureRMVirtualMachineScaleSet_linux(rInt int) string {
name = "acctestrg-%d" name = "acctestrg-%d"
location = "West Europe" location = "West Europe"
} }
resource "azurerm_virtual_network" "test" { resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d" name = "acctestvn-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
address_space = ["10.0.0.0/8"] address_space = ["10.0.0.0/8"]
} }
resource "azurerm_subnet" "test" { resource "azurerm_subnet" "test" {
name = "acctestsn-%d" name = "acctestsn-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.1.0/24" address_prefix = "10.0.1.0/24"
} }
resource "azurerm_storage_account" "test" { resource "azurerm_storage_account" "test" {
name = "accsa%d" name = "accsa%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
account_type = "Standard_LRS" account_type = "Standard_LRS"
} }
resource "azurerm_storage_container" "test" { resource "azurerm_storage_container" "test" {
name = "acctestsc-%d" name = "acctestsc-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}" storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private" container_access_type = "private"
} }
resource "azurerm_public_ip" "test" { resource "azurerm_public_ip" "test" {
name = "acctestpip-%d" name = "acctestpip-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
public_ip_address_allocation = "static" public_ip_address_allocation = "static"
} }
resource "azurerm_lb" "test" { resource "azurerm_lb" "test" {
name = "acctestlb-%d" name = "acctestlb-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
frontend_ip_configuration { frontend_ip_configuration {
name = "ip-address" name = "ip-address"
public_ip_address_id = "${azurerm_public_ip.test.id}" public_ip_address_id = "${azurerm_public_ip.test.id}"
} }
} }
resource "azurerm_lb_backend_address_pool" "test" { resource "azurerm_lb_backend_address_pool" "test" {
name = "acctestbap-%d" name = "acctestbap-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
loadbalancer_id = "${azurerm_lb.test.id}" loadbalancer_id = "${azurerm_lb.test.id}"
} }
resource "azurerm_virtual_machine_scale_set" "test" { resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctestvmss-%d" name = "acctestvmss-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
upgrade_policy_mode = "Automatic" upgrade_policy_mode = "Automatic"
sku { sku {
name = "Standard_A0" name = "Standard_A0"
tier = "Standard" tier = "Standard"
capacity = "1" capacity = "1"
} }
os_profile { os_profile {
computer_name_prefix = "prefix" computer_name_prefix = "prefix"
admin_username = "ubuntu" admin_username = "ubuntu"
admin_password = "password" admin_password = "password"
custom_data = "custom data!" custom_data = "custom data!"
} }
os_profile_linux_config { os_profile_linux_config {
disable_password_authentication = true disable_password_authentication = true
ssh_keys { ssh_keys {
path = "/home/ubuntu/.ssh/authorized_keys" path = "/home/ubuntu/.ssh/authorized_keys"
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com" key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com"
} }
} }
network_profile { network_profile {
name = "TestNetworkProfile" name = "TestNetworkProfile"
primary = true primary = true
ip_configuration { ip_configuration {
name = "TestIPConfiguration" name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}" subnet_id = "${azurerm_subnet.test.id}"
load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"] load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"]
} }
} }
storage_profile_os_disk { storage_profile_os_disk {
name = "osDiskProfile" name = "osDiskProfile"
caching = "ReadWrite" caching = "ReadWrite"
@ -537,7 +557,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
os_type = "linux" os_type = "linux"
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"] vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
} }
storage_profile_image_reference { storage_profile_image_reference {
publisher = "Canonical" publisher = "Canonical"
offer = "UbuntuServer" offer = "UbuntuServer"
@ -545,7 +564,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
version = "latest" version = "latest"
} }
} }
`, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) `, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
} }
@ -555,98 +573,82 @@ func testAccAzureRMVirtualMachineScaleSet_linuxUpdated(rInt int) string {
name = "acctestrg-%d" name = "acctestrg-%d"
location = "West Europe" location = "West Europe"
} }
resource "azurerm_virtual_network" "test" { resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d" name = "acctestvn-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
address_space = ["10.0.0.0/8"] address_space = ["10.0.0.0/8"]
} }
resource "azurerm_subnet" "test" { resource "azurerm_subnet" "test" {
name = "acctestsn-%d" name = "acctestsn-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.1.0/24" address_prefix = "10.0.1.0/24"
} }
resource "azurerm_storage_account" "test" { resource "azurerm_storage_account" "test" {
name = "accsa%d" name = "accsa%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
account_type = "Standard_LRS" account_type = "Standard_LRS"
} }
resource "azurerm_storage_container" "test" { resource "azurerm_storage_container" "test" {
name = "acctestsc-%d" name = "acctestsc-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}" storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private" container_access_type = "private"
} }
resource "azurerm_public_ip" "test" { resource "azurerm_public_ip" "test" {
name = "acctestpip-%d" name = "acctestpip-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
public_ip_address_allocation = "static" public_ip_address_allocation = "static"
} }
resource "azurerm_lb" "test" { resource "azurerm_lb" "test" {
name = "acctestlb-%d" name = "acctestlb-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
frontend_ip_configuration { frontend_ip_configuration {
name = "ip-address" name = "ip-address"
public_ip_address_id = "${azurerm_public_ip.test.id}" public_ip_address_id = "${azurerm_public_ip.test.id}"
} }
} }
resource "azurerm_lb_backend_address_pool" "test" { resource "azurerm_lb_backend_address_pool" "test" {
name = "acctestbap-%d" name = "acctestbap-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
loadbalancer_id = "${azurerm_lb.test.id}" loadbalancer_id = "${azurerm_lb.test.id}"
} }
resource "azurerm_virtual_machine_scale_set" "test" { resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctestvmss-%d" name = "acctestvmss-%d"
resource_group_name = "${azurerm_resource_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}" location = "${azurerm_resource_group.test.location}"
upgrade_policy_mode = "Automatic" upgrade_policy_mode = "Automatic"
sku { sku {
name = "Standard_A0" name = "Standard_A0"
tier = "Standard" tier = "Standard"
capacity = "1" capacity = "1"
} }
os_profile { os_profile {
computer_name_prefix = "prefix" computer_name_prefix = "prefix"
admin_username = "ubuntu" admin_username = "ubuntu"
admin_password = "password" admin_password = "password"
custom_data = "custom data!" custom_data = "custom data!"
} }
os_profile_linux_config { os_profile_linux_config {
disable_password_authentication = true disable_password_authentication = true
ssh_keys { ssh_keys {
path = "/home/ubuntu/.ssh/authorized_keys" path = "/home/ubuntu/.ssh/authorized_keys"
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com" key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com"
} }
} }
network_profile { network_profile {
name = "TestNetworkProfile" name = "TestNetworkProfile"
primary = true primary = true
ip_configuration { ip_configuration {
name = "TestIPConfiguration" name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}" subnet_id = "${azurerm_subnet.test.id}"
load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"] load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"]
} }
} }
storage_profile_os_disk { storage_profile_os_disk {
name = "osDiskProfile" name = "osDiskProfile"
caching = "ReadWrite" caching = "ReadWrite"
@ -654,22 +656,82 @@ resource "azurerm_virtual_machine_scale_set" "test" {
os_type = "linux" os_type = "linux"
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"] vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
} }
storage_profile_image_reference { storage_profile_image_reference {
publisher = "Canonical" publisher = "Canonical"
offer = "UbuntuServer" offer = "UbuntuServer"
sku = "14.04.2-LTS" sku = "14.04.2-LTS"
version = "latest" version = "latest"
} }
tags { tags {
ThisIs = "a test" ThisIs = "a test"
} }
} }
`, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) `, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
} }
var testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk = `
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US 2"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 2
}
os_profile {
computer_name_prefix = "testvm-%d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile-%d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
storage_profile_os_disk {
name = ""
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
`
var testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate = ` var testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate = `
resource "azurerm_resource_group" "test" { resource "azurerm_resource_group" "test" {
name = "acctestrg-%d" name = "acctestrg-%d"
@ -723,6 +785,17 @@ resource "azurerm_lb_backend_address_pool" "test" {
loadbalancer_id = "${azurerm_lb.test.id}" loadbalancer_id = "${azurerm_lb.test.id}"
} }
resource "azurerm_lb_nat_pool" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
name = "ssh"
loadbalancer_id = "${azurerm_lb.test.id}"
protocol = "Tcp"
frontend_port_start = 50000
frontend_port_end = 50119
backend_port = 22
frontend_ip_configuration_name = "default"
}
resource "azurerm_virtual_machine_scale_set" "test" { resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d" name = "acctvmss-%d"
location = "southcentralus" location = "southcentralus"
@ -730,7 +803,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
upgrade_policy_mode = "Manual" upgrade_policy_mode = "Manual"
sku { sku {
name = "Standard_A0" name = "Standard_D1_v2"
tier = "Standard" tier = "Standard"
capacity = 1 capacity = 1
} }
@ -744,11 +817,11 @@ resource "azurerm_virtual_machine_scale_set" "test" {
network_profile { network_profile {
name = "TestNetworkProfile" name = "TestNetworkProfile"
primary = true primary = true
ip_configuration { ip_configuration {
name = "TestIPConfiguration" name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}" subnet_id = "${azurerm_subnet.test.id}"
load_balancer_backend_address_pool_ids = [ "${azurerm_lb_backend_address_pool.test.id}" ] load_balancer_backend_address_pool_ids = [ "${azurerm_lb_backend_address_pool.test.id}" ]
load_balancer_inbound_nat_rules_ids = ["${azurerm_lb_nat_pool.test.id}"]
} }
} }
@ -762,7 +835,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
storage_profile_image_reference { storage_profile_image_reference {
publisher = "Canonical" publisher = "Canonical"
offer = "UbuntuServer" offer = "UbuntuServer"
sku = "14.04.2-LTS" sku = "16.04-LTS"
version = "latest" version = "latest"
} }
} }
@ -810,7 +883,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
overprovision = false overprovision = false
sku { sku {
name = "Standard_A0" name = "Standard_D1_v2"
tier = "Standard" tier = "Standard"
capacity = 1 capacity = 1
} }
@ -824,7 +897,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
network_profile { network_profile {
name = "TestNetworkProfile" name = "TestNetworkProfile"
primary = true primary = true
ip_configuration { ip_configuration {
name = "TestIPConfiguration" name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}" subnet_id = "${azurerm_subnet.test.id}"
@ -841,7 +913,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
storage_profile_image_reference { storage_profile_image_reference {
publisher = "Canonical" publisher = "Canonical"
offer = "UbuntuServer" offer = "UbuntuServer"
sku = "14.04.2-LTS" sku = "16.04-LTS"
version = "latest" version = "latest"
} }
} }
@ -889,7 +961,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
overprovision = false overprovision = false
sku { sku {
name = "Standard_A0" name = "Standard_D1_v2"
tier = "Standard" tier = "Standard"
capacity = 1 capacity = 1
} }
@ -903,7 +975,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
network_profile { network_profile {
name = "TestNetworkProfile" name = "TestNetworkProfile"
primary = true primary = true
ip_configuration { ip_configuration {
name = "TestIPConfiguration" name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}" subnet_id = "${azurerm_subnet.test.id}"
@ -920,7 +991,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
storage_profile_image_reference { storage_profile_image_reference {
publisher = "Canonical" publisher = "Canonical"
offer = "UbuntuServer" offer = "UbuntuServer"
sku = "14.04.2-LTS" sku = "16.04-LTS"
version = "latest" version = "latest"
} }
@ -930,7 +1001,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
type = "CustomScript" type = "CustomScript"
type_handler_version = "2.0" type_handler_version = "2.0"
auto_upgrade_minor_version = true auto_upgrade_minor_version = true
settings = <<SETTINGS settings = <<SETTINGS
{ {
"commandToExecute": "echo $HOSTNAME" "commandToExecute": "echo $HOSTNAME"
@ -945,7 +1015,6 @@ SETTINGS
SETTINGS SETTINGS
} }
} }
` `
var testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate = ` var testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate = `
@ -990,7 +1059,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
overprovision = false overprovision = false
sku { sku {
name = "Standard_A0" name = "Standard_D1_v2"
tier = "Standard" tier = "Standard"
capacity = 1 capacity = 1
} }
@ -1004,7 +1073,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
network_profile { network_profile {
name = "TestNetworkProfile" name = "TestNetworkProfile"
primary = true primary = true
ip_configuration { ip_configuration {
name = "TestIPConfiguration" name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}" subnet_id = "${azurerm_subnet.test.id}"
@ -1021,7 +1089,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
storage_profile_image_reference { storage_profile_image_reference {
publisher = "Canonical" publisher = "Canonical"
offer = "UbuntuServer" offer = "UbuntuServer"
sku = "14.04.2-LTS" sku = "16.04-LTS"
version = "latest" version = "latest"
} }
@ -1031,7 +1099,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
type = "CustomScript" type = "CustomScript"
type_handler_version = "2.0" type_handler_version = "2.0"
auto_upgrade_minor_version = true auto_upgrade_minor_version = true
settings = <<SETTINGS settings = <<SETTINGS
{ {
"commandToExecute": "echo $HOSTNAME" "commandToExecute": "echo $HOSTNAME"
@ -1055,3 +1122,79 @@ SETTINGS
} }
} }
` `
var testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict = `
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US 2"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "test" {
name = "acctni-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 2
}
os_profile {
computer_name_prefix = "testvm-%d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile-%d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
storage_profile_os_disk {
name = ""
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
vhd_containers = ["should_cause_conflict"]
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
`

View File

@ -6,12 +6,13 @@ import (
"strings" "strings"
"testing" "testing"
"regexp"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/Azure/azure-sdk-for-go/arm/disk" "github.com/Azure/azure-sdk-for-go/arm/disk"
"github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"regexp"
) )
func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) {

View File

@ -106,6 +106,128 @@ resource "azurerm_virtual_machine_scale_set" "test" {
} }
``` ```
## Example Usage with Managed Disks
```
resource "azurerm_resource_group" "test" {
name = "acctestrg"
location = "West US 2"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn"
address_space = ["10.0.0.0/16"]
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_public_ip" "test" {
name = "test"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
domain_name_label = "${azurerm_resource_group.test.name}"
tags {
environment = "staging"
}
}
resource "azurerm_lb" "test" {
name = "test"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
frontend_ip_configuration {
name = "PublicIPAddress"
public_ip_address_id = "${azurerm_public_ip.test.id}"
}
}
resource "azurerm_lb_backend_address_pool" "bpepool" {
resource_group_name = "${azurerm_resource_group.test.name}"
loadbalancer_id = "${azurerm_lb.test.id}"
name = "BackEndAddressPool"
}
resource "azurerm_lb_nat_pool" "lbnatpool" {
count = 3
resource_group_name = "${azurerm_resource_group.test.name}"
name = "ssh"
loadbalancer_id = "${azurerm_lb.test.id}"
protocol = "Tcp"
frontend_port_start = 50000
frontend_port_end = 50119
backend_port = 22
frontend_ip_configuration_name = "PublicIPAddress"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "mytestscaleset-1"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_A0"
tier = "Standard"
capacity = 2
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "14.04.2-LTS"
version = "latest"
}
storage_profile_os_disk {
name = "myosdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name_prefix = "testvm"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/myadmin/.ssh/authorized_keys"
key_data = "${file("~/.ssh/demo_key.pub")}"
}
}
network_profile {
name = "terraformnetworkprofile"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.bpepool.id}"]
load_balancer_inbound_nat_rules_ids = ["${element(azurerm_lb_nat_pool.lbnatpool.*.id, count.index)}"]
}
}
tags {
environment = "staging"
}
}
```
## Argument Reference ## Argument Reference
The following arguments are supported: The following arguments are supported:
@ -191,16 +313,18 @@ The following arguments are supported:
* `name` - (Required) Specifies name of the IP configuration. * `name` - (Required) Specifies name of the IP configuration.
* `subnet_id` - (Required) Specifies the identifier of the subnet. * `subnet_id` - (Required) Specifies the identifier of the subnet.
* `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. * `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.
* `load_balancer_inbound_nat_rules_ids` - (Optional) Specifies an array of references to inbound NAT rules for load balancers.
`storage_profile_os_disk` supports the following: `storage_profile_os_disk` supports the following:
* `name` - (Required) Specifies the disk name. * `name` - (Required) Specifies the disk name.
* `vhd_containers` - (Optional) Specifies the vhd uri. This property is ignored if using a custom image. * `vhd_containers` - (Optional) Specifies the vhd uri. Cannot be used when `image` or `managed_disk_type` is specified.
* `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.
* `create_option` - (Required) Specifies how the virtual machine should be created. The only possible option is `FromImage`. * `create_option` - (Required) Specifies how the virtual machine should be created. The only possible option is `FromImage`.
* `caching` - (Required) Specifies the caching requirements. * `caching` - (Optional) Specifies the caching requirements. Possible values include: `None` (default), `ReadOnly`, `ReadWrite`.
* `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. * `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.
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. 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.
If this property is set then vhd_containers is ignored. 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.
* `os_type` - (Optional) Specifies the operating system Type, valid values are windows, linux. * `os_type` - (Optional) Specifies the operating system Type, valid values are windows, linux.
`storage_profile_image_reference` supports the following: `storage_profile_image_reference` supports the following: