github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set_test.go (about)

     1  package azurerm
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/helper/acctest"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccAzureRMVirtualMachineScaleSet_basic(t *testing.T) {
    14  	ri := acctest.RandInt()
    15  	config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basic, ri, ri, ri, ri, ri, ri, ri, ri)
    16  	resource.Test(t, resource.TestCase{
    17  		PreCheck:     func() { testAccPreCheck(t) },
    18  		Providers:    testAccProviders,
    19  		CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
    20  		Steps: []resource.TestStep{
    21  			{
    22  				Config: config,
    23  				Check: resource.ComposeTestCheckFunc(
    24  					testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
    25  				),
    26  			},
    27  		},
    28  	})
    29  }
    30  
    31  func TestAccAzureRMVirtualMachineScaleSet_linuxUpdated(t *testing.T) {
    32  	resourceName := "azurerm_virtual_machine_scale_set.test"
    33  	ri := acctest.RandInt()
    34  	config := testAccAzureRMVirtualMachineScaleSet_linux(ri)
    35  	updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxUpdated(ri)
    36  
    37  	resource.Test(t, resource.TestCase{
    38  		PreCheck:     func() { testAccPreCheck(t) },
    39  		Providers:    testAccProviders,
    40  		CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
    41  		Steps: []resource.TestStep{
    42  			{
    43  				Config: config,
    44  				Check: resource.ComposeTestCheckFunc(
    45  					testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
    46  				),
    47  			},
    48  			{
    49  				Config: updatedConfig,
    50  				Check: resource.ComposeTestCheckFunc(
    51  					testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
    52  				),
    53  			},
    54  		},
    55  	})
    56  }
    57  
    58  func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) {
    59  	ri := acctest.RandInt()
    60  	config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basic, ri, ri, ri, ri, ri, ri, ri, ri)
    61  	resource.Test(t, resource.TestCase{
    62  		PreCheck:     func() { testAccPreCheck(t) },
    63  		Providers:    testAccProviders,
    64  		CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
    65  		Steps: []resource.TestStep{
    66  			{
    67  				Config: config,
    68  				Check: resource.ComposeTestCheckFunc(
    69  					testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
    70  					testCheckAzureRMVirtualMachineScaleSetDisappears("azurerm_virtual_machine_scale_set.test"),
    71  				),
    72  				ExpectNonEmptyPlan: true,
    73  			},
    74  		},
    75  	})
    76  }
    77  
    78  func TestAccAzureRMVirtualMachineScaleSet_loadBalancer(t *testing.T) {
    79  	ri := acctest.RandInt()
    80  	config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate, ri, ri, ri, ri, ri, ri, ri)
    81  	resource.Test(t, resource.TestCase{
    82  		PreCheck:     func() { testAccPreCheck(t) },
    83  		Providers:    testAccProviders,
    84  		CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
    85  		Steps: []resource.TestStep{
    86  			{
    87  				Config: config,
    88  				Check: resource.ComposeTestCheckFunc(
    89  					testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
    90  					testCheckAzureRMVirtualMachineScaleSetHasLoadbalancer("azurerm_virtual_machine_scale_set.test"),
    91  				),
    92  			},
    93  		},
    94  	})
    95  }
    96  
    97  func TestAccAzureRMVirtualMachineScaleSet_overprovision(t *testing.T) {
    98  	ri := acctest.RandInt()
    99  	config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetOverprovisionTemplate, ri, ri, ri, ri, ri, ri)
   100  	resource.Test(t, resource.TestCase{
   101  		PreCheck:     func() { testAccPreCheck(t) },
   102  		Providers:    testAccProviders,
   103  		CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
   104  		Steps: []resource.TestStep{
   105  			{
   106  				Config: config,
   107  				Check: resource.ComposeTestCheckFunc(
   108  					testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
   109  					testCheckAzureRMVirtualMachineScaleSetOverprovision("azurerm_virtual_machine_scale_set.test"),
   110  				),
   111  			},
   112  		},
   113  	})
   114  }
   115  
   116  func TestAccAzureRMVirtualMachineScaleSet_extension(t *testing.T) {
   117  	ri := acctest.RandInt()
   118  	config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetExtensionTemplate, ri, ri, ri, ri, ri, ri)
   119  	resource.Test(t, resource.TestCase{
   120  		PreCheck:     func() { testAccPreCheck(t) },
   121  		Providers:    testAccProviders,
   122  		CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
   123  		Steps: []resource.TestStep{
   124  			{
   125  				Config: config,
   126  				Check: resource.ComposeTestCheckFunc(
   127  					testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
   128  					testCheckAzureRMVirtualMachineScaleSetExtension("azurerm_virtual_machine_scale_set.test"),
   129  				),
   130  			},
   131  		},
   132  	})
   133  }
   134  
   135  func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions(t *testing.T) {
   136  	ri := acctest.RandInt()
   137  	config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate, ri, ri, ri, ri, ri, ri)
   138  	resource.Test(t, resource.TestCase{
   139  		PreCheck:     func() { testAccPreCheck(t) },
   140  		Providers:    testAccProviders,
   141  		CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
   142  		Steps: []resource.TestStep{
   143  			{
   144  				Config: config,
   145  				Check: resource.ComposeTestCheckFunc(
   146  					testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
   147  					testCheckAzureRMVirtualMachineScaleSetExtension("azurerm_virtual_machine_scale_set.test"),
   148  				),
   149  			},
   150  		},
   151  	})
   152  }
   153  
   154  func testCheckAzureRMVirtualMachineScaleSetExists(name string) resource.TestCheckFunc {
   155  	return func(s *terraform.State) error {
   156  		// Ensure we have enough information in state to look up in API
   157  		rs, ok := s.RootModule().Resources[name]
   158  		if !ok {
   159  			return fmt.Errorf("Not found: %s", name)
   160  		}
   161  
   162  		name := rs.Primary.Attributes["name"]
   163  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   164  		if !hasResourceGroup {
   165  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name)
   166  		}
   167  
   168  		conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
   169  
   170  		resp, err := conn.Get(resourceGroup, name)
   171  		if err != nil {
   172  			return fmt.Errorf("Bad: Get on vmScaleSetClient: %s", err)
   173  		}
   174  
   175  		if resp.StatusCode == http.StatusNotFound {
   176  			return fmt.Errorf("Bad: VirtualMachineScaleSet %q (resource group: %q) does not exist", name, resourceGroup)
   177  		}
   178  
   179  		return nil
   180  	}
   181  }
   182  
   183  func testCheckAzureRMVirtualMachineScaleSetDisappears(name string) resource.TestCheckFunc {
   184  	return func(s *terraform.State) error {
   185  		// Ensure we have enough information in state to look up in API
   186  		rs, ok := s.RootModule().Resources[name]
   187  		if !ok {
   188  			return fmt.Errorf("Not found: %s", name)
   189  		}
   190  
   191  		name := rs.Primary.Attributes["name"]
   192  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   193  		if !hasResourceGroup {
   194  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name)
   195  		}
   196  
   197  		conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
   198  
   199  		_, err := conn.Delete(resourceGroup, name, make(chan struct{}))
   200  		if err != nil {
   201  			return fmt.Errorf("Bad: Delete on vmScaleSetClient: %s", err)
   202  		}
   203  
   204  		return nil
   205  	}
   206  }
   207  
   208  func testCheckAzureRMVirtualMachineScaleSetDestroy(s *terraform.State) error {
   209  	conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
   210  
   211  	for _, rs := range s.RootModule().Resources {
   212  		if rs.Type != "azurerm_virtual_machine_scale_set" {
   213  			continue
   214  		}
   215  
   216  		name := rs.Primary.Attributes["name"]
   217  		resourceGroup := rs.Primary.Attributes["resource_group_name"]
   218  
   219  		resp, err := conn.Get(resourceGroup, name)
   220  
   221  		if err != nil {
   222  			return nil
   223  		}
   224  
   225  		if resp.StatusCode != http.StatusNotFound {
   226  			return fmt.Errorf("Virtual Machine Scale Set still exists:\n%#v", resp.VirtualMachineScaleSetProperties)
   227  		}
   228  	}
   229  
   230  	return nil
   231  }
   232  
   233  func testCheckAzureRMVirtualMachineScaleSetHasLoadbalancer(name string) resource.TestCheckFunc {
   234  	return func(s *terraform.State) error {
   235  		// Ensure we have enough information in state to look up in API
   236  		rs, ok := s.RootModule().Resources[name]
   237  		if !ok {
   238  			return fmt.Errorf("Not found: %s", name)
   239  		}
   240  
   241  		name := rs.Primary.Attributes["name"]
   242  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   243  		if !hasResourceGroup {
   244  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name)
   245  		}
   246  
   247  		conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
   248  		resp, err := conn.Get(resourceGroup, name)
   249  		if err != nil {
   250  			return fmt.Errorf("Bad: Get on vmScaleSetClient: %s", err)
   251  		}
   252  
   253  		if resp.StatusCode == http.StatusNotFound {
   254  			return fmt.Errorf("Bad: VirtualMachineScaleSet %q (resource group: %q) does not exist", name, resourceGroup)
   255  		}
   256  
   257  		n := resp.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations
   258  		if n == nil || len(*n) == 0 {
   259  			return fmt.Errorf("Bad: Could not get network interface configurations for scale set %v", name)
   260  		}
   261  
   262  		ip := (*n)[0].IPConfigurations
   263  		if ip == nil || len(*ip) == 0 {
   264  			return fmt.Errorf("Bad: Could not get ip configurations for scale set %v", name)
   265  		}
   266  
   267  		pools := (*ip)[0].LoadBalancerBackendAddressPools
   268  		if pools == nil || len(*pools) == 0 {
   269  			return fmt.Errorf("Bad: Load balancer backend pools is empty for scale set %v", name)
   270  		}
   271  
   272  		return nil
   273  	}
   274  }
   275  
   276  func testCheckAzureRMVirtualMachineScaleSetOverprovision(name string) resource.TestCheckFunc {
   277  	return func(s *terraform.State) error {
   278  		// Ensure we have enough information in state to look up in API
   279  		rs, ok := s.RootModule().Resources[name]
   280  		if !ok {
   281  			return fmt.Errorf("Not found: %s", name)
   282  		}
   283  
   284  		name := rs.Primary.Attributes["name"]
   285  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   286  		if !hasResourceGroup {
   287  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name)
   288  		}
   289  
   290  		conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
   291  		resp, err := conn.Get(resourceGroup, name)
   292  		if err != nil {
   293  			return fmt.Errorf("Bad: Get on vmScaleSetClient: %s", err)
   294  		}
   295  
   296  		if resp.StatusCode == http.StatusNotFound {
   297  			return fmt.Errorf("Bad: VirtualMachineScaleSet %q (resource group: %q) does not exist", name, resourceGroup)
   298  		}
   299  
   300  		if *resp.Overprovision {
   301  			return fmt.Errorf("Bad: Overprovision should have been false for scale set %v", name)
   302  		}
   303  
   304  		return nil
   305  	}
   306  }
   307  
   308  func testCheckAzureRMVirtualMachineScaleSetExtension(name string) resource.TestCheckFunc {
   309  	return func(s *terraform.State) error {
   310  		// Ensure we have enough information in state to look up in API
   311  		rs, ok := s.RootModule().Resources[name]
   312  		if !ok {
   313  			return fmt.Errorf("Not found: %s", name)
   314  		}
   315  
   316  		name := rs.Primary.Attributes["name"]
   317  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   318  		if !hasResourceGroup {
   319  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name)
   320  		}
   321  
   322  		conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
   323  		resp, err := conn.Get(resourceGroup, name)
   324  		if err != nil {
   325  			return fmt.Errorf("Bad: Get on vmScaleSetClient: %s", err)
   326  		}
   327  
   328  		if resp.StatusCode == http.StatusNotFound {
   329  			return fmt.Errorf("Bad: VirtualMachineScaleSet %q (resource group: %q) does not exist", name, resourceGroup)
   330  		}
   331  
   332  		n := resp.VirtualMachineProfile.ExtensionProfile.Extensions
   333  		if n == nil || len(*n) == 0 {
   334  			return fmt.Errorf("Bad: Could not get extensions for scale set %v", name)
   335  		}
   336  
   337  		return nil
   338  	}
   339  }
   340  
   341  var testAccAzureRMVirtualMachineScaleSet_basic = `
   342  resource "azurerm_resource_group" "test" {
   343    name     = "acctestRG-%d"
   344    location = "West US"
   345  }
   346  
   347  resource "azurerm_virtual_network" "test" {
   348    name                = "acctvn-%d"
   349    address_space       = ["10.0.0.0/16"]
   350    location            = "West US"
   351    resource_group_name = "${azurerm_resource_group.test.name}"
   352  }
   353  
   354  resource "azurerm_subnet" "test" {
   355    name                 = "acctsub-%d"
   356    resource_group_name  = "${azurerm_resource_group.test.name}"
   357    virtual_network_name = "${azurerm_virtual_network.test.name}"
   358    address_prefix       = "10.0.2.0/24"
   359  }
   360  
   361  resource "azurerm_network_interface" "test" {
   362    name                = "acctni-%d"
   363    location            = "West US"
   364    resource_group_name = "${azurerm_resource_group.test.name}"
   365  
   366    ip_configuration {
   367      name                          = "testconfiguration1"
   368      subnet_id                     = "${azurerm_subnet.test.id}"
   369      private_ip_address_allocation = "dynamic"
   370    }
   371  }
   372  
   373  resource "azurerm_storage_account" "test" {
   374    name                = "accsa%d"
   375    resource_group_name = "${azurerm_resource_group.test.name}"
   376    location            = "westus"
   377    account_type        = "Standard_LRS"
   378  
   379    tags {
   380      environment = "staging"
   381    }
   382  }
   383  
   384  resource "azurerm_storage_container" "test" {
   385    name                  = "vhds"
   386    resource_group_name   = "${azurerm_resource_group.test.name}"
   387    storage_account_name  = "${azurerm_storage_account.test.name}"
   388    container_access_type = "private"
   389  }
   390  
   391  resource "azurerm_virtual_machine_scale_set" "test" {
   392    name                = "acctvmss-%d"
   393    location            = "West US"
   394    resource_group_name = "${azurerm_resource_group.test.name}"
   395    upgrade_policy_mode = "Manual"
   396  
   397    sku {
   398      name     = "Standard_A0"
   399      tier     = "Standard"
   400      capacity = 2
   401    }
   402  
   403    os_profile {
   404      computer_name_prefix = "testvm-%d"
   405      admin_username       = "myadmin"
   406      admin_password       = "Passwword1234"
   407    }
   408  
   409    network_profile {
   410      name    = "TestNetworkProfile-%d"
   411      primary = true
   412  
   413      ip_configuration {
   414        name      = "TestIPConfiguration"
   415        subnet_id = "${azurerm_subnet.test.id}"
   416      }
   417    }
   418  
   419    storage_profile_os_disk {
   420      name           = "osDiskProfile"
   421      caching        = "ReadWrite"
   422      create_option  = "FromImage"
   423      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
   424    }
   425  
   426    storage_profile_image_reference {
   427      publisher = "Canonical"
   428      offer     = "UbuntuServer"
   429      sku       = "14.04.2-LTS"
   430      version   = "latest"
   431    }
   432  }
   433  `
   434  
   435  func testAccAzureRMVirtualMachineScaleSet_linux(rInt int) string {
   436  	return fmt.Sprintf(`
   437  	resource "azurerm_resource_group" "test" {
   438    name     = "acctestrg-%d"
   439    location = "West Europe"
   440  }
   441  
   442  resource "azurerm_virtual_network" "test" {
   443    name                = "acctestvn-%d"
   444    resource_group_name = "${azurerm_resource_group.test.name}"
   445    location            = "${azurerm_resource_group.test.location}"
   446    address_space       = ["10.0.0.0/8"]
   447  }
   448  
   449  resource "azurerm_subnet" "test" {
   450    name                 = "acctestsn-%d"
   451    resource_group_name  = "${azurerm_resource_group.test.name}"
   452    virtual_network_name = "${azurerm_virtual_network.test.name}"
   453    address_prefix       = "10.0.1.0/24"
   454  }
   455  
   456  resource "azurerm_storage_account" "test" {
   457    name                = "accsa%d"
   458    resource_group_name = "${azurerm_resource_group.test.name}"
   459    location            = "${azurerm_resource_group.test.location}"
   460    account_type        = "Standard_LRS"
   461  }
   462  
   463  resource "azurerm_storage_container" "test" {
   464    name                  = "acctestsc-%d"
   465    resource_group_name   = "${azurerm_resource_group.test.name}"
   466    storage_account_name  = "${azurerm_storage_account.test.name}"
   467    container_access_type = "private"
   468  }
   469  
   470  resource "azurerm_public_ip" "test" {
   471    name                         = "acctestpip-%d"
   472    resource_group_name          = "${azurerm_resource_group.test.name}"
   473    location                     = "${azurerm_resource_group.test.location}"
   474    public_ip_address_allocation = "static"
   475  }
   476  
   477  resource "azurerm_lb" "test" {
   478    name                = "acctestlb-%d"
   479    resource_group_name = "${azurerm_resource_group.test.name}"
   480    location            = "${azurerm_resource_group.test.location}"
   481  
   482    frontend_ip_configuration {
   483      name                 = "ip-address"
   484      public_ip_address_id = "${azurerm_public_ip.test.id}"
   485    }
   486  }
   487  
   488  resource "azurerm_lb_backend_address_pool" "test" {
   489    name                = "acctestbap-%d"
   490    resource_group_name = "${azurerm_resource_group.test.name}"
   491    loadbalancer_id     = "${azurerm_lb.test.id}"
   492  }
   493  
   494  resource "azurerm_virtual_machine_scale_set" "test" {
   495    name                = "acctestvmss-%d"
   496    resource_group_name = "${azurerm_resource_group.test.name}"
   497    location            = "${azurerm_resource_group.test.location}"
   498    upgrade_policy_mode = "Automatic"
   499  
   500    sku {
   501      name     = "Standard_A0"
   502      tier     = "Standard"
   503      capacity = "1"
   504    }
   505  
   506    os_profile {
   507      computer_name_prefix = "prefix"
   508      admin_username       = "ubuntu"
   509      admin_password       = "password"
   510      custom_data          = "custom data!"
   511    }
   512  
   513    os_profile_linux_config {
   514      disable_password_authentication = true
   515  
   516      ssh_keys {
   517        path     = "/home/ubuntu/.ssh/authorized_keys"
   518        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"
   519      }
   520    }
   521  
   522    network_profile {
   523      name    = "TestNetworkProfile"
   524      primary = true
   525  
   526      ip_configuration {
   527        name                                   = "TestIPConfiguration"
   528        subnet_id                              = "${azurerm_subnet.test.id}"
   529        load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"]
   530      }
   531    }
   532  
   533    storage_profile_os_disk {
   534      name           = "osDiskProfile"
   535      caching        = "ReadWrite"
   536      create_option  = "FromImage"
   537      os_type        = "linux"
   538      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
   539    }
   540  
   541    storage_profile_image_reference {
   542      publisher = "Canonical"
   543      offer     = "UbuntuServer"
   544      sku       = "14.04.2-LTS"
   545      version   = "latest"
   546    }
   547  }
   548  
   549  `, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
   550  }
   551  
   552  func testAccAzureRMVirtualMachineScaleSet_linuxUpdated(rInt int) string {
   553  	return fmt.Sprintf(`
   554  	resource "azurerm_resource_group" "test" {
   555    name     = "acctestrg-%d"
   556    location = "West Europe"
   557  }
   558  
   559  resource "azurerm_virtual_network" "test" {
   560    name                = "acctestvn-%d"
   561    resource_group_name = "${azurerm_resource_group.test.name}"
   562    location            = "${azurerm_resource_group.test.location}"
   563    address_space       = ["10.0.0.0/8"]
   564  }
   565  
   566  resource "azurerm_subnet" "test" {
   567    name                 = "acctestsn-%d"
   568    resource_group_name  = "${azurerm_resource_group.test.name}"
   569    virtual_network_name = "${azurerm_virtual_network.test.name}"
   570    address_prefix       = "10.0.1.0/24"
   571  }
   572  
   573  resource "azurerm_storage_account" "test" {
   574    name                = "accsa%d"
   575    resource_group_name = "${azurerm_resource_group.test.name}"
   576    location            = "${azurerm_resource_group.test.location}"
   577    account_type        = "Standard_LRS"
   578  }
   579  
   580  resource "azurerm_storage_container" "test" {
   581    name                  = "acctestsc-%d"
   582    resource_group_name   = "${azurerm_resource_group.test.name}"
   583    storage_account_name  = "${azurerm_storage_account.test.name}"
   584    container_access_type = "private"
   585  }
   586  
   587  resource "azurerm_public_ip" "test" {
   588    name                         = "acctestpip-%d"
   589    resource_group_name          = "${azurerm_resource_group.test.name}"
   590    location                     = "${azurerm_resource_group.test.location}"
   591    public_ip_address_allocation = "static"
   592  }
   593  
   594  resource "azurerm_lb" "test" {
   595    name                = "acctestlb-%d"
   596    resource_group_name = "${azurerm_resource_group.test.name}"
   597    location            = "${azurerm_resource_group.test.location}"
   598  
   599    frontend_ip_configuration {
   600      name                 = "ip-address"
   601      public_ip_address_id = "${azurerm_public_ip.test.id}"
   602    }
   603  }
   604  
   605  resource "azurerm_lb_backend_address_pool" "test" {
   606    name                = "acctestbap-%d"
   607    resource_group_name = "${azurerm_resource_group.test.name}"
   608    loadbalancer_id     = "${azurerm_lb.test.id}"
   609  }
   610  
   611  resource "azurerm_virtual_machine_scale_set" "test" {
   612    name                = "acctestvmss-%d"
   613    resource_group_name = "${azurerm_resource_group.test.name}"
   614    location            = "${azurerm_resource_group.test.location}"
   615    upgrade_policy_mode = "Automatic"
   616  
   617    sku {
   618      name     = "Standard_A0"
   619      tier     = "Standard"
   620      capacity = "1"
   621    }
   622  
   623    os_profile {
   624      computer_name_prefix = "prefix"
   625      admin_username       = "ubuntu"
   626      admin_password       = "password"
   627      custom_data          = "custom data!"
   628    }
   629  
   630    os_profile_linux_config {
   631      disable_password_authentication = true
   632  
   633      ssh_keys {
   634        path     = "/home/ubuntu/.ssh/authorized_keys"
   635        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"
   636      }
   637    }
   638  
   639    network_profile {
   640      name    = "TestNetworkProfile"
   641      primary = true
   642  
   643      ip_configuration {
   644        name                                   = "TestIPConfiguration"
   645        subnet_id                              = "${azurerm_subnet.test.id}"
   646        load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"]
   647      }
   648    }
   649  
   650    storage_profile_os_disk {
   651      name           = "osDiskProfile"
   652      caching        = "ReadWrite"
   653      create_option  = "FromImage"
   654      os_type        = "linux"
   655      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
   656    }
   657  
   658    storage_profile_image_reference {
   659      publisher = "Canonical"
   660      offer     = "UbuntuServer"
   661      sku       = "14.04.2-LTS"
   662      version   = "latest"
   663    }
   664  
   665    tags {
   666      ThisIs = "a test"
   667    }
   668  }
   669  
   670  `, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
   671  }
   672  
   673  var testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate = `
   674  resource "azurerm_resource_group" "test" {
   675    name     = "acctestrg-%d"
   676    location = "southcentralus"
   677  }
   678  
   679  resource "azurerm_virtual_network" "test" {
   680    name                = "acctvn-%d"
   681    address_space       = ["10.0.0.0/16"]
   682    location            = "southcentralus"
   683    resource_group_name = "${azurerm_resource_group.test.name}"
   684  }
   685  
   686  resource "azurerm_subnet" "test" {
   687    name                 = "acctsub-%d"
   688    resource_group_name  = "${azurerm_resource_group.test.name}"
   689    virtual_network_name = "${azurerm_virtual_network.test.name}"
   690    address_prefix       = "10.0.2.0/24"
   691  }
   692  
   693  resource "azurerm_storage_account" "test" {
   694    name                = "accsa%d"
   695    resource_group_name = "${azurerm_resource_group.test.name}"
   696    location            = "southcentralus"
   697    account_type        = "Standard_LRS"
   698  }
   699  
   700  resource "azurerm_storage_container" "test" {
   701    name                  = "vhds"
   702    resource_group_name   = "${azurerm_resource_group.test.name}"
   703    storage_account_name  = "${azurerm_storage_account.test.name}"
   704    container_access_type = "private"
   705  }
   706  
   707  resource "azurerm_lb" "test" {
   708    name                = "acctestlb-%d"
   709    location            = "southcentralus"
   710    resource_group_name = "${azurerm_resource_group.test.name}"
   711  
   712    frontend_ip_configuration {
   713      name                          = "default"
   714      subnet_id                     = "${azurerm_subnet.test.id}"
   715      private_ip_address_allocation = "Dynamic"
   716    }
   717  }
   718  
   719  resource "azurerm_lb_backend_address_pool" "test" {
   720    name                = "test"
   721    resource_group_name = "${azurerm_resource_group.test.name}"
   722    location            = "southcentralus"
   723    loadbalancer_id     = "${azurerm_lb.test.id}"
   724  }
   725  
   726  resource "azurerm_virtual_machine_scale_set" "test" {
   727    name                = "acctvmss-%d"
   728    location            = "southcentralus"
   729    resource_group_name = "${azurerm_resource_group.test.name}"
   730    upgrade_policy_mode = "Manual"
   731  
   732    sku {
   733      name     = "Standard_A0"
   734      tier     = "Standard"
   735      capacity = 1
   736    }
   737  
   738    os_profile {
   739      computer_name_prefix = "testvm-%d"
   740      admin_username       = "myadmin"
   741      admin_password       = "Passwword1234"
   742    }
   743  
   744    network_profile {
   745      name    = "TestNetworkProfile"
   746      primary = true
   747  
   748      ip_configuration {
   749        name                                   = "TestIPConfiguration"
   750        subnet_id                              = "${azurerm_subnet.test.id}"
   751        load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"]
   752      }
   753    }
   754  
   755    storage_profile_os_disk {
   756      name           = "os-disk"
   757      caching        = "ReadWrite"
   758      create_option  = "FromImage"
   759      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
   760    }
   761  
   762    storage_profile_image_reference {
   763      publisher = "Canonical"
   764      offer     = "UbuntuServer"
   765      sku       = "14.04.2-LTS"
   766      version   = "latest"
   767    }
   768  }
   769  `
   770  
   771  var testAccAzureRMVirtualMachineScaleSetOverprovisionTemplate = `
   772  resource "azurerm_resource_group" "test" {
   773    name     = "acctestrg-%d"
   774    location = "southcentralus"
   775  }
   776  
   777  resource "azurerm_virtual_network" "test" {
   778    name                = "acctvn-%d"
   779    address_space       = ["10.0.0.0/16"]
   780    location            = "southcentralus"
   781    resource_group_name = "${azurerm_resource_group.test.name}"
   782  }
   783  
   784  resource "azurerm_subnet" "test" {
   785    name                 = "acctsub-%d"
   786    resource_group_name  = "${azurerm_resource_group.test.name}"
   787    virtual_network_name = "${azurerm_virtual_network.test.name}"
   788    address_prefix       = "10.0.2.0/24"
   789  }
   790  
   791  resource "azurerm_storage_account" "test" {
   792    name                = "accsa%d"
   793    resource_group_name = "${azurerm_resource_group.test.name}"
   794    location            = "southcentralus"
   795    account_type        = "Standard_LRS"
   796  }
   797  
   798  resource "azurerm_storage_container" "test" {
   799    name                  = "vhds"
   800    resource_group_name   = "${azurerm_resource_group.test.name}"
   801    storage_account_name  = "${azurerm_storage_account.test.name}"
   802    container_access_type = "private"
   803  }
   804  
   805  resource "azurerm_virtual_machine_scale_set" "test" {
   806    name                = "acctvmss-%d"
   807    location            = "southcentralus"
   808    resource_group_name = "${azurerm_resource_group.test.name}"
   809    upgrade_policy_mode = "Manual"
   810    overprovision       = false
   811  
   812    sku {
   813      name     = "Standard_A0"
   814      tier     = "Standard"
   815      capacity = 1
   816    }
   817  
   818    os_profile {
   819      computer_name_prefix = "testvm-%d"
   820      admin_username       = "myadmin"
   821      admin_password       = "Passwword1234"
   822    }
   823  
   824    network_profile {
   825      name    = "TestNetworkProfile"
   826      primary = true
   827  
   828      ip_configuration {
   829        name      = "TestIPConfiguration"
   830        subnet_id = "${azurerm_subnet.test.id}"
   831      }
   832    }
   833  
   834    storage_profile_os_disk {
   835      name           = "os-disk"
   836      caching        = "ReadWrite"
   837      create_option  = "FromImage"
   838      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
   839    }
   840  
   841    storage_profile_image_reference {
   842      publisher = "Canonical"
   843      offer     = "UbuntuServer"
   844      sku       = "14.04.2-LTS"
   845      version   = "latest"
   846    }
   847  }
   848  `
   849  
   850  var testAccAzureRMVirtualMachineScaleSetExtensionTemplate = `
   851  resource "azurerm_resource_group" "test" {
   852    name     = "acctestrg-%d"
   853    location = "southcentralus"
   854  }
   855  
   856  resource "azurerm_virtual_network" "test" {
   857    name                = "acctvn-%d"
   858    address_space       = ["10.0.0.0/16"]
   859    location            = "southcentralus"
   860    resource_group_name = "${azurerm_resource_group.test.name}"
   861  }
   862  
   863  resource "azurerm_subnet" "test" {
   864    name                 = "acctsub-%d"
   865    resource_group_name  = "${azurerm_resource_group.test.name}"
   866    virtual_network_name = "${azurerm_virtual_network.test.name}"
   867    address_prefix       = "10.0.2.0/24"
   868  }
   869  
   870  resource "azurerm_storage_account" "test" {
   871    name                = "accsa%d"
   872    resource_group_name = "${azurerm_resource_group.test.name}"
   873    location            = "southcentralus"
   874    account_type        = "Standard_LRS"
   875  }
   876  
   877  resource "azurerm_storage_container" "test" {
   878    name                  = "vhds"
   879    resource_group_name   = "${azurerm_resource_group.test.name}"
   880    storage_account_name  = "${azurerm_storage_account.test.name}"
   881    container_access_type = "private"
   882  }
   883  
   884  resource "azurerm_virtual_machine_scale_set" "test" {
   885    name                = "acctvmss-%d"
   886    location            = "southcentralus"
   887    resource_group_name = "${azurerm_resource_group.test.name}"
   888    upgrade_policy_mode = "Manual"
   889    overprovision       = false
   890  
   891    sku {
   892      name     = "Standard_A0"
   893      tier     = "Standard"
   894      capacity = 1
   895    }
   896  
   897    os_profile {
   898      computer_name_prefix = "testvm-%d"
   899      admin_username       = "myadmin"
   900      admin_password       = "Passwword1234"
   901    }
   902  
   903    network_profile {
   904      name    = "TestNetworkProfile"
   905      primary = true
   906  
   907      ip_configuration {
   908        name      = "TestIPConfiguration"
   909        subnet_id = "${azurerm_subnet.test.id}"
   910      }
   911    }
   912  
   913    storage_profile_os_disk {
   914      name           = "os-disk"
   915      caching        = "ReadWrite"
   916      create_option  = "FromImage"
   917      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
   918    }
   919  
   920    storage_profile_image_reference {
   921      publisher = "Canonical"
   922      offer     = "UbuntuServer"
   923      sku       = "14.04.2-LTS"
   924      version   = "latest"
   925    }
   926  
   927    extension {
   928      name                       = "CustomScript"
   929      publisher                  = "Microsoft.Azure.Extensions"
   930      type                       = "CustomScript"
   931      type_handler_version       = "2.0"
   932      auto_upgrade_minor_version = true
   933  
   934      settings = <<SETTINGS
   935  		{
   936  			"commandToExecute": "echo $HOSTNAME"
   937  		}
   938  SETTINGS
   939  
   940      protected_settings = <<SETTINGS
   941  		{
   942  			"storageAccountName": "${azurerm_storage_account.test.name}",
   943  			"storageAccountKey": "${azurerm_storage_account.test.primary_access_key}"
   944  		}
   945  SETTINGS
   946    }
   947  }
   948  
   949  `
   950  
   951  var testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate = `
   952  resource "azurerm_resource_group" "test" {
   953    name     = "acctestrg-%d"
   954    location = "southcentralus"
   955  }
   956  
   957  resource "azurerm_virtual_network" "test" {
   958    name                = "acctvn-%d"
   959    address_space       = ["10.0.0.0/16"]
   960    location            = "southcentralus"
   961    resource_group_name = "${azurerm_resource_group.test.name}"
   962  }
   963  
   964  resource "azurerm_subnet" "test" {
   965    name                 = "acctsub-%d"
   966    resource_group_name  = "${azurerm_resource_group.test.name}"
   967    virtual_network_name = "${azurerm_virtual_network.test.name}"
   968    address_prefix       = "10.0.2.0/24"
   969  }
   970  
   971  resource "azurerm_storage_account" "test" {
   972    name                = "accsa%d"
   973    resource_group_name = "${azurerm_resource_group.test.name}"
   974    location            = "southcentralus"
   975    account_type        = "Standard_LRS"
   976  }
   977  
   978  resource "azurerm_storage_container" "test" {
   979    name                  = "vhds"
   980    resource_group_name   = "${azurerm_resource_group.test.name}"
   981    storage_account_name  = "${azurerm_storage_account.test.name}"
   982    container_access_type = "private"
   983  }
   984  
   985  resource "azurerm_virtual_machine_scale_set" "test" {
   986    name                = "acctvmss-%d"
   987    location            = "southcentralus"
   988    resource_group_name = "${azurerm_resource_group.test.name}"
   989    upgrade_policy_mode = "Manual"
   990    overprovision       = false
   991  
   992    sku {
   993      name     = "Standard_A0"
   994      tier     = "Standard"
   995      capacity = 1
   996    }
   997  
   998    os_profile {
   999      computer_name_prefix = "testvm-%d"
  1000      admin_username       = "myadmin"
  1001      admin_password       = "Passwword1234"
  1002    }
  1003  
  1004    network_profile {
  1005      name    = "TestNetworkProfile"
  1006      primary = true
  1007  
  1008      ip_configuration {
  1009        name      = "TestIPConfiguration"
  1010        subnet_id = "${azurerm_subnet.test.id}"
  1011      }
  1012    }
  1013  
  1014    storage_profile_os_disk {
  1015      name           = "os-disk"
  1016      caching        = "ReadWrite"
  1017      create_option  = "FromImage"
  1018      vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
  1019    }
  1020  
  1021    storage_profile_image_reference {
  1022      publisher = "Canonical"
  1023      offer     = "UbuntuServer"
  1024      sku       = "14.04.2-LTS"
  1025      version   = "latest"
  1026    }
  1027  
  1028    extension {
  1029      name                       = "CustomScript"
  1030      publisher                  = "Microsoft.Azure.Extensions"
  1031      type                       = "CustomScript"
  1032      type_handler_version       = "2.0"
  1033      auto_upgrade_minor_version = true
  1034  
  1035      settings = <<SETTINGS
  1036  		{
  1037  			"commandToExecute": "echo $HOSTNAME"
  1038  		}
  1039  SETTINGS
  1040  
  1041      protected_settings = <<SETTINGS
  1042  		{
  1043  			"storageAccountName": "${azurerm_storage_account.test.name}",
  1044  			"storageAccountKey": "${azurerm_storage_account.test.primary_access_key}"
  1045  		}
  1046  SETTINGS
  1047    }
  1048  
  1049    extension {
  1050      name                       = "Docker"
  1051      publisher                  = "Microsoft.Azure.Extensions"
  1052      type                       = "DockerExtension"
  1053      type_handler_version       = "1.0"
  1054      auto_upgrade_minor_version = true
  1055    }
  1056  }
  1057  `