github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go (about)

     1  package azurerm
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/Azure/azure-sdk-for-go/arm/compute"
     9  	"github.com/hashicorp/terraform/helper/acctest"
    10  	"github.com/hashicorp/terraform/helper/resource"
    11  	"github.com/hashicorp/terraform/terraform"
    12  )
    13  
    14  func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) {
    15  	var vm compute.VirtualMachine
    16  	ri := acctest.RandInt()
    17  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    18  	resource.Test(t, resource.TestCase{
    19  		PreCheck:     func() { testAccPreCheck(t) },
    20  		Providers:    testAccProviders,
    21  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    22  		Steps: []resource.TestStep{
    23  			{
    24  				Config: config,
    25  				Check: resource.ComposeTestCheckFunc(
    26  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    27  				),
    28  			},
    29  		},
    30  	})
    31  }
    32  
    33  func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) {
    34  	var vm compute.VirtualMachine
    35  	ri := acctest.RandInt()
    36  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    37  	resource.Test(t, resource.TestCase{
    38  		PreCheck:     func() { testAccPreCheck(t) },
    39  		Providers:    testAccProviders,
    40  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    41  		Steps: []resource.TestStep{
    42  			{
    43  				Config: config,
    44  				Check: resource.ComposeTestCheckFunc(
    45  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    46  					testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test", &vm),
    47  				),
    48  				ExpectNonEmptyPlan: true,
    49  			},
    50  		},
    51  	})
    52  }
    53  
    54  func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) {
    55  	var vm compute.VirtualMachine
    56  
    57  	ri := acctest.RandInt()
    58  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri)
    59  	resource.Test(t, resource.TestCase{
    60  		PreCheck:     func() { testAccPreCheck(t) },
    61  		Providers:    testAccProviders,
    62  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    63  		Steps: []resource.TestStep{
    64  			{
    65  				Config: config,
    66  				Check: resource.ComposeTestCheckFunc(
    67  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    68  				),
    69  			},
    70  		},
    71  	})
    72  }
    73  
    74  func TestAccAzureRMVirtualMachine_tags(t *testing.T) {
    75  	var vm compute.VirtualMachine
    76  
    77  	ri := acctest.RandInt()
    78  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    79  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineUpdated, ri, ri, ri, ri, ri, ri, ri)
    80  	resource.Test(t, resource.TestCase{
    81  		PreCheck:     func() { testAccPreCheck(t) },
    82  		Providers:    testAccProviders,
    83  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    84  		Steps: []resource.TestStep{
    85  			{
    86  				Config: preConfig,
    87  				Check: resource.ComposeTestCheckFunc(
    88  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    89  					resource.TestCheckResourceAttr(
    90  						"azurerm_virtual_machine.test", "tags.%", "2"),
    91  					resource.TestCheckResourceAttr(
    92  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
    93  					resource.TestCheckResourceAttr(
    94  						"azurerm_virtual_machine.test", "tags.cost-center", "Ops"),
    95  				),
    96  			},
    97  
    98  			{
    99  				Config: postConfig,
   100  				Check: resource.ComposeTestCheckFunc(
   101  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   102  					resource.TestCheckResourceAttr(
   103  						"azurerm_virtual_machine.test", "tags.%", "1"),
   104  					resource.TestCheckResourceAttr(
   105  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
   106  				),
   107  			},
   108  		},
   109  	})
   110  }
   111  
   112  //This is a regression test around https://github.com/hashicorp/terraform/issues/6517
   113  //Because we use CreateOrUpdate, we were sending an empty password on update requests
   114  func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) {
   115  	var vm compute.VirtualMachine
   116  
   117  	ri := acctest.RandInt()
   118  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   119  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   120  	resource.Test(t, resource.TestCase{
   121  		PreCheck:     func() { testAccPreCheck(t) },
   122  		Providers:    testAccProviders,
   123  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   124  		Steps: []resource.TestStep{
   125  			{
   126  				Config: preConfig,
   127  				Check: resource.ComposeTestCheckFunc(
   128  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   129  					resource.TestCheckResourceAttr(
   130  						"azurerm_virtual_machine.test", "vm_size", "Standard_A0"),
   131  				),
   132  			},
   133  			{
   134  				Config: postConfig,
   135  				Check: resource.ComposeTestCheckFunc(
   136  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   137  					resource.TestCheckResourceAttr(
   138  						"azurerm_virtual_machine.test", "vm_size", "Standard_A1"),
   139  				),
   140  			},
   141  		},
   142  	})
   143  }
   144  
   145  func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) {
   146  	var vm compute.VirtualMachine
   147  	ri := acctest.RandInt()
   148  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicWindowsMachine, ri, ri, ri, ri, ri, ri)
   149  	resource.Test(t, resource.TestCase{
   150  		PreCheck:     func() { testAccPreCheck(t) },
   151  		Providers:    testAccProviders,
   152  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   153  		Steps: []resource.TestStep{
   154  			{
   155  				Config: config,
   156  				Check: resource.ComposeTestCheckFunc(
   157  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   158  				),
   159  			},
   160  		},
   161  	})
   162  }
   163  
   164  func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) {
   165  	var vm compute.VirtualMachine
   166  	ri := acctest.RandInt()
   167  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsUnattendedConfig, ri, ri, ri, ri, ri, ri)
   168  	resource.Test(t, resource.TestCase{
   169  		PreCheck:     func() { testAccPreCheck(t) },
   170  		Providers:    testAccProviders,
   171  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   172  		Steps: []resource.TestStep{
   173  			{
   174  				Config: config,
   175  				Check: resource.ComposeTestCheckFunc(
   176  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   177  				),
   178  			},
   179  		},
   180  	})
   181  }
   182  
   183  func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) {
   184  	var vm compute.VirtualMachine
   185  	ri := acctest.RandInt()
   186  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_diagnosticsProfile, ri, ri, ri, ri, ri, ri)
   187  	resource.Test(t, resource.TestCase{
   188  		PreCheck:     func() { testAccPreCheck(t) },
   189  		Providers:    testAccProviders,
   190  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   191  		Steps: []resource.TestStep{
   192  			{
   193  				Config: config,
   194  				Check: resource.ComposeTestCheckFunc(
   195  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   196  				),
   197  			},
   198  		},
   199  	})
   200  }
   201  
   202  func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) {
   203  	var vm compute.VirtualMachine
   204  	ri := acctest.RandInt()
   205  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_winRMConfig, ri, ri, ri, ri, ri, ri)
   206  	resource.Test(t, resource.TestCase{
   207  		PreCheck:     func() { testAccPreCheck(t) },
   208  		Providers:    testAccProviders,
   209  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   210  		Steps: []resource.TestStep{
   211  			{
   212  				Config: config,
   213  				Check: resource.ComposeTestCheckFunc(
   214  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   215  				),
   216  			},
   217  		},
   218  	})
   219  }
   220  
   221  func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) {
   222  	var vm compute.VirtualMachine
   223  	ri := acctest.RandInt()
   224  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri)
   225  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM, ri, ri, ri, ri, ri)
   226  	resource.Test(t, resource.TestCase{
   227  		PreCheck:     func() { testAccPreCheck(t) },
   228  		Providers:    testAccProviders,
   229  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   230  		Steps: []resource.TestStep{
   231  			{
   232  				Config: preConfig,
   233  				Check: resource.ComposeTestCheckFunc(
   234  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   235  				),
   236  			},
   237  			{
   238  				Config: postConfig,
   239  				Check: resource.ComposeTestCheckFunc(
   240  					testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", true),
   241  					testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", true),
   242  				),
   243  			},
   244  		},
   245  	})
   246  }
   247  
   248  func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) {
   249  	var vm compute.VirtualMachine
   250  	ri := acctest.RandInt()
   251  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore, ri, ri, ri, ri, ri, ri, ri, ri)
   252  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter, ri, ri, ri, ri, ri, ri)
   253  	resource.Test(t, resource.TestCase{
   254  		PreCheck:     func() { testAccPreCheck(t) },
   255  		Providers:    testAccProviders,
   256  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   257  		Steps: []resource.TestStep{
   258  			{
   259  				Config: preConfig,
   260  				Check: resource.ComposeTestCheckFunc(
   261  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   262  				),
   263  			},
   264  			{
   265  				Config: postConfig,
   266  				Check: resource.ComposeTestCheckFunc(
   267  					testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", false),
   268  					testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", false),
   269  				),
   270  			},
   271  		},
   272  	})
   273  }
   274  
   275  func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) {
   276  	var afterCreate, afterUpdate compute.VirtualMachine
   277  
   278  	ri := acctest.RandInt()
   279  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_machineNameBeforeUpdate, ri, ri, ri, ri, ri, ri, ri)
   280  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateMachineName, ri, ri, ri, ri, ri, ri, ri)
   281  	resource.Test(t, resource.TestCase{
   282  		PreCheck:     func() { testAccPreCheck(t) },
   283  		Providers:    testAccProviders,
   284  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   285  		Steps: []resource.TestStep{
   286  			resource.TestStep{
   287  				Config: preConfig,
   288  				Check: resource.ComposeTestCheckFunc(
   289  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   290  				),
   291  			},
   292  
   293  			resource.TestStep{
   294  				Config: postConfig,
   295  				Check: resource.ComposeTestCheckFunc(
   296  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   297  					testAccCheckVirtualMachineRecreated(
   298  						t, &afterCreate, &afterUpdate),
   299  				),
   300  			},
   301  		},
   302  	})
   303  }
   304  
   305  func TestAccAzureRMVirtualMachine_ChangeAvailbilitySet(t *testing.T) {
   306  	var afterCreate, afterUpdate compute.VirtualMachine
   307  
   308  	ri := acctest.RandInt()
   309  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri)
   310  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri)
   311  	resource.Test(t, resource.TestCase{
   312  		PreCheck:     func() { testAccPreCheck(t) },
   313  		Providers:    testAccProviders,
   314  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   315  		Steps: []resource.TestStep{
   316  			resource.TestStep{
   317  				Config: preConfig,
   318  				Check: resource.ComposeTestCheckFunc(
   319  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   320  				),
   321  			},
   322  
   323  			resource.TestStep{
   324  				Config: postConfig,
   325  				Check: resource.ComposeTestCheckFunc(
   326  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   327  					testAccCheckVirtualMachineRecreated(
   328  						t, &afterCreate, &afterUpdate),
   329  				),
   330  			},
   331  		},
   332  	})
   333  }
   334  
   335  func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) resource.TestCheckFunc {
   336  	return func(s *terraform.State) error {
   337  		// Ensure we have enough information in state to look up in API
   338  		rs, ok := s.RootModule().Resources[name]
   339  		if !ok {
   340  			return fmt.Errorf("Not found: %s", name)
   341  		}
   342  
   343  		vmName := rs.Primary.Attributes["name"]
   344  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   345  		if !hasResourceGroup {
   346  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   347  		}
   348  
   349  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   350  
   351  		resp, err := conn.Get(resourceGroup, vmName, "")
   352  		if err != nil {
   353  			return fmt.Errorf("Bad: Get on vmClient: %s", err)
   354  		}
   355  
   356  		if resp.StatusCode == http.StatusNotFound {
   357  			return fmt.Errorf("Bad: VirtualMachine %q (resource group: %q) does not exist", vmName, resourceGroup)
   358  		}
   359  
   360  		*vm = resp
   361  
   362  		return nil
   363  	}
   364  }
   365  
   366  func testAccCheckVirtualMachineRecreated(t *testing.T,
   367  	before, after *compute.VirtualMachine) resource.TestCheckFunc {
   368  	return func(s *terraform.State) error {
   369  		if before.ID == after.ID {
   370  			t.Fatalf("Expected change of Virtual Machine IDs, but both were %v", before.ID)
   371  		}
   372  		return nil
   373  	}
   374  }
   375  
   376  func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error {
   377  	conn := testAccProvider.Meta().(*ArmClient).vmClient
   378  
   379  	for _, rs := range s.RootModule().Resources {
   380  		if rs.Type != "azurerm_virtual_machine" {
   381  			continue
   382  		}
   383  
   384  		name := rs.Primary.Attributes["name"]
   385  		resourceGroup := rs.Primary.Attributes["resource_group_name"]
   386  
   387  		resp, err := conn.Get(resourceGroup, name, "")
   388  
   389  		if err != nil {
   390  			return nil
   391  		}
   392  
   393  		if resp.StatusCode != http.StatusNotFound {
   394  			return fmt.Errorf("Virtual Machine still exists:\n%#v", resp.Properties)
   395  		}
   396  	}
   397  
   398  	return nil
   399  }
   400  
   401  func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) resource.TestCheckFunc {
   402  	return func(s *terraform.State) error {
   403  		for _, rs := range s.RootModule().Resources {
   404  			if rs.Type != "azurerm_storage_container" {
   405  				continue
   406  			}
   407  
   408  			// fetch storage account and container name
   409  			resourceGroup := rs.Primary.Attributes["resource_group_name"]
   410  			storageAccountName := rs.Primary.Attributes["storage_account_name"]
   411  			containerName := rs.Primary.Attributes["name"]
   412  			storageClient, _, err := testAccProvider.Meta().(*ArmClient).getBlobStorageClientForStorageAccount(resourceGroup, storageAccountName)
   413  			if err != nil {
   414  				return fmt.Errorf("Error creating Blob storage client: %s", err)
   415  			}
   416  
   417  			exists, err := storageClient.BlobExists(containerName, name)
   418  			if err != nil {
   419  				return fmt.Errorf("Error checking if Disk VHD Blob exists: %s", err)
   420  			}
   421  
   422  			if exists && !shouldExist {
   423  				return fmt.Errorf("Disk VHD Blob still exists")
   424  			} else if !exists && shouldExist {
   425  				return fmt.Errorf("Disk VHD Blob should exist")
   426  			}
   427  		}
   428  
   429  		return nil
   430  	}
   431  }
   432  
   433  func testCheckAzureRMVirtualMachineDisappears(name string, vm *compute.VirtualMachine) resource.TestCheckFunc {
   434  	return func(s *terraform.State) error {
   435  		// Ensure we have enough information in state to look up in API
   436  		rs, ok := s.RootModule().Resources[name]
   437  		if !ok {
   438  			return fmt.Errorf("Not found: %s", name)
   439  		}
   440  
   441  		vmName := rs.Primary.Attributes["name"]
   442  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   443  		if !hasResourceGroup {
   444  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   445  		}
   446  
   447  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   448  
   449  		_, err := conn.Delete(resourceGroup, vmName, make(chan struct{}))
   450  		if err != nil {
   451  			return fmt.Errorf("Bad: Delete on vmClient: %s", err)
   452  		}
   453  
   454  		return nil
   455  	}
   456  }
   457  
   458  var testAccAzureRMVirtualMachine_basicLinuxMachine = `
   459  resource "azurerm_resource_group" "test" {
   460      name = "acctestRG-%d"
   461      location = "West US"
   462  }
   463  
   464  resource "azurerm_virtual_network" "test" {
   465      name = "acctvn-%d"
   466      address_space = ["10.0.0.0/16"]
   467      location = "West US"
   468      resource_group_name = "${azurerm_resource_group.test.name}"
   469  }
   470  
   471  resource "azurerm_subnet" "test" {
   472      name = "acctsub-%d"
   473      resource_group_name = "${azurerm_resource_group.test.name}"
   474      virtual_network_name = "${azurerm_virtual_network.test.name}"
   475      address_prefix = "10.0.2.0/24"
   476  }
   477  
   478  resource "azurerm_network_interface" "test" {
   479      name = "acctni-%d"
   480      location = "West US"
   481      resource_group_name = "${azurerm_resource_group.test.name}"
   482  
   483      ip_configuration {
   484      	name = "testconfiguration1"
   485      	subnet_id = "${azurerm_subnet.test.id}"
   486      	private_ip_address_allocation = "dynamic"
   487      }
   488  }
   489  
   490  resource "azurerm_storage_account" "test" {
   491      name = "accsa%d"
   492      resource_group_name = "${azurerm_resource_group.test.name}"
   493      location = "westus"
   494      account_type = "Standard_LRS"
   495  
   496      tags {
   497          environment = "staging"
   498      }
   499  }
   500  
   501  resource "azurerm_storage_container" "test" {
   502      name = "vhds"
   503      resource_group_name = "${azurerm_resource_group.test.name}"
   504      storage_account_name = "${azurerm_storage_account.test.name}"
   505      container_access_type = "private"
   506  }
   507  
   508  resource "azurerm_virtual_machine" "test" {
   509      name = "acctvm-%d"
   510      location = "West US"
   511      resource_group_name = "${azurerm_resource_group.test.name}"
   512      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   513      vm_size = "Standard_A0"
   514  
   515      storage_image_reference {
   516  	publisher = "Canonical"
   517  	offer = "UbuntuServer"
   518  	sku = "14.04.2-LTS"
   519  	version = "latest"
   520      }
   521  
   522      storage_os_disk {
   523          name = "myosdisk1"
   524          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   525          caching = "ReadWrite"
   526          create_option = "FromImage"
   527          disk_size_gb = "45"
   528      }
   529  
   530      os_profile {
   531  	computer_name = "hostname%d"
   532  	admin_username = "testadmin"
   533  	admin_password = "Password1234!"
   534      }
   535  
   536      os_profile_linux_config {
   537  	disable_password_authentication = false
   538      }
   539  
   540      tags {
   541      	environment = "Production"
   542      	cost-center = "Ops"
   543      }
   544  }
   545  `
   546  
   547  var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = `
   548  resource "azurerm_resource_group" "test" {
   549      name = "acctestRG-%d"
   550      location = "West US"
   551  }
   552  
   553  resource "azurerm_virtual_network" "test" {
   554      name = "acctvn-%d"
   555      address_space = ["10.0.0.0/16"]
   556      location = "West US"
   557      resource_group_name = "${azurerm_resource_group.test.name}"
   558  }
   559  
   560  resource "azurerm_subnet" "test" {
   561      name = "acctsub-%d"
   562      resource_group_name = "${azurerm_resource_group.test.name}"
   563      virtual_network_name = "${azurerm_virtual_network.test.name}"
   564      address_prefix = "10.0.2.0/24"
   565  }
   566  
   567  resource "azurerm_network_interface" "test" {
   568      name = "acctni-%d"
   569      location = "West US"
   570      resource_group_name = "${azurerm_resource_group.test.name}"
   571  
   572      ip_configuration {
   573      	name = "testconfiguration1"
   574      	subnet_id = "${azurerm_subnet.test.id}"
   575      	private_ip_address_allocation = "dynamic"
   576      }
   577  }
   578  
   579  resource "azurerm_storage_account" "test" {
   580      name = "accsa%d"
   581      resource_group_name = "${azurerm_resource_group.test.name}"
   582      location = "westus"
   583      account_type = "Standard_LRS"
   584  
   585      tags {
   586          environment = "staging"
   587      }
   588  }
   589  
   590  resource "azurerm_storage_container" "test" {
   591      name = "vhds"
   592      resource_group_name = "${azurerm_resource_group.test.name}"
   593      storage_account_name = "${azurerm_storage_account.test.name}"
   594      container_access_type = "private"
   595  }
   596  
   597  resource "azurerm_virtual_machine" "test" {
   598      name = "acctvm-%d"
   599      location = "West US"
   600      resource_group_name = "${azurerm_resource_group.test.name}"
   601      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   602      vm_size = "Standard_A0"
   603      delete_os_disk_on_termination = true
   604  
   605      storage_image_reference {
   606  	publisher = "Canonical"
   607  	offer = "UbuntuServer"
   608  	sku = "14.04.2-LTS"
   609  	version = "latest"
   610      }
   611  
   612      storage_os_disk {
   613          name = "myosdisk1"
   614          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   615          caching = "ReadWrite"
   616          create_option = "FromImage"
   617      }
   618  
   619      os_profile {
   620  	computer_name = "hostname%d"
   621  	admin_username = "testadmin"
   622  	admin_password = "Password1234!"
   623      }
   624  
   625      os_profile_linux_config {
   626  	disable_password_authentication = false
   627      }
   628  
   629      tags {
   630      	environment = "Production"
   631      	cost-center = "Ops"
   632      }
   633  }
   634  `
   635  
   636  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore = `
   637  resource "azurerm_resource_group" "test" {
   638      name = "acctestRG-%d"
   639      location = "West US"
   640  }
   641  
   642  resource "azurerm_resource_group" "test-sa" {
   643      name = "acctestRG-sa-%d"
   644      location = "West US"
   645  }
   646  
   647  resource "azurerm_virtual_network" "test" {
   648      name = "acctvn-%d"
   649      address_space = ["10.0.0.0/16"]
   650      location = "West US"
   651      resource_group_name = "${azurerm_resource_group.test.name}"
   652  }
   653  
   654  resource "azurerm_subnet" "test" {
   655      name = "acctsub-%d"
   656      resource_group_name = "${azurerm_resource_group.test.name}"
   657      virtual_network_name = "${azurerm_virtual_network.test.name}"
   658      address_prefix = "10.0.2.0/24"
   659  }
   660  
   661  resource "azurerm_network_interface" "test" {
   662      name = "acctni-%d"
   663      location = "West US"
   664      resource_group_name = "${azurerm_resource_group.test.name}"
   665  
   666      ip_configuration {
   667      	name = "testconfiguration1"
   668      	subnet_id = "${azurerm_subnet.test.id}"
   669      	private_ip_address_allocation = "dynamic"
   670      }
   671  }
   672  
   673  resource "azurerm_storage_account" "test" {
   674      name = "accsa%d"
   675      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   676      location = "westus"
   677      account_type = "Standard_LRS"
   678  
   679      tags {
   680          environment = "staging"
   681      }
   682  }
   683  
   684  resource "azurerm_storage_container" "test" {
   685      name = "vhds"
   686      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   687      storage_account_name = "${azurerm_storage_account.test.name}"
   688      container_access_type = "private"
   689  }
   690  
   691  resource "azurerm_virtual_machine" "test" {
   692      name = "acctvm-%d"
   693      location = "West US"
   694      resource_group_name = "${azurerm_resource_group.test.name}"
   695      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   696      vm_size = "Standard_A0"
   697  
   698      storage_image_reference {
   699  	publisher = "Canonical"
   700  	offer = "UbuntuServer"
   701  	sku = "14.04.2-LTS"
   702  	version = "latest"
   703      }
   704  
   705      storage_os_disk {
   706          name = "myosdisk1"
   707          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   708          caching = "ReadWrite"
   709          create_option = "FromImage"
   710      }
   711  
   712      delete_os_disk_on_termination = true
   713  
   714      storage_data_disk {
   715          name          = "mydatadisk1"
   716          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
   717      	disk_size_gb  = "1023"
   718      	create_option = "Empty"
   719      	lun           = 0
   720      }
   721  
   722      delete_data_disks_on_termination = true
   723  
   724      os_profile {
   725  	computer_name = "hostname%d"
   726  	admin_username = "testadmin"
   727  	admin_password = "Password1234!"
   728      }
   729  
   730      os_profile_linux_config {
   731  	disable_password_authentication = false
   732      }
   733  
   734      tags {
   735      	environment = "Production"
   736      	cost-center = "Ops"
   737      }
   738  }
   739  `
   740  
   741  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter = `
   742  resource "azurerm_resource_group" "test" {
   743      name = "acctestRG-%d"
   744      location = "West US"
   745  }
   746  
   747  resource "azurerm_resource_group" "test-sa" {
   748      name = "acctestRG-sa-%d"
   749      location = "West US"
   750  }
   751  
   752  resource "azurerm_virtual_network" "test" {
   753      name = "acctvn-%d"
   754      address_space = ["10.0.0.0/16"]
   755      location = "West US"
   756      resource_group_name = "${azurerm_resource_group.test.name}"
   757  }
   758  
   759  resource "azurerm_subnet" "test" {
   760      name = "acctsub-%d"
   761      resource_group_name = "${azurerm_resource_group.test.name}"
   762      virtual_network_name = "${azurerm_virtual_network.test.name}"
   763      address_prefix = "10.0.2.0/24"
   764  }
   765  
   766  resource "azurerm_network_interface" "test" {
   767      name = "acctni-%d"
   768      location = "West US"
   769      resource_group_name = "${azurerm_resource_group.test.name}"
   770  
   771      ip_configuration {
   772      	name = "testconfiguration1"
   773      	subnet_id = "${azurerm_subnet.test.id}"
   774      	private_ip_address_allocation = "dynamic"
   775      }
   776  }
   777  
   778  resource "azurerm_storage_account" "test" {
   779      name = "accsa%d"
   780      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   781      location = "westus"
   782      account_type = "Standard_LRS"
   783  
   784      tags {
   785          environment = "staging"
   786      }
   787  }
   788  
   789  resource "azurerm_storage_container" "test" {
   790      name = "vhds"
   791      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   792      storage_account_name = "${azurerm_storage_account.test.name}"
   793      container_access_type = "private"
   794  }
   795  `
   796  
   797  var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = `
   798  resource "azurerm_resource_group" "test" {
   799      name = "acctestRG-%d"
   800      location = "West US"
   801  }
   802  
   803  resource "azurerm_virtual_network" "test" {
   804      name = "acctvn-%d"
   805      address_space = ["10.0.0.0/16"]
   806      location = "West US"
   807      resource_group_name = "${azurerm_resource_group.test.name}"
   808  }
   809  
   810  resource "azurerm_subnet" "test" {
   811      name = "acctsub-%d"
   812      resource_group_name = "${azurerm_resource_group.test.name}"
   813      virtual_network_name = "${azurerm_virtual_network.test.name}"
   814      address_prefix = "10.0.2.0/24"
   815  }
   816  
   817  resource "azurerm_network_interface" "test" {
   818      name = "acctni-%d"
   819      location = "West US"
   820      resource_group_name = "${azurerm_resource_group.test.name}"
   821  
   822      ip_configuration {
   823      	name = "testconfiguration1"
   824      	subnet_id = "${azurerm_subnet.test.id}"
   825      	private_ip_address_allocation = "dynamic"
   826      }
   827  }
   828  
   829  resource "azurerm_storage_account" "test" {
   830      name = "accsa%d"
   831      resource_group_name = "${azurerm_resource_group.test.name}"
   832      location = "westus"
   833      account_type = "Standard_LRS"
   834  
   835      tags {
   836          environment = "staging"
   837      }
   838  }
   839  
   840  resource "azurerm_storage_container" "test" {
   841      name = "vhds"
   842      resource_group_name = "${azurerm_resource_group.test.name}"
   843      storage_account_name = "${azurerm_storage_account.test.name}"
   844      container_access_type = "private"
   845  }
   846  `
   847  
   848  var testAccAzureRMVirtualMachine_withDataDisk = `
   849  resource "azurerm_resource_group" "test" {
   850      name = "acctestRG-%d"
   851      location = "West US"
   852  }
   853  
   854  resource "azurerm_virtual_network" "test" {
   855      name = "acctvn-%d"
   856      address_space = ["10.0.0.0/16"]
   857      location = "West US"
   858      resource_group_name = "${azurerm_resource_group.test.name}"
   859  }
   860  
   861  resource "azurerm_subnet" "test" {
   862      name = "acctsub-%d"
   863      resource_group_name = "${azurerm_resource_group.test.name}"
   864      virtual_network_name = "${azurerm_virtual_network.test.name}"
   865      address_prefix = "10.0.2.0/24"
   866  }
   867  
   868  resource "azurerm_network_interface" "test" {
   869      name = "acctni-%d"
   870      location = "West US"
   871      resource_group_name = "${azurerm_resource_group.test.name}"
   872  
   873      ip_configuration {
   874      	name = "testconfiguration1"
   875      	subnet_id = "${azurerm_subnet.test.id}"
   876      	private_ip_address_allocation = "dynamic"
   877      }
   878  }
   879  
   880  resource "azurerm_storage_account" "test" {
   881      name = "accsa%d"
   882      resource_group_name = "${azurerm_resource_group.test.name}"
   883      location = "westus"
   884      account_type = "Standard_LRS"
   885  
   886      tags {
   887          environment = "staging"
   888      }
   889  }
   890  
   891  resource "azurerm_storage_container" "test" {
   892      name = "vhds"
   893      resource_group_name = "${azurerm_resource_group.test.name}"
   894      storage_account_name = "${azurerm_storage_account.test.name}"
   895      container_access_type = "private"
   896  }
   897  
   898  resource "azurerm_virtual_machine" "test" {
   899      name = "acctvm-%d"
   900      location = "West US"
   901      resource_group_name = "${azurerm_resource_group.test.name}"
   902      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   903      vm_size = "Standard_A0"
   904  
   905      storage_image_reference {
   906  	publisher = "Canonical"
   907  	offer = "UbuntuServer"
   908  	sku = "14.04.2-LTS"
   909  	version = "latest"
   910      }
   911  
   912      storage_os_disk {
   913          name = "myosdisk1"
   914          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   915          caching = "ReadWrite"
   916          create_option = "FromImage"
   917      }
   918  
   919      storage_data_disk {
   920          name          = "mydatadisk1"
   921          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
   922      	disk_size_gb  = "1023"
   923      	create_option = "Empty"
   924      	lun           = 0
   925      }
   926  
   927      os_profile {
   928  	computer_name = "hostname%d"
   929  	admin_username = "testadmin"
   930  	admin_password = "Password1234!"
   931      }
   932  
   933      os_profile_linux_config {
   934  	disable_password_authentication = false
   935      }
   936  
   937      tags {
   938      	environment = "Production"
   939      	cost-center = "Ops"
   940      }
   941  }
   942  `
   943  
   944  var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = `
   945  resource "azurerm_resource_group" "test" {
   946      name = "acctestRG-%d"
   947      location = "West US"
   948  }
   949  
   950  resource "azurerm_virtual_network" "test" {
   951      name = "acctvn-%d"
   952      address_space = ["10.0.0.0/16"]
   953      location = "West US"
   954      resource_group_name = "${azurerm_resource_group.test.name}"
   955  }
   956  
   957  resource "azurerm_subnet" "test" {
   958      name = "acctsub-%d"
   959      resource_group_name = "${azurerm_resource_group.test.name}"
   960      virtual_network_name = "${azurerm_virtual_network.test.name}"
   961      address_prefix = "10.0.2.0/24"
   962  }
   963  
   964  resource "azurerm_network_interface" "test" {
   965      name = "acctni-%d"
   966      location = "West US"
   967      resource_group_name = "${azurerm_resource_group.test.name}"
   968  
   969      ip_configuration {
   970      	name = "testconfiguration1"
   971      	subnet_id = "${azurerm_subnet.test.id}"
   972      	private_ip_address_allocation = "dynamic"
   973      }
   974  }
   975  
   976  resource "azurerm_storage_account" "test" {
   977      name = "accsa%d"
   978      resource_group_name = "${azurerm_resource_group.test.name}"
   979      location = "westus"
   980      account_type = "Standard_LRS"
   981  
   982      tags {
   983          environment = "staging"
   984      }
   985  }
   986  
   987  resource "azurerm_storage_container" "test" {
   988      name = "vhds"
   989      resource_group_name = "${azurerm_resource_group.test.name}"
   990      storage_account_name = "${azurerm_storage_account.test.name}"
   991      container_access_type = "private"
   992  }
   993  
   994  resource "azurerm_virtual_machine" "test" {
   995      name = "acctvm-%d"
   996      location = "West US"
   997      resource_group_name = "${azurerm_resource_group.test.name}"
   998      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   999      vm_size = "Standard_A0"
  1000  
  1001      storage_image_reference {
  1002  	publisher = "Canonical"
  1003  	offer = "UbuntuServer"
  1004  	sku = "14.04.2-LTS"
  1005  	version = "latest"
  1006      }
  1007  
  1008      storage_os_disk {
  1009          name = "myosdisk1"
  1010          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1011          caching = "ReadWrite"
  1012          create_option = "FromImage"
  1013      }
  1014  
  1015      os_profile {
  1016  	computer_name = "hostname%d"
  1017  	admin_username = "testadmin"
  1018  	admin_password = "Password1234!"
  1019      }
  1020  
  1021      os_profile_linux_config {
  1022  	disable_password_authentication = false
  1023      }
  1024  
  1025      tags {
  1026      	environment = "Production"
  1027      }
  1028  }
  1029  `
  1030  
  1031  var testAccAzureRMVirtualMachine_updatedLinuxMachine = `
  1032  resource "azurerm_resource_group" "test" {
  1033      name = "acctestRG-%d"
  1034      location = "West US"
  1035  }
  1036  
  1037  resource "azurerm_virtual_network" "test" {
  1038      name = "acctvn-%d"
  1039      address_space = ["10.0.0.0/16"]
  1040      location = "West US"
  1041      resource_group_name = "${azurerm_resource_group.test.name}"
  1042  }
  1043  
  1044  resource "azurerm_subnet" "test" {
  1045      name = "acctsub-%d"
  1046      resource_group_name = "${azurerm_resource_group.test.name}"
  1047      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1048      address_prefix = "10.0.2.0/24"
  1049  }
  1050  
  1051  resource "azurerm_network_interface" "test" {
  1052      name = "acctni-%d"
  1053      location = "West US"
  1054      resource_group_name = "${azurerm_resource_group.test.name}"
  1055  
  1056      ip_configuration {
  1057      	name = "testconfiguration1"
  1058      	subnet_id = "${azurerm_subnet.test.id}"
  1059      	private_ip_address_allocation = "dynamic"
  1060      }
  1061  }
  1062  
  1063  resource "azurerm_storage_account" "test" {
  1064      name = "accsa%d"
  1065      resource_group_name = "${azurerm_resource_group.test.name}"
  1066      location = "westus"
  1067      account_type = "Standard_LRS"
  1068  
  1069      tags {
  1070          environment = "staging"
  1071      }
  1072  }
  1073  
  1074  resource "azurerm_storage_container" "test" {
  1075      name = "vhds"
  1076      resource_group_name = "${azurerm_resource_group.test.name}"
  1077      storage_account_name = "${azurerm_storage_account.test.name}"
  1078      container_access_type = "private"
  1079  }
  1080  
  1081  resource "azurerm_virtual_machine" "test" {
  1082      name = "acctvm-%d"
  1083      location = "West US"
  1084      resource_group_name = "${azurerm_resource_group.test.name}"
  1085      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1086      vm_size = "Standard_A1"
  1087  
  1088      storage_image_reference {
  1089  	publisher = "Canonical"
  1090  	offer = "UbuntuServer"
  1091  	sku = "14.04.2-LTS"
  1092  	version = "latest"
  1093      }
  1094  
  1095      storage_os_disk {
  1096          name = "myosdisk1"
  1097          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1098          caching = "ReadWrite"
  1099          create_option = "FromImage"
  1100      }
  1101  
  1102      os_profile {
  1103  	computer_name = "hostname%d"
  1104  	admin_username = "testadmin"
  1105  	admin_password = "Password1234!"
  1106      }
  1107  
  1108      os_profile_linux_config {
  1109  	disable_password_authentication = false
  1110      }
  1111  }
  1112  `
  1113  
  1114  var testAccAzureRMVirtualMachine_basicWindowsMachine = `
  1115  resource "azurerm_resource_group" "test" {
  1116      name = "acctestRG-%d"
  1117      location = "West US"
  1118  }
  1119  
  1120  resource "azurerm_virtual_network" "test" {
  1121      name = "acctvn-%d"
  1122      address_space = ["10.0.0.0/16"]
  1123      location = "West US"
  1124      resource_group_name = "${azurerm_resource_group.test.name}"
  1125  }
  1126  
  1127  resource "azurerm_subnet" "test" {
  1128      name = "acctsub-%d"
  1129      resource_group_name = "${azurerm_resource_group.test.name}"
  1130      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1131      address_prefix = "10.0.2.0/24"
  1132  }
  1133  
  1134  resource "azurerm_network_interface" "test" {
  1135      name = "acctni-%d"
  1136      location = "West US"
  1137      resource_group_name = "${azurerm_resource_group.test.name}"
  1138  
  1139      ip_configuration {
  1140      	name = "testconfiguration1"
  1141      	subnet_id = "${azurerm_subnet.test.id}"
  1142      	private_ip_address_allocation = "dynamic"
  1143      }
  1144  }
  1145  
  1146  resource "azurerm_storage_account" "test" {
  1147      name = "accsa%d"
  1148      resource_group_name = "${azurerm_resource_group.test.name}"
  1149      location = "westus"
  1150      account_type = "Standard_LRS"
  1151  
  1152      tags {
  1153          environment = "staging"
  1154      }
  1155  }
  1156  
  1157  resource "azurerm_storage_container" "test" {
  1158      name = "vhds"
  1159      resource_group_name = "${azurerm_resource_group.test.name}"
  1160      storage_account_name = "${azurerm_storage_account.test.name}"
  1161      container_access_type = "private"
  1162  }
  1163  
  1164  resource "azurerm_virtual_machine" "test" {
  1165      name = "acctvm-%d"
  1166      location = "West US"
  1167      resource_group_name = "${azurerm_resource_group.test.name}"
  1168      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1169      vm_size = "Standard_A0"
  1170  
  1171      storage_image_reference {
  1172  	publisher = "MicrosoftWindowsServer"
  1173  	offer = "WindowsServer"
  1174  	sku = "2012-Datacenter"
  1175  	version = "latest"
  1176      }
  1177  
  1178      storage_os_disk {
  1179          name = "myosdisk1"
  1180          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1181          caching = "ReadWrite"
  1182          create_option = "FromImage"
  1183      }
  1184  
  1185      os_profile {
  1186  	computer_name = "winhost01"
  1187  	admin_username = "testadmin"
  1188  	admin_password = "Password1234!"
  1189      }
  1190  
  1191      os_profile_windows_config {
  1192  	enable_automatic_upgrades = false
  1193  	provision_vm_agent = true
  1194      }
  1195  }
  1196  `
  1197  
  1198  var testAccAzureRMVirtualMachine_windowsUnattendedConfig = `
  1199  resource "azurerm_resource_group" "test" {
  1200      name = "acctestRG-%d"
  1201      location = "West US"
  1202  }
  1203  
  1204  resource "azurerm_virtual_network" "test" {
  1205      name = "acctvn-%d"
  1206      address_space = ["10.0.0.0/16"]
  1207      location = "West US"
  1208      resource_group_name = "${azurerm_resource_group.test.name}"
  1209  }
  1210  
  1211  resource "azurerm_subnet" "test" {
  1212      name = "acctsub-%d"
  1213      resource_group_name = "${azurerm_resource_group.test.name}"
  1214      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1215      address_prefix = "10.0.2.0/24"
  1216  }
  1217  
  1218  resource "azurerm_network_interface" "test" {
  1219      name = "acctni-%d"
  1220      location = "West US"
  1221      resource_group_name = "${azurerm_resource_group.test.name}"
  1222  
  1223      ip_configuration {
  1224      	name = "testconfiguration1"
  1225      	subnet_id = "${azurerm_subnet.test.id}"
  1226      	private_ip_address_allocation = "dynamic"
  1227      }
  1228  }
  1229  
  1230  resource "azurerm_storage_account" "test" {
  1231      name = "accsa%d"
  1232      resource_group_name = "${azurerm_resource_group.test.name}"
  1233      location = "westus"
  1234      account_type = "Standard_LRS"
  1235  
  1236      tags {
  1237          environment = "staging"
  1238      }
  1239  }
  1240  
  1241  resource "azurerm_storage_container" "test" {
  1242      name = "vhds"
  1243      resource_group_name = "${azurerm_resource_group.test.name}"
  1244      storage_account_name = "${azurerm_storage_account.test.name}"
  1245      container_access_type = "private"
  1246  }
  1247  
  1248  resource "azurerm_virtual_machine" "test" {
  1249      name = "acctvm-%d"
  1250      location = "West US"
  1251      resource_group_name = "${azurerm_resource_group.test.name}"
  1252      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1253      vm_size = "Standard_A0"
  1254  
  1255      storage_image_reference {
  1256  	publisher = "MicrosoftWindowsServer"
  1257  	offer = "WindowsServer"
  1258  	sku = "2012-Datacenter"
  1259  	version = "latest"
  1260      }
  1261  
  1262      storage_os_disk {
  1263          name = "myosdisk1"
  1264          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1265          caching = "ReadWrite"
  1266          create_option = "FromImage"
  1267      }
  1268  
  1269      os_profile {
  1270  	computer_name = "winhost01"
  1271  	admin_username = "testadmin"
  1272  	admin_password = "Password1234!"
  1273      }
  1274  
  1275      os_profile_windows_config {
  1276          provision_vm_agent = true
  1277          additional_unattend_config {
  1278              pass = "oobeSystem"
  1279              component = "Microsoft-Windows-Shell-Setup"
  1280              setting_name = "FirstLogonCommands"
  1281              content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
  1282          }
  1283      }
  1284  
  1285  }
  1286  `
  1287  
  1288  var testAccAzureRMVirtualMachine_diagnosticsProfile = `
  1289  resource "azurerm_resource_group" "test" {
  1290      name = "acctestRG-%d"
  1291      location = "West US"
  1292  }
  1293  
  1294  resource "azurerm_virtual_network" "test" {
  1295      name = "acctvn-%d"
  1296      address_space = ["10.0.0.0/16"]
  1297      location = "West US"
  1298      resource_group_name = "${azurerm_resource_group.test.name}"
  1299  }
  1300  
  1301  resource "azurerm_subnet" "test" {
  1302      name = "acctsub-%d"
  1303      resource_group_name = "${azurerm_resource_group.test.name}"
  1304      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1305      address_prefix = "10.0.2.0/24"
  1306  }
  1307  
  1308  resource "azurerm_network_interface" "test" {
  1309      name = "acctni-%d"
  1310      location = "West US"
  1311      resource_group_name = "${azurerm_resource_group.test.name}"
  1312  
  1313      ip_configuration {
  1314          name = "testconfiguration1"
  1315          subnet_id = "${azurerm_subnet.test.id}"
  1316          private_ip_address_allocation = "dynamic"
  1317      }
  1318  }
  1319  
  1320  resource "azurerm_storage_account" "test" {
  1321      name = "accsa%d"
  1322      resource_group_name = "${azurerm_resource_group.test.name}"
  1323      location = "westus"
  1324      account_type = "Standard_LRS"
  1325  
  1326      tags {
  1327          environment = "staging"
  1328      }
  1329  }
  1330  
  1331  resource "azurerm_storage_container" "test" {
  1332      name = "vhds"
  1333      resource_group_name = "${azurerm_resource_group.test.name}"
  1334      storage_account_name = "${azurerm_storage_account.test.name}"
  1335      container_access_type = "private"
  1336  }
  1337  
  1338  resource "azurerm_virtual_machine" "test" {
  1339      name = "acctvm-%d"
  1340      location = "West US"
  1341      resource_group_name = "${azurerm_resource_group.test.name}"
  1342      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1343      vm_size = "Standard_A0"
  1344  
  1345      storage_image_reference {
  1346  	publisher = "MicrosoftWindowsServer"
  1347  	offer = "WindowsServer"
  1348  	sku = "2012-Datacenter"
  1349  	version = "latest"
  1350      }
  1351  
  1352      storage_os_disk {
  1353          name = "myosdisk1"
  1354          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1355          caching = "ReadWrite"
  1356          create_option = "FromImage"
  1357      }
  1358  
  1359      os_profile {
  1360  	computer_name = "winhost01"
  1361  	admin_username = "testadmin"
  1362  	admin_password = "Password1234!"
  1363      }
  1364  
  1365      boot_diagnostics {
  1366          enabled = true
  1367          storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}"
  1368      }
  1369  
  1370      os_profile_windows_config {
  1371          winrm {
  1372  	  protocol = "http"
  1373          }
  1374      }
  1375  }
  1376  
  1377  `
  1378  
  1379  var testAccAzureRMVirtualMachine_winRMConfig = `
  1380  resource "azurerm_resource_group" "test" {
  1381      name = "acctestRG-%d"
  1382      location = "West US"
  1383  }
  1384  
  1385  resource "azurerm_virtual_network" "test" {
  1386      name = "acctvn-%d"
  1387      address_space = ["10.0.0.0/16"]
  1388      location = "West US"
  1389      resource_group_name = "${azurerm_resource_group.test.name}"
  1390  }
  1391  
  1392  resource "azurerm_subnet" "test" {
  1393      name = "acctsub-%d"
  1394      resource_group_name = "${azurerm_resource_group.test.name}"
  1395      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1396      address_prefix = "10.0.2.0/24"
  1397  }
  1398  
  1399  resource "azurerm_network_interface" "test" {
  1400      name = "acctni-%d"
  1401      location = "West US"
  1402      resource_group_name = "${azurerm_resource_group.test.name}"
  1403  
  1404      ip_configuration {
  1405      	name = "testconfiguration1"
  1406      	subnet_id = "${azurerm_subnet.test.id}"
  1407      	private_ip_address_allocation = "dynamic"
  1408      }
  1409  }
  1410  
  1411  resource "azurerm_storage_account" "test" {
  1412      name = "accsa%d"
  1413      resource_group_name = "${azurerm_resource_group.test.name}"
  1414      location = "westus"
  1415      account_type = "Standard_LRS"
  1416  
  1417      tags {
  1418          environment = "staging"
  1419      }
  1420  }
  1421  
  1422  resource "azurerm_storage_container" "test" {
  1423      name = "vhds"
  1424      resource_group_name = "${azurerm_resource_group.test.name}"
  1425      storage_account_name = "${azurerm_storage_account.test.name}"
  1426      container_access_type = "private"
  1427  }
  1428  
  1429  resource "azurerm_virtual_machine" "test" {
  1430      name = "acctvm-%d"
  1431      location = "West US"
  1432      resource_group_name = "${azurerm_resource_group.test.name}"
  1433      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1434      vm_size = "Standard_A0"
  1435  
  1436      storage_image_reference {
  1437  	publisher = "MicrosoftWindowsServer"
  1438  	offer = "WindowsServer"
  1439  	sku = "2012-Datacenter"
  1440  	version = "latest"
  1441      }
  1442  
  1443      storage_os_disk {
  1444          name = "myosdisk1"
  1445          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1446          caching = "ReadWrite"
  1447          create_option = "FromImage"
  1448      }
  1449  
  1450      os_profile {
  1451  	computer_name = "winhost01"
  1452  	admin_username = "testadmin"
  1453  	admin_password = "Password1234!"
  1454      }
  1455  
  1456      os_profile_windows_config {
  1457          winrm {
  1458  	  protocol = "http"
  1459          }
  1460      }
  1461  }
  1462  `
  1463  
  1464  var testAccAzureRMVirtualMachine_withAvailabilitySet = `
  1465   resource "azurerm_resource_group" "test" {
  1466       name = "acctestRG-%d"
  1467       location = "West US"
  1468   }
  1469  
  1470   resource "azurerm_virtual_network" "test" {
  1471       name = "acctvn-%d"
  1472       address_space = ["10.0.0.0/16"]
  1473       location = "West US"
  1474       resource_group_name = "${azurerm_resource_group.test.name}"
  1475   }
  1476  
  1477   resource "azurerm_subnet" "test" {
  1478       name = "acctsub-%d"
  1479       resource_group_name = "${azurerm_resource_group.test.name}"
  1480       virtual_network_name = "${azurerm_virtual_network.test.name}"
  1481       address_prefix = "10.0.2.0/24"
  1482   }
  1483  
  1484   resource "azurerm_network_interface" "test" {
  1485       name = "acctni-%d"
  1486       location = "West US"
  1487       resource_group_name = "${azurerm_resource_group.test.name}"
  1488  
  1489       ip_configuration {
  1490       	name = "testconfiguration1"
  1491       	subnet_id = "${azurerm_subnet.test.id}"
  1492       	private_ip_address_allocation = "dynamic"
  1493       }
  1494   }
  1495  
  1496   resource "azurerm_storage_account" "test" {
  1497       name = "accsa%d"
  1498       resource_group_name = "${azurerm_resource_group.test.name}"
  1499       location = "westus"
  1500       account_type = "Standard_LRS"
  1501  
  1502       tags {
  1503           environment = "staging"
  1504       }
  1505   }
  1506  
  1507   resource "azurerm_availability_set" "test" {
  1508      name = "availabilityset%d"
  1509      location = "West US"
  1510      resource_group_name = "${azurerm_resource_group.test.name}"
  1511  }
  1512  
  1513   resource "azurerm_storage_container" "test" {
  1514       name = "vhds"
  1515       resource_group_name = "${azurerm_resource_group.test.name}"
  1516       storage_account_name = "${azurerm_storage_account.test.name}"
  1517       container_access_type = "private"
  1518   }
  1519  
  1520   resource "azurerm_virtual_machine" "test" {
  1521       name = "acctvm-%d"
  1522       location = "West US"
  1523       resource_group_name = "${azurerm_resource_group.test.name}"
  1524       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1525       vm_size = "Standard_A0"
  1526       availability_set_id = "${azurerm_availability_set.test.id}"
  1527       delete_os_disk_on_termination = true
  1528  
  1529       storage_image_reference {
  1530   	publisher = "Canonical"
  1531   	offer = "UbuntuServer"
  1532   	sku = "14.04.2-LTS"
  1533   	version = "latest"
  1534       }
  1535  
  1536       storage_os_disk {
  1537           name = "myosdisk1"
  1538           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1539           caching = "ReadWrite"
  1540           create_option = "FromImage"
  1541       }
  1542  
  1543       os_profile {
  1544   	computer_name = "hostname%d"
  1545   	admin_username = "testadmin"
  1546   	admin_password = "Password1234!"
  1547       }
  1548  
  1549       os_profile_linux_config {
  1550   	disable_password_authentication = false
  1551       }
  1552   }
  1553  `
  1554  
  1555  var testAccAzureRMVirtualMachine_updateAvailabilitySet = `
  1556   resource "azurerm_resource_group" "test" {
  1557       name = "acctestRG-%d"
  1558       location = "West US"
  1559   }
  1560  
  1561   resource "azurerm_virtual_network" "test" {
  1562       name = "acctvn-%d"
  1563       address_space = ["10.0.0.0/16"]
  1564       location = "West US"
  1565       resource_group_name = "${azurerm_resource_group.test.name}"
  1566   }
  1567  
  1568   resource "azurerm_subnet" "test" {
  1569       name = "acctsub-%d"
  1570       resource_group_name = "${azurerm_resource_group.test.name}"
  1571       virtual_network_name = "${azurerm_virtual_network.test.name}"
  1572       address_prefix = "10.0.2.0/24"
  1573   }
  1574  
  1575   resource "azurerm_network_interface" "test" {
  1576       name = "acctni-%d"
  1577       location = "West US"
  1578       resource_group_name = "${azurerm_resource_group.test.name}"
  1579  
  1580       ip_configuration {
  1581       	name = "testconfiguration1"
  1582       	subnet_id = "${azurerm_subnet.test.id}"
  1583       	private_ip_address_allocation = "dynamic"
  1584       }
  1585   }
  1586  
  1587   resource "azurerm_storage_account" "test" {
  1588       name = "accsa%d"
  1589       resource_group_name = "${azurerm_resource_group.test.name}"
  1590       location = "westus"
  1591       account_type = "Standard_LRS"
  1592  
  1593       tags {
  1594           environment = "staging"
  1595       }
  1596   }
  1597  
  1598   resource "azurerm_availability_set" "test" {
  1599      name = "updatedAvailabilitySet%d"
  1600      location = "West US"
  1601      resource_group_name = "${azurerm_resource_group.test.name}"
  1602  }
  1603  
  1604   resource "azurerm_storage_container" "test" {
  1605       name = "vhds"
  1606       resource_group_name = "${azurerm_resource_group.test.name}"
  1607       storage_account_name = "${azurerm_storage_account.test.name}"
  1608       container_access_type = "private"
  1609   }
  1610  
  1611   resource "azurerm_virtual_machine" "test" {
  1612       name = "acctvm-%d"
  1613       location = "West US"
  1614       resource_group_name = "${azurerm_resource_group.test.name}"
  1615       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1616       vm_size = "Standard_A0"
  1617       availability_set_id = "${azurerm_availability_set.test.id}"
  1618       delete_os_disk_on_termination = true
  1619  
  1620       storage_image_reference {
  1621   	publisher = "Canonical"
  1622   	offer = "UbuntuServer"
  1623   	sku = "14.04.2-LTS"
  1624   	version = "latest"
  1625       }
  1626  
  1627       storage_os_disk {
  1628           name = "myosdisk1"
  1629           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1630           caching = "ReadWrite"
  1631           create_option = "FromImage"
  1632       }
  1633  
  1634       os_profile {
  1635   	computer_name = "hostname%d"
  1636   	admin_username = "testadmin"
  1637   	admin_password = "Password1234!"
  1638       }
  1639  
  1640       os_profile_linux_config {
  1641   	disable_password_authentication = false
  1642       }
  1643   }
  1644  `
  1645  
  1646  var testAccAzureRMVirtualMachine_updateMachineName = `
  1647   resource "azurerm_resource_group" "test" {
  1648       name = "acctestRG-%d"
  1649       location = "West US"
  1650   }
  1651  
  1652   resource "azurerm_virtual_network" "test" {
  1653       name = "acctvn-%d"
  1654       address_space = ["10.0.0.0/16"]
  1655       location = "West US"
  1656       resource_group_name = "${azurerm_resource_group.test.name}"
  1657   }
  1658  
  1659   resource "azurerm_subnet" "test" {
  1660       name = "acctsub-%d"
  1661       resource_group_name = "${azurerm_resource_group.test.name}"
  1662       virtual_network_name = "${azurerm_virtual_network.test.name}"
  1663       address_prefix = "10.0.2.0/24"
  1664   }
  1665  
  1666   resource "azurerm_network_interface" "test" {
  1667       name = "acctni-%d"
  1668       location = "West US"
  1669       resource_group_name = "${azurerm_resource_group.test.name}"
  1670  
  1671       ip_configuration {
  1672       	name = "testconfiguration1"
  1673       	subnet_id = "${azurerm_subnet.test.id}"
  1674       	private_ip_address_allocation = "dynamic"
  1675       }
  1676   }
  1677  
  1678   resource "azurerm_storage_account" "test" {
  1679       name = "accsa%d"
  1680       resource_group_name = "${azurerm_resource_group.test.name}"
  1681       location = "westus"
  1682       account_type = "Standard_LRS"
  1683  
  1684       tags {
  1685           environment = "staging"
  1686       }
  1687   }
  1688  
  1689   resource "azurerm_storage_container" "test" {
  1690       name = "vhds"
  1691       resource_group_name = "${azurerm_resource_group.test.name}"
  1692       storage_account_name = "${azurerm_storage_account.test.name}"
  1693       container_access_type = "private"
  1694   }
  1695  
  1696   resource "azurerm_virtual_machine" "test" {
  1697       name = "acctvm-%d"
  1698       location = "West US"
  1699       resource_group_name = "${azurerm_resource_group.test.name}"
  1700       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1701       vm_size = "Standard_A0"
  1702        delete_os_disk_on_termination = true
  1703  
  1704       storage_image_reference {
  1705   	publisher = "Canonical"
  1706   	offer = "UbuntuServer"
  1707   	sku = "14.04.2-LTS"
  1708   	version = "latest"
  1709       }
  1710  
  1711       storage_os_disk {
  1712           name = "myosdisk1"
  1713           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1714           caching = "ReadWrite"
  1715           create_option = "FromImage"
  1716       }
  1717  
  1718       os_profile {
  1719   	computer_name = "newhostname%d"
  1720   	admin_username = "testadmin"
  1721   	admin_password = "Password1234!"
  1722       }
  1723  
  1724       os_profile_linux_config {
  1725   	disable_password_authentication = false
  1726       }
  1727   }
  1728   `