github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/azurerm/resource_arm_virtual_machine_test.go (about)

     1  package azurerm
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/Azure/azure-sdk-for-go/arm/compute"
    10  	"github.com/hashicorp/terraform/helper/acctest"
    11  	"github.com/hashicorp/terraform/helper/resource"
    12  	"github.com/hashicorp/terraform/terraform"
    13  )
    14  
    15  func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) {
    16  	var vm compute.VirtualMachine
    17  	ri := acctest.RandInt()
    18  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    19  	resource.Test(t, resource.TestCase{
    20  		PreCheck:     func() { testAccPreCheck(t) },
    21  		Providers:    testAccProviders,
    22  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    23  		Steps: []resource.TestStep{
    24  			{
    25  				Config: config,
    26  				Check: resource.ComposeTestCheckFunc(
    27  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    28  				),
    29  			},
    30  		},
    31  	})
    32  }
    33  
    34  func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) {
    35  	var vm compute.VirtualMachine
    36  	ri := acctest.RandInt()
    37  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    38  	resource.Test(t, resource.TestCase{
    39  		PreCheck:     func() { testAccPreCheck(t) },
    40  		Providers:    testAccProviders,
    41  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    42  		Steps: []resource.TestStep{
    43  			{
    44  				Config: config,
    45  				Check: resource.ComposeTestCheckFunc(
    46  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    47  					testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test", &vm),
    48  				),
    49  				ExpectNonEmptyPlan: true,
    50  			},
    51  		},
    52  	})
    53  }
    54  
    55  func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) {
    56  	var vm compute.VirtualMachine
    57  
    58  	ri := acctest.RandInt()
    59  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri)
    60  	resource.Test(t, resource.TestCase{
    61  		PreCheck:     func() { testAccPreCheck(t) },
    62  		Providers:    testAccProviders,
    63  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    64  		Steps: []resource.TestStep{
    65  			{
    66  				Config: config,
    67  				Check: resource.ComposeTestCheckFunc(
    68  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    69  				),
    70  			},
    71  		},
    72  	})
    73  }
    74  
    75  func TestAccAzureRMVirtualMachine_tags(t *testing.T) {
    76  	var vm compute.VirtualMachine
    77  
    78  	ri := acctest.RandInt()
    79  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    80  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineUpdated, ri, ri, ri, ri, ri, ri, ri)
    81  	resource.Test(t, resource.TestCase{
    82  		PreCheck:     func() { testAccPreCheck(t) },
    83  		Providers:    testAccProviders,
    84  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    85  		Steps: []resource.TestStep{
    86  			{
    87  				Config: preConfig,
    88  				Check: resource.ComposeTestCheckFunc(
    89  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    90  					resource.TestCheckResourceAttr(
    91  						"azurerm_virtual_machine.test", "tags.%", "2"),
    92  					resource.TestCheckResourceAttr(
    93  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
    94  					resource.TestCheckResourceAttr(
    95  						"azurerm_virtual_machine.test", "tags.cost-center", "Ops"),
    96  				),
    97  			},
    98  
    99  			{
   100  				Config: postConfig,
   101  				Check: resource.ComposeTestCheckFunc(
   102  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   103  					resource.TestCheckResourceAttr(
   104  						"azurerm_virtual_machine.test", "tags.%", "1"),
   105  					resource.TestCheckResourceAttr(
   106  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
   107  				),
   108  			},
   109  		},
   110  	})
   111  }
   112  
   113  //This is a regression test around https://github.com/hashicorp/terraform/issues/6517
   114  //Because we use CreateOrUpdate, we were sending an empty password on update requests
   115  func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) {
   116  	var vm compute.VirtualMachine
   117  
   118  	ri := acctest.RandInt()
   119  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   120  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   121  	resource.Test(t, resource.TestCase{
   122  		PreCheck:     func() { testAccPreCheck(t) },
   123  		Providers:    testAccProviders,
   124  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   125  		Steps: []resource.TestStep{
   126  			{
   127  				Config: preConfig,
   128  				Check: resource.ComposeTestCheckFunc(
   129  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   130  					resource.TestCheckResourceAttr(
   131  						"azurerm_virtual_machine.test", "vm_size", "Standard_A0"),
   132  				),
   133  			},
   134  			{
   135  				Config: postConfig,
   136  				Check: resource.ComposeTestCheckFunc(
   137  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   138  					resource.TestCheckResourceAttr(
   139  						"azurerm_virtual_machine.test", "vm_size", "Standard_A1"),
   140  				),
   141  			},
   142  		},
   143  	})
   144  }
   145  
   146  func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) {
   147  	var vm compute.VirtualMachine
   148  	ri := acctest.RandInt()
   149  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicWindowsMachine, ri, ri, ri, ri, ri, ri)
   150  	resource.Test(t, resource.TestCase{
   151  		PreCheck:     func() { testAccPreCheck(t) },
   152  		Providers:    testAccProviders,
   153  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   154  		Steps: []resource.TestStep{
   155  			{
   156  				Config: config,
   157  				Check: resource.ComposeTestCheckFunc(
   158  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   159  				),
   160  			},
   161  		},
   162  	})
   163  }
   164  
   165  func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) {
   166  	var vm compute.VirtualMachine
   167  	ri := acctest.RandInt()
   168  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsUnattendedConfig, ri, ri, ri, ri, ri, ri)
   169  	resource.Test(t, resource.TestCase{
   170  		PreCheck:     func() { testAccPreCheck(t) },
   171  		Providers:    testAccProviders,
   172  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   173  		Steps: []resource.TestStep{
   174  			{
   175  				Config: config,
   176  				Check: resource.ComposeTestCheckFunc(
   177  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   178  				),
   179  			},
   180  		},
   181  	})
   182  }
   183  
   184  func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) {
   185  	var vm compute.VirtualMachine
   186  	ri := acctest.RandInt()
   187  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_diagnosticsProfile, ri, ri, ri, ri, ri, ri)
   188  	resource.Test(t, resource.TestCase{
   189  		PreCheck:     func() { testAccPreCheck(t) },
   190  		Providers:    testAccProviders,
   191  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   192  		Steps: []resource.TestStep{
   193  			{
   194  				Config: config,
   195  				Check: resource.ComposeTestCheckFunc(
   196  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   197  				),
   198  			},
   199  		},
   200  	})
   201  }
   202  
   203  func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) {
   204  	var vm compute.VirtualMachine
   205  	ri := acctest.RandInt()
   206  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_winRMConfig, ri, ri, ri, ri, ri, ri)
   207  	resource.Test(t, resource.TestCase{
   208  		PreCheck:     func() { testAccPreCheck(t) },
   209  		Providers:    testAccProviders,
   210  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   211  		Steps: []resource.TestStep{
   212  			{
   213  				Config: config,
   214  				Check: resource.ComposeTestCheckFunc(
   215  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   216  				),
   217  			},
   218  		},
   219  	})
   220  }
   221  
   222  func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) {
   223  	var vm compute.VirtualMachine
   224  	ri := acctest.RandInt()
   225  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri)
   226  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM, ri, ri, ri, ri, ri)
   227  	resource.Test(t, resource.TestCase{
   228  		PreCheck:     func() { testAccPreCheck(t) },
   229  		Providers:    testAccProviders,
   230  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   231  		Steps: []resource.TestStep{
   232  			{
   233  				Config: preConfig,
   234  				Check: resource.ComposeTestCheckFunc(
   235  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   236  				),
   237  			},
   238  			{
   239  				Config: postConfig,
   240  				Check: resource.ComposeTestCheckFunc(
   241  					testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", true),
   242  					testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", true),
   243  				),
   244  			},
   245  		},
   246  	})
   247  }
   248  
   249  func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) {
   250  	var vm compute.VirtualMachine
   251  	ri := acctest.RandInt()
   252  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore, ri, ri, ri, ri, ri, ri, ri, ri)
   253  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter, ri, ri, ri, ri, ri, ri)
   254  	resource.Test(t, resource.TestCase{
   255  		PreCheck:     func() { testAccPreCheck(t) },
   256  		Providers:    testAccProviders,
   257  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   258  		Steps: []resource.TestStep{
   259  			{
   260  				Config: preConfig,
   261  				Check: resource.ComposeTestCheckFunc(
   262  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   263  				),
   264  			},
   265  			{
   266  				Config: postConfig,
   267  				Check: resource.ComposeTestCheckFunc(
   268  					testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", false),
   269  					testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", false),
   270  				),
   271  			},
   272  		},
   273  	})
   274  }
   275  
   276  func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) {
   277  	var afterCreate, afterUpdate compute.VirtualMachine
   278  
   279  	ri := acctest.RandInt()
   280  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_machineNameBeforeUpdate, ri, ri, ri, ri, ri, ri, ri)
   281  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateMachineName, ri, ri, ri, ri, ri, ri, ri)
   282  	resource.Test(t, resource.TestCase{
   283  		PreCheck:     func() { testAccPreCheck(t) },
   284  		Providers:    testAccProviders,
   285  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   286  		Steps: []resource.TestStep{
   287  			resource.TestStep{
   288  				Config: preConfig,
   289  				Check: resource.ComposeTestCheckFunc(
   290  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   291  				),
   292  			},
   293  
   294  			resource.TestStep{
   295  				Config: postConfig,
   296  				Check: resource.ComposeTestCheckFunc(
   297  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   298  					testAccCheckVirtualMachineRecreated(
   299  						t, &afterCreate, &afterUpdate),
   300  				),
   301  			},
   302  		},
   303  	})
   304  }
   305  
   306  func TestAccAzureRMVirtualMachine_ChangeAvailbilitySet(t *testing.T) {
   307  	var afterCreate, afterUpdate compute.VirtualMachine
   308  
   309  	ri := acctest.RandInt()
   310  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri)
   311  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri)
   312  	resource.Test(t, resource.TestCase{
   313  		PreCheck:     func() { testAccPreCheck(t) },
   314  		Providers:    testAccProviders,
   315  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   316  		Steps: []resource.TestStep{
   317  			resource.TestStep{
   318  				Config: preConfig,
   319  				Check: resource.ComposeTestCheckFunc(
   320  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   321  				),
   322  			},
   323  
   324  			resource.TestStep{
   325  				Config: postConfig,
   326  				Check: resource.ComposeTestCheckFunc(
   327  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   328  					testAccCheckVirtualMachineRecreated(
   329  						t, &afterCreate, &afterUpdate),
   330  				),
   331  			},
   332  		},
   333  	})
   334  }
   335  
   336  func TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) {
   337  	var afterCreate, afterUpdate compute.VirtualMachine
   338  
   339  	ri := acctest.RandInt()
   340  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore, ri, ri, ri, ri, ri, ri, ri)
   341  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter, ri, ri, ri, ri, ri, ri, ri)
   342  	resource.Test(t, resource.TestCase{
   343  		PreCheck:     func() { testAccPreCheck(t) },
   344  		Providers:    testAccProviders,
   345  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   346  		Steps: []resource.TestStep{
   347  			resource.TestStep{
   348  				Config: preConfig,
   349  				Check: resource.ComposeTestCheckFunc(
   350  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   351  				),
   352  			},
   353  
   354  			resource.TestStep{
   355  				Config: postConfig,
   356  				Check: resource.ComposeTestCheckFunc(
   357  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   358  					testAccCheckVirtualMachineRecreated(
   359  						t, &afterCreate, &afterUpdate),
   360  				),
   361  			},
   362  		},
   363  	})
   364  }
   365  
   366  func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) {
   367  	var afterCreate, afterUpdate compute.VirtualMachine
   368  
   369  	ri := acctest.RandInt()
   370  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   371  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged, ri, ri, ri, ri, ri, ri, ri)
   372  	resource.Test(t, resource.TestCase{
   373  		PreCheck:     func() { testAccPreCheck(t) },
   374  		Providers:    testAccProviders,
   375  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   376  		Steps: []resource.TestStep{
   377  			resource.TestStep{
   378  				Config: preConfig,
   379  				Check: resource.ComposeTestCheckFunc(
   380  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   381  				),
   382  			},
   383  
   384  			resource.TestStep{
   385  				Config: postConfig,
   386  				Check: resource.ComposeTestCheckFunc(
   387  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   388  					testAccCheckVirtualMachineRecreated(
   389  						t, &afterCreate, &afterUpdate),
   390  				),
   391  			},
   392  		},
   393  	})
   394  }
   395  
   396  func TestAccAzureRMVirtualMachine_plan(t *testing.T) {
   397  	var vm compute.VirtualMachine
   398  	ri := acctest.RandInt()
   399  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_plan, ri, ri, ri, ri, ri, ri, ri)
   400  	resource.Test(t, resource.TestCase{
   401  		PreCheck:     func() { testAccPreCheck(t) },
   402  		Providers:    testAccProviders,
   403  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   404  		Steps: []resource.TestStep{
   405  			{
   406  				Config: config,
   407  				Check: resource.ComposeTestCheckFunc(
   408  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   409  				),
   410  			},
   411  		},
   412  	})
   413  }
   414  
   415  func TestAccAzureRMVirtualMachine_changeSSHKey(t *testing.T) {
   416  	var vm compute.VirtualMachine
   417  	ri := strings.ToLower(acctest.RandString(10))
   418  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_linuxMachineWithSSH, ri, ri, ri, ri, ri, ri, ri)
   419  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved, ri, ri, ri, ri, ri, ri, ri)
   420  	resource.Test(t, resource.TestCase{
   421  		PreCheck:     func() { testAccPreCheck(t) },
   422  		Providers:    testAccProviders,
   423  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   424  		Steps: []resource.TestStep{
   425  			{
   426  				Config: preConfig,
   427  				Check: resource.ComposeTestCheckFunc(
   428  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   429  				),
   430  			},
   431  			{
   432  				Config: postConfig,
   433  				Check: resource.ComposeTestCheckFunc(
   434  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   435  				),
   436  			},
   437  		},
   438  	})
   439  }
   440  
   441  func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) resource.TestCheckFunc {
   442  	return func(s *terraform.State) error {
   443  		// Ensure we have enough information in state to look up in API
   444  		rs, ok := s.RootModule().Resources[name]
   445  		if !ok {
   446  			return fmt.Errorf("Not found: %s", name)
   447  		}
   448  
   449  		vmName := rs.Primary.Attributes["name"]
   450  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   451  		if !hasResourceGroup {
   452  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   453  		}
   454  
   455  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   456  
   457  		resp, err := conn.Get(resourceGroup, vmName, "")
   458  		if err != nil {
   459  			return fmt.Errorf("Bad: Get on vmClient: %s", err)
   460  		}
   461  
   462  		if resp.StatusCode == http.StatusNotFound {
   463  			return fmt.Errorf("Bad: VirtualMachine %q (resource group: %q) does not exist", vmName, resourceGroup)
   464  		}
   465  
   466  		*vm = resp
   467  
   468  		return nil
   469  	}
   470  }
   471  
   472  func testAccCheckVirtualMachineRecreated(t *testing.T,
   473  	before, after *compute.VirtualMachine) resource.TestCheckFunc {
   474  	return func(s *terraform.State) error {
   475  		if before.ID == after.ID {
   476  			t.Fatalf("Expected change of Virtual Machine IDs, but both were %v", before.ID)
   477  		}
   478  		return nil
   479  	}
   480  }
   481  
   482  func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error {
   483  	conn := testAccProvider.Meta().(*ArmClient).vmClient
   484  
   485  	for _, rs := range s.RootModule().Resources {
   486  		if rs.Type != "azurerm_virtual_machine" {
   487  			continue
   488  		}
   489  
   490  		name := rs.Primary.Attributes["name"]
   491  		resourceGroup := rs.Primary.Attributes["resource_group_name"]
   492  
   493  		resp, err := conn.Get(resourceGroup, name, "")
   494  
   495  		if err != nil {
   496  			return nil
   497  		}
   498  
   499  		if resp.StatusCode != http.StatusNotFound {
   500  			return fmt.Errorf("Virtual Machine still exists:\n%#v", resp.VirtualMachineProperties)
   501  		}
   502  	}
   503  
   504  	return nil
   505  }
   506  
   507  func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) resource.TestCheckFunc {
   508  	return func(s *terraform.State) error {
   509  		for _, rs := range s.RootModule().Resources {
   510  			if rs.Type != "azurerm_storage_container" {
   511  				continue
   512  			}
   513  
   514  			// fetch storage account and container name
   515  			resourceGroup := rs.Primary.Attributes["resource_group_name"]
   516  			storageAccountName := rs.Primary.Attributes["storage_account_name"]
   517  			containerName := rs.Primary.Attributes["name"]
   518  			storageClient, _, err := testAccProvider.Meta().(*ArmClient).getBlobStorageClientForStorageAccount(resourceGroup, storageAccountName)
   519  			if err != nil {
   520  				return fmt.Errorf("Error creating Blob storage client: %s", err)
   521  			}
   522  
   523  			exists, err := storageClient.BlobExists(containerName, name)
   524  			if err != nil {
   525  				return fmt.Errorf("Error checking if Disk VHD Blob exists: %s", err)
   526  			}
   527  
   528  			if exists && !shouldExist {
   529  				return fmt.Errorf("Disk VHD Blob still exists")
   530  			} else if !exists && shouldExist {
   531  				return fmt.Errorf("Disk VHD Blob should exist")
   532  			}
   533  		}
   534  
   535  		return nil
   536  	}
   537  }
   538  
   539  func testCheckAzureRMVirtualMachineDisappears(name string, vm *compute.VirtualMachine) resource.TestCheckFunc {
   540  	return func(s *terraform.State) error {
   541  		// Ensure we have enough information in state to look up in API
   542  		rs, ok := s.RootModule().Resources[name]
   543  		if !ok {
   544  			return fmt.Errorf("Not found: %s", name)
   545  		}
   546  
   547  		vmName := rs.Primary.Attributes["name"]
   548  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   549  		if !hasResourceGroup {
   550  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   551  		}
   552  
   553  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   554  
   555  		_, err := conn.Delete(resourceGroup, vmName, make(chan struct{}))
   556  		if err != nil {
   557  			return fmt.Errorf("Bad: Delete on vmClient: %s", err)
   558  		}
   559  
   560  		return nil
   561  	}
   562  }
   563  
   564  func TestAccAzureRMVirtualMachine_windowsLicenseType(t *testing.T) {
   565  	var vm compute.VirtualMachine
   566  	ri := acctest.RandInt()
   567  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsLicenseType, ri, ri, ri, ri, ri, ri)
   568  	resource.Test(t, resource.TestCase{
   569  		PreCheck:     func() { testAccPreCheck(t) },
   570  		Providers:    testAccProviders,
   571  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   572  		Steps: []resource.TestStep{
   573  			{
   574  				Config: config,
   575  				Check: resource.ComposeTestCheckFunc(
   576  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   577  				),
   578  			},
   579  		},
   580  	})
   581  }
   582  
   583  var testAccAzureRMVirtualMachine_basicLinuxMachine = `
   584  resource "azurerm_resource_group" "test" {
   585      name = "acctestRG-%d"
   586      location = "West US"
   587  }
   588  
   589  resource "azurerm_virtual_network" "test" {
   590      name = "acctvn-%d"
   591      address_space = ["10.0.0.0/16"]
   592      location = "West US"
   593      resource_group_name = "${azurerm_resource_group.test.name}"
   594  }
   595  
   596  resource "azurerm_subnet" "test" {
   597      name = "acctsub-%d"
   598      resource_group_name = "${azurerm_resource_group.test.name}"
   599      virtual_network_name = "${azurerm_virtual_network.test.name}"
   600      address_prefix = "10.0.2.0/24"
   601  }
   602  
   603  resource "azurerm_network_interface" "test" {
   604      name = "acctni-%d"
   605      location = "West US"
   606      resource_group_name = "${azurerm_resource_group.test.name}"
   607  
   608      ip_configuration {
   609      	name = "testconfiguration1"
   610      	subnet_id = "${azurerm_subnet.test.id}"
   611      	private_ip_address_allocation = "dynamic"
   612      }
   613  }
   614  
   615  resource "azurerm_storage_account" "test" {
   616      name = "accsa%d"
   617      resource_group_name = "${azurerm_resource_group.test.name}"
   618      location = "westus"
   619      account_type = "Standard_LRS"
   620  
   621      tags {
   622          environment = "staging"
   623      }
   624  }
   625  
   626  resource "azurerm_storage_container" "test" {
   627      name = "vhds"
   628      resource_group_name = "${azurerm_resource_group.test.name}"
   629      storage_account_name = "${azurerm_storage_account.test.name}"
   630      container_access_type = "private"
   631  }
   632  
   633  resource "azurerm_virtual_machine" "test" {
   634      name = "acctvm-%d"
   635      location = "West US"
   636      resource_group_name = "${azurerm_resource_group.test.name}"
   637      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   638      vm_size = "Standard_A0"
   639  
   640      storage_image_reference {
   641  	publisher = "Canonical"
   642  	offer = "UbuntuServer"
   643  	sku = "14.04.2-LTS"
   644  	version = "latest"
   645      }
   646  
   647      storage_os_disk {
   648          name = "myosdisk1"
   649          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   650          caching = "ReadWrite"
   651          create_option = "FromImage"
   652          disk_size_gb = "45"
   653      }
   654  
   655      os_profile {
   656  	computer_name = "hostname%d"
   657  	admin_username = "testadmin"
   658  	admin_password = "Password1234!"
   659      }
   660  
   661      os_profile_linux_config {
   662  	disable_password_authentication = false
   663      }
   664  
   665      tags {
   666      	environment = "Production"
   667      	cost-center = "Ops"
   668      }
   669  }
   670  `
   671  
   672  var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = `
   673  resource "azurerm_resource_group" "test" {
   674      name = "acctestRG-%d"
   675      location = "West US"
   676  }
   677  
   678  resource "azurerm_virtual_network" "test" {
   679      name = "acctvn-%d"
   680      address_space = ["10.0.0.0/16"]
   681      location = "West US"
   682      resource_group_name = "${azurerm_resource_group.test.name}"
   683  }
   684  
   685  resource "azurerm_subnet" "test" {
   686      name = "acctsub-%d"
   687      resource_group_name = "${azurerm_resource_group.test.name}"
   688      virtual_network_name = "${azurerm_virtual_network.test.name}"
   689      address_prefix = "10.0.2.0/24"
   690  }
   691  
   692  resource "azurerm_network_interface" "test" {
   693      name = "acctni-%d"
   694      location = "West US"
   695      resource_group_name = "${azurerm_resource_group.test.name}"
   696  
   697      ip_configuration {
   698      	name = "testconfiguration1"
   699      	subnet_id = "${azurerm_subnet.test.id}"
   700      	private_ip_address_allocation = "dynamic"
   701      }
   702  }
   703  
   704  resource "azurerm_storage_account" "test" {
   705      name = "accsa%d"
   706      resource_group_name = "${azurerm_resource_group.test.name}"
   707      location = "westus"
   708      account_type = "Standard_LRS"
   709  
   710      tags {
   711          environment = "staging"
   712      }
   713  }
   714  
   715  resource "azurerm_storage_container" "test" {
   716      name = "vhds"
   717      resource_group_name = "${azurerm_resource_group.test.name}"
   718      storage_account_name = "${azurerm_storage_account.test.name}"
   719      container_access_type = "private"
   720  }
   721  
   722  resource "azurerm_virtual_machine" "test" {
   723      name = "acctvm-%d"
   724      location = "West US"
   725      resource_group_name = "${azurerm_resource_group.test.name}"
   726      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   727      vm_size = "Standard_A0"
   728      delete_os_disk_on_termination = true
   729  
   730      storage_image_reference {
   731  	publisher = "Canonical"
   732  	offer = "UbuntuServer"
   733  	sku = "14.04.2-LTS"
   734  	version = "latest"
   735      }
   736  
   737      storage_os_disk {
   738          name = "myosdisk1"
   739          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   740          caching = "ReadWrite"
   741          create_option = "FromImage"
   742      }
   743  
   744      os_profile {
   745  	computer_name = "hostname%d"
   746  	admin_username = "testadmin"
   747  	admin_password = "Password1234!"
   748      }
   749  
   750      os_profile_linux_config {
   751  	disable_password_authentication = false
   752      }
   753  
   754      tags {
   755      	environment = "Production"
   756      	cost-center = "Ops"
   757      }
   758  }
   759  `
   760  
   761  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore = `
   762  resource "azurerm_resource_group" "test" {
   763      name = "acctestRG-%d"
   764      location = "West US"
   765  }
   766  
   767  resource "azurerm_resource_group" "test-sa" {
   768      name = "acctestRG-sa-%d"
   769      location = "West US"
   770  }
   771  
   772  resource "azurerm_virtual_network" "test" {
   773      name = "acctvn-%d"
   774      address_space = ["10.0.0.0/16"]
   775      location = "West US"
   776      resource_group_name = "${azurerm_resource_group.test.name}"
   777  }
   778  
   779  resource "azurerm_subnet" "test" {
   780      name = "acctsub-%d"
   781      resource_group_name = "${azurerm_resource_group.test.name}"
   782      virtual_network_name = "${azurerm_virtual_network.test.name}"
   783      address_prefix = "10.0.2.0/24"
   784  }
   785  
   786  resource "azurerm_network_interface" "test" {
   787      name = "acctni-%d"
   788      location = "West US"
   789      resource_group_name = "${azurerm_resource_group.test.name}"
   790  
   791      ip_configuration {
   792      	name = "testconfiguration1"
   793      	subnet_id = "${azurerm_subnet.test.id}"
   794      	private_ip_address_allocation = "dynamic"
   795      }
   796  }
   797  
   798  resource "azurerm_storage_account" "test" {
   799      name = "accsa%d"
   800      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   801      location = "westus"
   802      account_type = "Standard_LRS"
   803  
   804      tags {
   805          environment = "staging"
   806      }
   807  }
   808  
   809  resource "azurerm_storage_container" "test" {
   810      name = "vhds"
   811      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   812      storage_account_name = "${azurerm_storage_account.test.name}"
   813      container_access_type = "private"
   814  }
   815  
   816  resource "azurerm_virtual_machine" "test" {
   817      name = "acctvm-%d"
   818      location = "West US"
   819      resource_group_name = "${azurerm_resource_group.test.name}"
   820      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   821      vm_size = "Standard_A0"
   822  
   823      storage_image_reference {
   824  	publisher = "Canonical"
   825  	offer = "UbuntuServer"
   826  	sku = "14.04.2-LTS"
   827  	version = "latest"
   828      }
   829  
   830      storage_os_disk {
   831          name = "myosdisk1"
   832          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   833          caching = "ReadWrite"
   834          create_option = "FromImage"
   835      }
   836  
   837      delete_os_disk_on_termination = true
   838  
   839      storage_data_disk {
   840          name          = "mydatadisk1"
   841          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
   842      	disk_size_gb  = "1023"
   843      	create_option = "Empty"
   844      	lun           = 0
   845      }
   846  
   847      delete_data_disks_on_termination = true
   848  
   849      os_profile {
   850  	computer_name = "hostname%d"
   851  	admin_username = "testadmin"
   852  	admin_password = "Password1234!"
   853      }
   854  
   855      os_profile_linux_config {
   856  	disable_password_authentication = false
   857      }
   858  
   859      tags {
   860      	environment = "Production"
   861      	cost-center = "Ops"
   862      }
   863  }
   864  `
   865  
   866  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter = `
   867  resource "azurerm_resource_group" "test" {
   868      name = "acctestRG-%d"
   869      location = "West US"
   870  }
   871  
   872  resource "azurerm_resource_group" "test-sa" {
   873      name = "acctestRG-sa-%d"
   874      location = "West US"
   875  }
   876  
   877  resource "azurerm_virtual_network" "test" {
   878      name = "acctvn-%d"
   879      address_space = ["10.0.0.0/16"]
   880      location = "West US"
   881      resource_group_name = "${azurerm_resource_group.test.name}"
   882  }
   883  
   884  resource "azurerm_subnet" "test" {
   885      name = "acctsub-%d"
   886      resource_group_name = "${azurerm_resource_group.test.name}"
   887      virtual_network_name = "${azurerm_virtual_network.test.name}"
   888      address_prefix = "10.0.2.0/24"
   889  }
   890  
   891  resource "azurerm_network_interface" "test" {
   892      name = "acctni-%d"
   893      location = "West US"
   894      resource_group_name = "${azurerm_resource_group.test.name}"
   895  
   896      ip_configuration {
   897      	name = "testconfiguration1"
   898      	subnet_id = "${azurerm_subnet.test.id}"
   899      	private_ip_address_allocation = "dynamic"
   900      }
   901  }
   902  
   903  resource "azurerm_storage_account" "test" {
   904      name = "accsa%d"
   905      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   906      location = "westus"
   907      account_type = "Standard_LRS"
   908  
   909      tags {
   910          environment = "staging"
   911      }
   912  }
   913  
   914  resource "azurerm_storage_container" "test" {
   915      name = "vhds"
   916      resource_group_name = "${azurerm_resource_group.test-sa.name}"
   917      storage_account_name = "${azurerm_storage_account.test.name}"
   918      container_access_type = "private"
   919  }
   920  `
   921  
   922  var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = `
   923  resource "azurerm_resource_group" "test" {
   924      name = "acctestRG-%d"
   925      location = "West US"
   926  }
   927  
   928  resource "azurerm_virtual_network" "test" {
   929      name = "acctvn-%d"
   930      address_space = ["10.0.0.0/16"]
   931      location = "West US"
   932      resource_group_name = "${azurerm_resource_group.test.name}"
   933  }
   934  
   935  resource "azurerm_subnet" "test" {
   936      name = "acctsub-%d"
   937      resource_group_name = "${azurerm_resource_group.test.name}"
   938      virtual_network_name = "${azurerm_virtual_network.test.name}"
   939      address_prefix = "10.0.2.0/24"
   940  }
   941  
   942  resource "azurerm_network_interface" "test" {
   943      name = "acctni-%d"
   944      location = "West US"
   945      resource_group_name = "${azurerm_resource_group.test.name}"
   946  
   947      ip_configuration {
   948      	name = "testconfiguration1"
   949      	subnet_id = "${azurerm_subnet.test.id}"
   950      	private_ip_address_allocation = "dynamic"
   951      }
   952  }
   953  
   954  resource "azurerm_storage_account" "test" {
   955      name = "accsa%d"
   956      resource_group_name = "${azurerm_resource_group.test.name}"
   957      location = "westus"
   958      account_type = "Standard_LRS"
   959  
   960      tags {
   961          environment = "staging"
   962      }
   963  }
   964  
   965  resource "azurerm_storage_container" "test" {
   966      name = "vhds"
   967      resource_group_name = "${azurerm_resource_group.test.name}"
   968      storage_account_name = "${azurerm_storage_account.test.name}"
   969      container_access_type = "private"
   970  }
   971  `
   972  
   973  var testAccAzureRMVirtualMachine_withDataDisk = `
   974  resource "azurerm_resource_group" "test" {
   975      name = "acctestRG-%d"
   976      location = "West US"
   977  }
   978  
   979  resource "azurerm_virtual_network" "test" {
   980      name = "acctvn-%d"
   981      address_space = ["10.0.0.0/16"]
   982      location = "West US"
   983      resource_group_name = "${azurerm_resource_group.test.name}"
   984  }
   985  
   986  resource "azurerm_subnet" "test" {
   987      name = "acctsub-%d"
   988      resource_group_name = "${azurerm_resource_group.test.name}"
   989      virtual_network_name = "${azurerm_virtual_network.test.name}"
   990      address_prefix = "10.0.2.0/24"
   991  }
   992  
   993  resource "azurerm_network_interface" "test" {
   994      name = "acctni-%d"
   995      location = "West US"
   996      resource_group_name = "${azurerm_resource_group.test.name}"
   997  
   998      ip_configuration {
   999      	name = "testconfiguration1"
  1000      	subnet_id = "${azurerm_subnet.test.id}"
  1001      	private_ip_address_allocation = "dynamic"
  1002      }
  1003  }
  1004  
  1005  resource "azurerm_storage_account" "test" {
  1006      name = "accsa%d"
  1007      resource_group_name = "${azurerm_resource_group.test.name}"
  1008      location = "westus"
  1009      account_type = "Standard_LRS"
  1010  
  1011      tags {
  1012          environment = "staging"
  1013      }
  1014  }
  1015  
  1016  resource "azurerm_storage_container" "test" {
  1017      name = "vhds"
  1018      resource_group_name = "${azurerm_resource_group.test.name}"
  1019      storage_account_name = "${azurerm_storage_account.test.name}"
  1020      container_access_type = "private"
  1021  }
  1022  
  1023  resource "azurerm_virtual_machine" "test" {
  1024      name = "acctvm-%d"
  1025      location = "West US"
  1026      resource_group_name = "${azurerm_resource_group.test.name}"
  1027      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1028      vm_size = "Standard_A0"
  1029  
  1030      storage_image_reference {
  1031  	publisher = "Canonical"
  1032  	offer = "UbuntuServer"
  1033  	sku = "14.04.2-LTS"
  1034  	version = "latest"
  1035      }
  1036  
  1037      storage_os_disk {
  1038          name = "myosdisk1"
  1039          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1040          caching = "ReadWrite"
  1041          create_option = "FromImage"
  1042      }
  1043  
  1044      storage_data_disk {
  1045          name          = "mydatadisk1"
  1046          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
  1047      	disk_size_gb  = "1023"
  1048      	create_option = "Empty"
  1049          caching       = "ReadWrite"
  1050      	lun           = 0
  1051      }
  1052  
  1053      os_profile {
  1054  	computer_name = "hostname%d"
  1055  	admin_username = "testadmin"
  1056  	admin_password = "Password1234!"
  1057      }
  1058  
  1059      os_profile_linux_config {
  1060  	disable_password_authentication = false
  1061      }
  1062  
  1063      tags {
  1064      	environment = "Production"
  1065      	cost-center = "Ops"
  1066      }
  1067  }
  1068  `
  1069  
  1070  var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = `
  1071  resource "azurerm_resource_group" "test" {
  1072      name = "acctestRG-%d"
  1073      location = "West US"
  1074  }
  1075  
  1076  resource "azurerm_virtual_network" "test" {
  1077      name = "acctvn-%d"
  1078      address_space = ["10.0.0.0/16"]
  1079      location = "West US"
  1080      resource_group_name = "${azurerm_resource_group.test.name}"
  1081  }
  1082  
  1083  resource "azurerm_subnet" "test" {
  1084      name = "acctsub-%d"
  1085      resource_group_name = "${azurerm_resource_group.test.name}"
  1086      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1087      address_prefix = "10.0.2.0/24"
  1088  }
  1089  
  1090  resource "azurerm_network_interface" "test" {
  1091      name = "acctni-%d"
  1092      location = "West US"
  1093      resource_group_name = "${azurerm_resource_group.test.name}"
  1094  
  1095      ip_configuration {
  1096      	name = "testconfiguration1"
  1097      	subnet_id = "${azurerm_subnet.test.id}"
  1098      	private_ip_address_allocation = "dynamic"
  1099      }
  1100  }
  1101  
  1102  resource "azurerm_storage_account" "test" {
  1103      name = "accsa%d"
  1104      resource_group_name = "${azurerm_resource_group.test.name}"
  1105      location = "westus"
  1106      account_type = "Standard_LRS"
  1107  
  1108      tags {
  1109          environment = "staging"
  1110      }
  1111  }
  1112  
  1113  resource "azurerm_storage_container" "test" {
  1114      name = "vhds"
  1115      resource_group_name = "${azurerm_resource_group.test.name}"
  1116      storage_account_name = "${azurerm_storage_account.test.name}"
  1117      container_access_type = "private"
  1118  }
  1119  
  1120  resource "azurerm_virtual_machine" "test" {
  1121      name = "acctvm-%d"
  1122      location = "West US"
  1123      resource_group_name = "${azurerm_resource_group.test.name}"
  1124      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1125      vm_size = "Standard_A0"
  1126  
  1127      storage_image_reference {
  1128  	publisher = "Canonical"
  1129  	offer = "UbuntuServer"
  1130  	sku = "14.04.2-LTS"
  1131  	version = "latest"
  1132      }
  1133  
  1134      storage_os_disk {
  1135          name = "myosdisk1"
  1136          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1137          caching = "ReadWrite"
  1138          create_option = "FromImage"
  1139      }
  1140  
  1141      os_profile {
  1142  	computer_name = "hostname%d"
  1143  	admin_username = "testadmin"
  1144  	admin_password = "Password1234!"
  1145      }
  1146  
  1147      os_profile_linux_config {
  1148  	disable_password_authentication = false
  1149      }
  1150  
  1151      tags {
  1152      	environment = "Production"
  1153      }
  1154  }
  1155  `
  1156  
  1157  var testAccAzureRMVirtualMachine_updatedLinuxMachine = `
  1158  resource "azurerm_resource_group" "test" {
  1159      name = "acctestRG-%d"
  1160      location = "West US"
  1161  }
  1162  
  1163  resource "azurerm_virtual_network" "test" {
  1164      name = "acctvn-%d"
  1165      address_space = ["10.0.0.0/16"]
  1166      location = "West US"
  1167      resource_group_name = "${azurerm_resource_group.test.name}"
  1168  }
  1169  
  1170  resource "azurerm_subnet" "test" {
  1171      name = "acctsub-%d"
  1172      resource_group_name = "${azurerm_resource_group.test.name}"
  1173      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1174      address_prefix = "10.0.2.0/24"
  1175  }
  1176  
  1177  resource "azurerm_network_interface" "test" {
  1178      name = "acctni-%d"
  1179      location = "West US"
  1180      resource_group_name = "${azurerm_resource_group.test.name}"
  1181  
  1182      ip_configuration {
  1183      	name = "testconfiguration1"
  1184      	subnet_id = "${azurerm_subnet.test.id}"
  1185      	private_ip_address_allocation = "dynamic"
  1186      }
  1187  }
  1188  
  1189  resource "azurerm_storage_account" "test" {
  1190      name = "accsa%d"
  1191      resource_group_name = "${azurerm_resource_group.test.name}"
  1192      location = "westus"
  1193      account_type = "Standard_LRS"
  1194  
  1195      tags {
  1196          environment = "staging"
  1197      }
  1198  }
  1199  
  1200  resource "azurerm_storage_container" "test" {
  1201      name = "vhds"
  1202      resource_group_name = "${azurerm_resource_group.test.name}"
  1203      storage_account_name = "${azurerm_storage_account.test.name}"
  1204      container_access_type = "private"
  1205  }
  1206  
  1207  resource "azurerm_virtual_machine" "test" {
  1208      name = "acctvm-%d"
  1209      location = "West US"
  1210      resource_group_name = "${azurerm_resource_group.test.name}"
  1211      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1212      vm_size = "Standard_A1"
  1213  
  1214      storage_image_reference {
  1215  	publisher = "Canonical"
  1216  	offer = "UbuntuServer"
  1217  	sku = "14.04.2-LTS"
  1218  	version = "latest"
  1219      }
  1220  
  1221      storage_os_disk {
  1222          name = "myosdisk1"
  1223          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1224          caching = "ReadWrite"
  1225          create_option = "FromImage"
  1226      }
  1227  
  1228      os_profile {
  1229  	computer_name = "hostname%d"
  1230  	admin_username = "testadmin"
  1231  	admin_password = "Password1234!"
  1232      }
  1233  
  1234      os_profile_linux_config {
  1235  	disable_password_authentication = false
  1236      }
  1237  }
  1238  `
  1239  
  1240  var testAccAzureRMVirtualMachine_basicWindowsMachine = `
  1241  resource "azurerm_resource_group" "test" {
  1242      name = "acctestRG-%d"
  1243      location = "West US"
  1244  }
  1245  
  1246  resource "azurerm_virtual_network" "test" {
  1247      name = "acctvn-%d"
  1248      address_space = ["10.0.0.0/16"]
  1249      location = "West US"
  1250      resource_group_name = "${azurerm_resource_group.test.name}"
  1251  }
  1252  
  1253  resource "azurerm_subnet" "test" {
  1254      name = "acctsub-%d"
  1255      resource_group_name = "${azurerm_resource_group.test.name}"
  1256      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1257      address_prefix = "10.0.2.0/24"
  1258  }
  1259  
  1260  resource "azurerm_network_interface" "test" {
  1261      name = "acctni-%d"
  1262      location = "West US"
  1263      resource_group_name = "${azurerm_resource_group.test.name}"
  1264  
  1265      ip_configuration {
  1266      	name = "testconfiguration1"
  1267      	subnet_id = "${azurerm_subnet.test.id}"
  1268      	private_ip_address_allocation = "dynamic"
  1269      }
  1270  }
  1271  
  1272  resource "azurerm_storage_account" "test" {
  1273      name = "accsa%d"
  1274      resource_group_name = "${azurerm_resource_group.test.name}"
  1275      location = "westus"
  1276      account_type = "Standard_LRS"
  1277  
  1278      tags {
  1279          environment = "staging"
  1280      }
  1281  }
  1282  
  1283  resource "azurerm_storage_container" "test" {
  1284      name = "vhds"
  1285      resource_group_name = "${azurerm_resource_group.test.name}"
  1286      storage_account_name = "${azurerm_storage_account.test.name}"
  1287      container_access_type = "private"
  1288  }
  1289  
  1290  resource "azurerm_virtual_machine" "test" {
  1291      name = "acctvm-%d"
  1292      location = "West US"
  1293      resource_group_name = "${azurerm_resource_group.test.name}"
  1294      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1295      vm_size = "Standard_A0"
  1296  
  1297      storage_image_reference {
  1298  	publisher = "MicrosoftWindowsServer"
  1299  	offer = "WindowsServer"
  1300  	sku = "2012-Datacenter"
  1301  	version = "latest"
  1302      }
  1303  
  1304      storage_os_disk {
  1305          name = "myosdisk1"
  1306          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1307          caching = "ReadWrite"
  1308          create_option = "FromImage"
  1309      }
  1310  
  1311      os_profile {
  1312  	computer_name = "winhost01"
  1313  	admin_username = "testadmin"
  1314  	admin_password = "Password1234!"
  1315      }
  1316  
  1317      os_profile_windows_config {
  1318  	enable_automatic_upgrades = false
  1319  	provision_vm_agent = true
  1320      }
  1321  }
  1322  `
  1323  
  1324  var testAccAzureRMVirtualMachine_windowsUnattendedConfig = `
  1325  resource "azurerm_resource_group" "test" {
  1326      name = "acctestRG-%d"
  1327      location = "West US"
  1328  }
  1329  
  1330  resource "azurerm_virtual_network" "test" {
  1331      name = "acctvn-%d"
  1332      address_space = ["10.0.0.0/16"]
  1333      location = "West US"
  1334      resource_group_name = "${azurerm_resource_group.test.name}"
  1335  }
  1336  
  1337  resource "azurerm_subnet" "test" {
  1338      name = "acctsub-%d"
  1339      resource_group_name = "${azurerm_resource_group.test.name}"
  1340      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1341      address_prefix = "10.0.2.0/24"
  1342  }
  1343  
  1344  resource "azurerm_network_interface" "test" {
  1345      name = "acctni-%d"
  1346      location = "West US"
  1347      resource_group_name = "${azurerm_resource_group.test.name}"
  1348  
  1349      ip_configuration {
  1350      	name = "testconfiguration1"
  1351      	subnet_id = "${azurerm_subnet.test.id}"
  1352      	private_ip_address_allocation = "dynamic"
  1353      }
  1354  }
  1355  
  1356  resource "azurerm_storage_account" "test" {
  1357      name = "accsa%d"
  1358      resource_group_name = "${azurerm_resource_group.test.name}"
  1359      location = "westus"
  1360      account_type = "Standard_LRS"
  1361  
  1362      tags {
  1363          environment = "staging"
  1364      }
  1365  }
  1366  
  1367  resource "azurerm_storage_container" "test" {
  1368      name = "vhds"
  1369      resource_group_name = "${azurerm_resource_group.test.name}"
  1370      storage_account_name = "${azurerm_storage_account.test.name}"
  1371      container_access_type = "private"
  1372  }
  1373  
  1374  resource "azurerm_virtual_machine" "test" {
  1375      name = "acctvm-%d"
  1376      location = "West US"
  1377      resource_group_name = "${azurerm_resource_group.test.name}"
  1378      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1379      vm_size = "Standard_A0"
  1380  
  1381      storage_image_reference {
  1382  	publisher = "MicrosoftWindowsServer"
  1383  	offer = "WindowsServer"
  1384  	sku = "2012-Datacenter"
  1385  	version = "latest"
  1386      }
  1387  
  1388      storage_os_disk {
  1389          name = "myosdisk1"
  1390          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1391          caching = "ReadWrite"
  1392          create_option = "FromImage"
  1393      }
  1394  
  1395      os_profile {
  1396  	computer_name = "winhost01"
  1397  	admin_username = "testadmin"
  1398  	admin_password = "Password1234!"
  1399      }
  1400  
  1401      os_profile_windows_config {
  1402          provision_vm_agent = true
  1403          additional_unattend_config {
  1404              pass = "oobeSystem"
  1405              component = "Microsoft-Windows-Shell-Setup"
  1406              setting_name = "FirstLogonCommands"
  1407              content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
  1408          }
  1409      }
  1410  
  1411  }
  1412  `
  1413  
  1414  var testAccAzureRMVirtualMachine_diagnosticsProfile = `
  1415  resource "azurerm_resource_group" "test" {
  1416      name = "acctestRG-%d"
  1417      location = "West US"
  1418  }
  1419  
  1420  resource "azurerm_virtual_network" "test" {
  1421      name = "acctvn-%d"
  1422      address_space = ["10.0.0.0/16"]
  1423      location = "West US"
  1424      resource_group_name = "${azurerm_resource_group.test.name}"
  1425  }
  1426  
  1427  resource "azurerm_subnet" "test" {
  1428      name = "acctsub-%d"
  1429      resource_group_name = "${azurerm_resource_group.test.name}"
  1430      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1431      address_prefix = "10.0.2.0/24"
  1432  }
  1433  
  1434  resource "azurerm_network_interface" "test" {
  1435      name = "acctni-%d"
  1436      location = "West US"
  1437      resource_group_name = "${azurerm_resource_group.test.name}"
  1438  
  1439      ip_configuration {
  1440          name = "testconfiguration1"
  1441          subnet_id = "${azurerm_subnet.test.id}"
  1442          private_ip_address_allocation = "dynamic"
  1443      }
  1444  }
  1445  
  1446  resource "azurerm_storage_account" "test" {
  1447      name = "accsa%d"
  1448      resource_group_name = "${azurerm_resource_group.test.name}"
  1449      location = "westus"
  1450      account_type = "Standard_LRS"
  1451  
  1452      tags {
  1453          environment = "staging"
  1454      }
  1455  }
  1456  
  1457  resource "azurerm_storage_container" "test" {
  1458      name = "vhds"
  1459      resource_group_name = "${azurerm_resource_group.test.name}"
  1460      storage_account_name = "${azurerm_storage_account.test.name}"
  1461      container_access_type = "private"
  1462  }
  1463  
  1464  resource "azurerm_virtual_machine" "test" {
  1465      name = "acctvm-%d"
  1466      location = "West US"
  1467      resource_group_name = "${azurerm_resource_group.test.name}"
  1468      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1469      vm_size = "Standard_A0"
  1470  
  1471      storage_image_reference {
  1472  	publisher = "MicrosoftWindowsServer"
  1473  	offer = "WindowsServer"
  1474  	sku = "2012-Datacenter"
  1475  	version = "latest"
  1476      }
  1477  
  1478      storage_os_disk {
  1479          name = "myosdisk1"
  1480          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1481          caching = "ReadWrite"
  1482          create_option = "FromImage"
  1483      }
  1484  
  1485      os_profile {
  1486  	computer_name = "winhost01"
  1487  	admin_username = "testadmin"
  1488  	admin_password = "Password1234!"
  1489      }
  1490  
  1491      boot_diagnostics {
  1492          enabled = true
  1493          storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}"
  1494      }
  1495  
  1496      os_profile_windows_config {
  1497          winrm {
  1498  	  protocol = "http"
  1499          }
  1500      }
  1501  }
  1502  
  1503  `
  1504  
  1505  var testAccAzureRMVirtualMachine_winRMConfig = `
  1506  resource "azurerm_resource_group" "test" {
  1507      name = "acctestRG-%d"
  1508      location = "West US"
  1509  }
  1510  
  1511  resource "azurerm_virtual_network" "test" {
  1512      name = "acctvn-%d"
  1513      address_space = ["10.0.0.0/16"]
  1514      location = "West US"
  1515      resource_group_name = "${azurerm_resource_group.test.name}"
  1516  }
  1517  
  1518  resource "azurerm_subnet" "test" {
  1519      name = "acctsub-%d"
  1520      resource_group_name = "${azurerm_resource_group.test.name}"
  1521      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1522      address_prefix = "10.0.2.0/24"
  1523  }
  1524  
  1525  resource "azurerm_network_interface" "test" {
  1526      name = "acctni-%d"
  1527      location = "West US"
  1528      resource_group_name = "${azurerm_resource_group.test.name}"
  1529  
  1530      ip_configuration {
  1531      	name = "testconfiguration1"
  1532      	subnet_id = "${azurerm_subnet.test.id}"
  1533      	private_ip_address_allocation = "dynamic"
  1534      }
  1535  }
  1536  
  1537  resource "azurerm_storage_account" "test" {
  1538      name = "accsa%d"
  1539      resource_group_name = "${azurerm_resource_group.test.name}"
  1540      location = "westus"
  1541      account_type = "Standard_LRS"
  1542  
  1543      tags {
  1544          environment = "staging"
  1545      }
  1546  }
  1547  
  1548  resource "azurerm_storage_container" "test" {
  1549      name = "vhds"
  1550      resource_group_name = "${azurerm_resource_group.test.name}"
  1551      storage_account_name = "${azurerm_storage_account.test.name}"
  1552      container_access_type = "private"
  1553  }
  1554  
  1555  resource "azurerm_virtual_machine" "test" {
  1556      name = "acctvm-%d"
  1557      location = "West US"
  1558      resource_group_name = "${azurerm_resource_group.test.name}"
  1559      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1560      vm_size = "Standard_A0"
  1561  
  1562      storage_image_reference {
  1563  	publisher = "MicrosoftWindowsServer"
  1564  	offer = "WindowsServer"
  1565  	sku = "2012-Datacenter"
  1566  	version = "latest"
  1567      }
  1568  
  1569      storage_os_disk {
  1570          name = "myosdisk1"
  1571          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1572          caching = "ReadWrite"
  1573          create_option = "FromImage"
  1574      }
  1575  
  1576      os_profile {
  1577  	computer_name = "winhost01"
  1578  	admin_username = "testadmin"
  1579  	admin_password = "Password1234!"
  1580      }
  1581  
  1582      os_profile_windows_config {
  1583          winrm {
  1584  	  protocol = "http"
  1585          }
  1586      }
  1587  }
  1588  `
  1589  
  1590  var testAccAzureRMVirtualMachine_withAvailabilitySet = `
  1591   resource "azurerm_resource_group" "test" {
  1592       name = "acctestRG-%d"
  1593       location = "West US"
  1594   }
  1595  
  1596   resource "azurerm_virtual_network" "test" {
  1597       name = "acctvn-%d"
  1598       address_space = ["10.0.0.0/16"]
  1599       location = "West US"
  1600       resource_group_name = "${azurerm_resource_group.test.name}"
  1601   }
  1602  
  1603   resource "azurerm_subnet" "test" {
  1604       name = "acctsub-%d"
  1605       resource_group_name = "${azurerm_resource_group.test.name}"
  1606       virtual_network_name = "${azurerm_virtual_network.test.name}"
  1607       address_prefix = "10.0.2.0/24"
  1608   }
  1609  
  1610   resource "azurerm_network_interface" "test" {
  1611       name = "acctni-%d"
  1612       location = "West US"
  1613       resource_group_name = "${azurerm_resource_group.test.name}"
  1614  
  1615       ip_configuration {
  1616       	name = "testconfiguration1"
  1617       	subnet_id = "${azurerm_subnet.test.id}"
  1618       	private_ip_address_allocation = "dynamic"
  1619       }
  1620   }
  1621  
  1622   resource "azurerm_storage_account" "test" {
  1623       name = "accsa%d"
  1624       resource_group_name = "${azurerm_resource_group.test.name}"
  1625       location = "westus"
  1626       account_type = "Standard_LRS"
  1627  
  1628       tags {
  1629           environment = "staging"
  1630       }
  1631   }
  1632  
  1633   resource "azurerm_availability_set" "test" {
  1634      name = "availabilityset%d"
  1635      location = "West US"
  1636      resource_group_name = "${azurerm_resource_group.test.name}"
  1637  }
  1638  
  1639   resource "azurerm_storage_container" "test" {
  1640       name = "vhds"
  1641       resource_group_name = "${azurerm_resource_group.test.name}"
  1642       storage_account_name = "${azurerm_storage_account.test.name}"
  1643       container_access_type = "private"
  1644   }
  1645  
  1646   resource "azurerm_virtual_machine" "test" {
  1647       name = "acctvm-%d"
  1648       location = "West US"
  1649       resource_group_name = "${azurerm_resource_group.test.name}"
  1650       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1651       vm_size = "Standard_A0"
  1652       availability_set_id = "${azurerm_availability_set.test.id}"
  1653       delete_os_disk_on_termination = true
  1654  
  1655       storage_image_reference {
  1656   	publisher = "Canonical"
  1657   	offer = "UbuntuServer"
  1658   	sku = "14.04.2-LTS"
  1659   	version = "latest"
  1660       }
  1661  
  1662       storage_os_disk {
  1663           name = "myosdisk1"
  1664           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1665           caching = "ReadWrite"
  1666           create_option = "FromImage"
  1667       }
  1668  
  1669       os_profile {
  1670   	computer_name = "hostname%d"
  1671   	admin_username = "testadmin"
  1672   	admin_password = "Password1234!"
  1673       }
  1674  
  1675       os_profile_linux_config {
  1676   	disable_password_authentication = false
  1677       }
  1678   }
  1679  `
  1680  
  1681  var testAccAzureRMVirtualMachine_updateAvailabilitySet = `
  1682   resource "azurerm_resource_group" "test" {
  1683       name = "acctestRG-%d"
  1684       location = "West US"
  1685   }
  1686  
  1687   resource "azurerm_virtual_network" "test" {
  1688       name = "acctvn-%d"
  1689       address_space = ["10.0.0.0/16"]
  1690       location = "West US"
  1691       resource_group_name = "${azurerm_resource_group.test.name}"
  1692   }
  1693  
  1694   resource "azurerm_subnet" "test" {
  1695       name = "acctsub-%d"
  1696       resource_group_name = "${azurerm_resource_group.test.name}"
  1697       virtual_network_name = "${azurerm_virtual_network.test.name}"
  1698       address_prefix = "10.0.2.0/24"
  1699   }
  1700  
  1701   resource "azurerm_network_interface" "test" {
  1702       name = "acctni-%d"
  1703       location = "West US"
  1704       resource_group_name = "${azurerm_resource_group.test.name}"
  1705  
  1706       ip_configuration {
  1707       	name = "testconfiguration1"
  1708       	subnet_id = "${azurerm_subnet.test.id}"
  1709       	private_ip_address_allocation = "dynamic"
  1710       }
  1711   }
  1712  
  1713   resource "azurerm_storage_account" "test" {
  1714       name = "accsa%d"
  1715       resource_group_name = "${azurerm_resource_group.test.name}"
  1716       location = "westus"
  1717       account_type = "Standard_LRS"
  1718  
  1719       tags {
  1720           environment = "staging"
  1721       }
  1722   }
  1723  
  1724   resource "azurerm_availability_set" "test" {
  1725      name = "updatedAvailabilitySet%d"
  1726      location = "West US"
  1727      resource_group_name = "${azurerm_resource_group.test.name}"
  1728  }
  1729  
  1730   resource "azurerm_storage_container" "test" {
  1731       name = "vhds"
  1732       resource_group_name = "${azurerm_resource_group.test.name}"
  1733       storage_account_name = "${azurerm_storage_account.test.name}"
  1734       container_access_type = "private"
  1735   }
  1736  
  1737   resource "azurerm_virtual_machine" "test" {
  1738       name = "acctvm-%d"
  1739       location = "West US"
  1740       resource_group_name = "${azurerm_resource_group.test.name}"
  1741       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1742       vm_size = "Standard_A0"
  1743       availability_set_id = "${azurerm_availability_set.test.id}"
  1744       delete_os_disk_on_termination = true
  1745  
  1746       storage_image_reference {
  1747   	publisher = "Canonical"
  1748   	offer = "UbuntuServer"
  1749   	sku = "14.04.2-LTS"
  1750   	version = "latest"
  1751       }
  1752  
  1753       storage_os_disk {
  1754           name = "myosdisk1"
  1755           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1756           caching = "ReadWrite"
  1757           create_option = "FromImage"
  1758       }
  1759  
  1760       os_profile {
  1761   	computer_name = "hostname%d"
  1762   	admin_username = "testadmin"
  1763   	admin_password = "Password1234!"
  1764       }
  1765  
  1766       os_profile_linux_config {
  1767   	disable_password_authentication = false
  1768       }
  1769   }
  1770  `
  1771  
  1772  var testAccAzureRMVirtualMachine_updateMachineName = `
  1773   resource "azurerm_resource_group" "test" {
  1774       name = "acctestRG-%d"
  1775       location = "West US"
  1776   }
  1777  
  1778   resource "azurerm_virtual_network" "test" {
  1779       name = "acctvn-%d"
  1780       address_space = ["10.0.0.0/16"]
  1781       location = "West US"
  1782       resource_group_name = "${azurerm_resource_group.test.name}"
  1783   }
  1784  
  1785   resource "azurerm_subnet" "test" {
  1786       name = "acctsub-%d"
  1787       resource_group_name = "${azurerm_resource_group.test.name}"
  1788       virtual_network_name = "${azurerm_virtual_network.test.name}"
  1789       address_prefix = "10.0.2.0/24"
  1790   }
  1791  
  1792   resource "azurerm_network_interface" "test" {
  1793       name = "acctni-%d"
  1794       location = "West US"
  1795       resource_group_name = "${azurerm_resource_group.test.name}"
  1796  
  1797       ip_configuration {
  1798       	name = "testconfiguration1"
  1799       	subnet_id = "${azurerm_subnet.test.id}"
  1800       	private_ip_address_allocation = "dynamic"
  1801       }
  1802   }
  1803  
  1804   resource "azurerm_storage_account" "test" {
  1805       name = "accsa%d"
  1806       resource_group_name = "${azurerm_resource_group.test.name}"
  1807       location = "westus"
  1808       account_type = "Standard_LRS"
  1809  
  1810       tags {
  1811           environment = "staging"
  1812       }
  1813   }
  1814  
  1815   resource "azurerm_storage_container" "test" {
  1816       name = "vhds"
  1817       resource_group_name = "${azurerm_resource_group.test.name}"
  1818       storage_account_name = "${azurerm_storage_account.test.name}"
  1819       container_access_type = "private"
  1820   }
  1821  
  1822   resource "azurerm_virtual_machine" "test" {
  1823       name = "acctvm-%d"
  1824       location = "West US"
  1825       resource_group_name = "${azurerm_resource_group.test.name}"
  1826       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1827       vm_size = "Standard_A0"
  1828        delete_os_disk_on_termination = true
  1829  
  1830       storage_image_reference {
  1831   	publisher = "Canonical"
  1832   	offer = "UbuntuServer"
  1833   	sku = "14.04.2-LTS"
  1834   	version = "latest"
  1835       }
  1836  
  1837       storage_os_disk {
  1838           name = "myosdisk1"
  1839           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1840           caching = "ReadWrite"
  1841           create_option = "FromImage"
  1842       }
  1843  
  1844       os_profile {
  1845   	computer_name = "newhostname%d"
  1846   	admin_username = "testadmin"
  1847   	admin_password = "Password1234!"
  1848       }
  1849  
  1850       os_profile_linux_config {
  1851   	disable_password_authentication = false
  1852       }
  1853   }
  1854   `
  1855  
  1856  var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore = `
  1857  resource "azurerm_resource_group" "test" {
  1858      name = "acctestRG-%d"
  1859      location = "West US"
  1860  }
  1861  
  1862  resource "azurerm_virtual_network" "test" {
  1863      name = "acctvn-%d"
  1864      address_space = ["10.0.0.0/16"]
  1865      location = "West US"
  1866      resource_group_name = "${azurerm_resource_group.test.name}"
  1867  }
  1868  
  1869  resource "azurerm_subnet" "test" {
  1870      name = "acctsub-%d"
  1871      resource_group_name = "${azurerm_resource_group.test.name}"
  1872      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1873      address_prefix = "10.0.2.0/24"
  1874  }
  1875  
  1876  resource "azurerm_network_interface" "test" {
  1877      name = "acctni-%d"
  1878      location = "West US"
  1879      resource_group_name = "${azurerm_resource_group.test.name}"
  1880  
  1881      ip_configuration {
  1882      	name = "testconfiguration1"
  1883      	subnet_id = "${azurerm_subnet.test.id}"
  1884      	private_ip_address_allocation = "dynamic"
  1885      }
  1886  }
  1887  
  1888  resource "azurerm_storage_account" "test" {
  1889      name = "accsa%d"
  1890      resource_group_name = "${azurerm_resource_group.test.name}"
  1891      location = "westus"
  1892      account_type = "Standard_LRS"
  1893  
  1894      tags {
  1895          environment = "staging"
  1896      }
  1897  }
  1898  
  1899  resource "azurerm_storage_container" "test" {
  1900      name = "vhds"
  1901      resource_group_name = "${azurerm_resource_group.test.name}"
  1902      storage_account_name = "${azurerm_storage_account.test.name}"
  1903      container_access_type = "private"
  1904  }
  1905  
  1906  resource "azurerm_virtual_machine" "test" {
  1907      name = "acctvm-%d"
  1908      location = "West US"
  1909      resource_group_name = "${azurerm_resource_group.test.name}"
  1910      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1911      vm_size = "Standard_A0"
  1912      delete_os_disk_on_termination = true
  1913  
  1914      storage_image_reference {
  1915  	publisher = "Canonical"
  1916  	offer = "UbuntuServer"
  1917  	sku = "14.04.2-LTS"
  1918  	version = "latest"
  1919      }
  1920  
  1921      storage_os_disk {
  1922          name = "myosdisk1"
  1923          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1924          caching = "ReadWrite"
  1925          create_option = "FromImage"
  1926          disk_size_gb = "45"
  1927      }
  1928  
  1929      os_profile {
  1930  	computer_name = "hostname%d"
  1931  	admin_username = "testadmin"
  1932  	admin_password = "Password1234!"
  1933      }
  1934  
  1935      os_profile_linux_config {
  1936  	disable_password_authentication = false
  1937      }
  1938  
  1939      tags {
  1940      	environment = "Production"
  1941      	cost-center = "Ops"
  1942      }
  1943  }
  1944  `
  1945  
  1946  var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter = `
  1947  resource "azurerm_resource_group" "test" {
  1948      name = "acctestRG-%d"
  1949      location = "West US"
  1950  }
  1951  
  1952  resource "azurerm_virtual_network" "test" {
  1953      name = "acctvn-%d"
  1954      address_space = ["10.0.0.0/16"]
  1955      location = "West US"
  1956      resource_group_name = "${azurerm_resource_group.test.name}"
  1957  }
  1958  
  1959  resource "azurerm_subnet" "test" {
  1960      name = "acctsub-%d"
  1961      resource_group_name = "${azurerm_resource_group.test.name}"
  1962      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1963      address_prefix = "10.0.2.0/24"
  1964  }
  1965  
  1966  resource "azurerm_network_interface" "test" {
  1967      name = "acctni-%d"
  1968      location = "West US"
  1969      resource_group_name = "${azurerm_resource_group.test.name}"
  1970  
  1971      ip_configuration {
  1972      	name = "testconfiguration1"
  1973      	subnet_id = "${azurerm_subnet.test.id}"
  1974      	private_ip_address_allocation = "dynamic"
  1975      }
  1976  }
  1977  
  1978  resource "azurerm_storage_account" "test" {
  1979      name = "accsa%d"
  1980      resource_group_name = "${azurerm_resource_group.test.name}"
  1981      location = "westus"
  1982      account_type = "Standard_LRS"
  1983  
  1984      tags {
  1985          environment = "staging"
  1986      }
  1987  }
  1988  
  1989  resource "azurerm_storage_container" "test" {
  1990      name = "vhds"
  1991      resource_group_name = "${azurerm_resource_group.test.name}"
  1992      storage_account_name = "${azurerm_storage_account.test.name}"
  1993      container_access_type = "private"
  1994  }
  1995  
  1996  resource "azurerm_virtual_machine" "test" {
  1997      name = "acctvm-%d"
  1998      location = "West US"
  1999      resource_group_name = "${azurerm_resource_group.test.name}"
  2000      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2001      vm_size = "Standard_A0"
  2002      delete_os_disk_on_termination = true
  2003  
  2004      storage_image_reference {
  2005  	publisher = "CoreOS"
  2006  	offer = "CoreOS"
  2007  	sku = "Stable"
  2008  	version = "latest"
  2009      }
  2010  
  2011      storage_os_disk {
  2012          name = "myosdisk1"
  2013          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2014          caching = "ReadWrite"
  2015          create_option = "FromImage"
  2016          disk_size_gb = "45"
  2017      }
  2018  
  2019      os_profile {
  2020  	computer_name = "hostname%d"
  2021  	admin_username = "testadmin"
  2022  	admin_password = "Password1234!"
  2023      }
  2024  
  2025      os_profile_linux_config {
  2026  	disable_password_authentication = false
  2027      }
  2028  
  2029      tags {
  2030      	environment = "Production"
  2031      	cost-center = "Ops"
  2032      }
  2033  }
  2034  `
  2035  
  2036  var testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged = `
  2037  resource "azurerm_resource_group" "test" {
  2038      name = "acctestRG-%d"
  2039      location = "West US"
  2040  }
  2041  
  2042  resource "azurerm_virtual_network" "test" {
  2043      name = "acctvn-%d"
  2044      address_space = ["10.0.0.0/16"]
  2045      location = "West US"
  2046      resource_group_name = "${azurerm_resource_group.test.name}"
  2047  }
  2048  
  2049  resource "azurerm_subnet" "test" {
  2050      name = "acctsub-%d"
  2051      resource_group_name = "${azurerm_resource_group.test.name}"
  2052      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2053      address_prefix = "10.0.2.0/24"
  2054  }
  2055  
  2056  resource "azurerm_network_interface" "test" {
  2057      name = "acctni-%d"
  2058      location = "West US"
  2059      resource_group_name = "${azurerm_resource_group.test.name}"
  2060  
  2061      ip_configuration {
  2062      	name = "testconfiguration1"
  2063      	subnet_id = "${azurerm_subnet.test.id}"
  2064      	private_ip_address_allocation = "dynamic"
  2065      }
  2066  }
  2067  
  2068  resource "azurerm_storage_account" "test" {
  2069      name = "accsa%d"
  2070      resource_group_name = "${azurerm_resource_group.test.name}"
  2071      location = "westus"
  2072      account_type = "Standard_LRS"
  2073  
  2074      tags {
  2075          environment = "staging"
  2076      }
  2077  }
  2078  
  2079  resource "azurerm_storage_container" "test" {
  2080      name = "vhds"
  2081      resource_group_name = "${azurerm_resource_group.test.name}"
  2082      storage_account_name = "${azurerm_storage_account.test.name}"
  2083      container_access_type = "private"
  2084  }
  2085  
  2086  resource "azurerm_virtual_machine" "test" {
  2087      name = "acctvm-%d"
  2088      location = "West US"
  2089      resource_group_name = "${azurerm_resource_group.test.name}"
  2090      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2091      vm_size = "Standard_A0"
  2092  
  2093      storage_image_reference {
  2094  	publisher = "Canonical"
  2095  	offer = "UbuntuServer"
  2096  	sku = "14.04.2-LTS"
  2097  	version = "latest"
  2098      }
  2099  
  2100      storage_os_disk {
  2101          name = "myosdisk1"
  2102          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdiskchanged2.vhd"
  2103          caching = "ReadWrite"
  2104          create_option = "FromImage"
  2105          disk_size_gb = "45"
  2106      }
  2107  
  2108      os_profile {
  2109  	computer_name = "hostname%d"
  2110  	admin_username = "testadmin"
  2111  	admin_password = "Password1234!"
  2112      }
  2113  
  2114      os_profile_linux_config {
  2115  	disable_password_authentication = false
  2116      }
  2117  
  2118      tags {
  2119      	environment = "Production"
  2120      	cost-center = "Ops"
  2121      }
  2122  }
  2123  `
  2124  
  2125  var testAccAzureRMVirtualMachine_windowsLicenseType = `
  2126  resource "azurerm_resource_group" "test" {
  2127      name = "acctestRG-%d"
  2128      location = "West US"
  2129  }
  2130  
  2131  resource "azurerm_virtual_network" "test" {
  2132      name = "acctvn-%d"
  2133      address_space = ["10.0.0.0/16"]
  2134      location = "West US"
  2135      resource_group_name = "${azurerm_resource_group.test.name}"
  2136  }
  2137  
  2138  resource "azurerm_subnet" "test" {
  2139      name = "acctsub-%d"
  2140      resource_group_name = "${azurerm_resource_group.test.name}"
  2141      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2142      address_prefix = "10.0.2.0/24"
  2143  }
  2144  
  2145  resource "azurerm_network_interface" "test" {
  2146      name = "acctni-%d"
  2147      location = "West US"
  2148      resource_group_name = "${azurerm_resource_group.test.name}"
  2149  
  2150      ip_configuration {
  2151      	name = "testconfiguration1"
  2152      	subnet_id = "${azurerm_subnet.test.id}"
  2153      	private_ip_address_allocation = "dynamic"
  2154      }
  2155  }
  2156  
  2157  resource "azurerm_storage_account" "test" {
  2158      name = "accsa%d"
  2159      resource_group_name = "${azurerm_resource_group.test.name}"
  2160      location = "westus"
  2161      account_type = "Standard_LRS"
  2162  
  2163      tags {
  2164          environment = "staging"
  2165      }
  2166  }
  2167  
  2168  resource "azurerm_storage_container" "test" {
  2169      name = "vhds"
  2170      resource_group_name = "${azurerm_resource_group.test.name}"
  2171      storage_account_name = "${azurerm_storage_account.test.name}"
  2172      container_access_type = "private"
  2173  }
  2174  
  2175  resource "azurerm_virtual_machine" "test" {
  2176      name = "acctvm-%d"
  2177      location = "West US"
  2178      resource_group_name = "${azurerm_resource_group.test.name}"
  2179      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2180      vm_size = "Standard_A0"
  2181      license_type = "Windows_Server"
  2182  
  2183      storage_image_reference {
  2184  	publisher = "MicrosoftWindowsServer"
  2185  	offer = "WindowsServer-HUB"
  2186  	sku = "2008-R2-SP1-HUB"
  2187  	version = "latest"
  2188      }
  2189  
  2190      storage_os_disk {
  2191          name = "myosdisk1"
  2192          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2193          caching = "ReadWrite"
  2194          create_option = "FromImage"
  2195      }
  2196  
  2197      os_profile {
  2198  	computer_name = "winhost01"
  2199  	admin_username = "testadmin"
  2200  	admin_password = "Password1234!"
  2201      }
  2202  
  2203      os_profile_windows_config {
  2204  	enable_automatic_upgrades = false
  2205  	provision_vm_agent = true
  2206      }
  2207  }
  2208  `
  2209  
  2210  var testAccAzureRMVirtualMachine_plan = `
  2211  resource "azurerm_resource_group" "test" {
  2212      name = "acctestRG-%d"
  2213      location = "West US"
  2214  }
  2215  
  2216  resource "azurerm_virtual_network" "test" {
  2217      name = "acctvn-%d"
  2218      address_space = ["10.0.0.0/16"]
  2219      location = "West US"
  2220      resource_group_name = "${azurerm_resource_group.test.name}"
  2221  }
  2222  
  2223  resource "azurerm_subnet" "test" {
  2224      name = "acctsub-%d"
  2225      resource_group_name = "${azurerm_resource_group.test.name}"
  2226      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2227      address_prefix = "10.0.2.0/24"
  2228  }
  2229  
  2230  resource "azurerm_network_interface" "test" {
  2231      name = "acctni-%d"
  2232      location = "West US"
  2233      resource_group_name = "${azurerm_resource_group.test.name}"
  2234  
  2235      ip_configuration {
  2236      	name = "testconfiguration1"
  2237      	subnet_id = "${azurerm_subnet.test.id}"
  2238      	private_ip_address_allocation = "dynamic"
  2239      }
  2240  }
  2241  
  2242  resource "azurerm_storage_account" "test" {
  2243      name = "accsa%d"
  2244      resource_group_name = "${azurerm_resource_group.test.name}"
  2245      location = "westus"
  2246      account_type = "Standard_LRS"
  2247  
  2248      tags {
  2249          environment = "staging"
  2250      }
  2251  }
  2252  
  2253  resource "azurerm_storage_container" "test" {
  2254      name = "vhds"
  2255      resource_group_name = "${azurerm_resource_group.test.name}"
  2256      storage_account_name = "${azurerm_storage_account.test.name}"
  2257      container_access_type = "private"
  2258  }
  2259  
  2260  resource "azurerm_virtual_machine" "test" {
  2261      name = "acctvm-%d"
  2262      location = "West US"
  2263      resource_group_name = "${azurerm_resource_group.test.name}"
  2264      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2265      vm_size = "Standard_DS1_v2"
  2266  
  2267      storage_image_reference {
  2268  	publisher = "kemptech"
  2269  	offer = "vlm-azure"
  2270  	sku = "freeloadmaster"
  2271  	version = "latest"
  2272      }
  2273  
  2274      storage_os_disk {
  2275          name = "myosdisk1"
  2276          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2277          caching = "ReadWrite"
  2278          create_option = "FromImage"
  2279          disk_size_gb = "45"
  2280      }
  2281  
  2282      os_profile {
  2283  	computer_name = "hostname%d"
  2284  	admin_username = "testadmin"
  2285  	admin_password = "Password1234!"
  2286      }
  2287  
  2288      os_profile_linux_config {
  2289  	disable_password_authentication = false
  2290      }
  2291  
  2292      plan {
  2293          name = "freeloadmaster"
  2294          publisher = "kemptech"
  2295          product = "vlm-azure"
  2296      }
  2297  
  2298      tags {
  2299      	environment = "Production"
  2300      	cost-center = "Ops"
  2301      }
  2302  }
  2303  `
  2304  
  2305  var testAccAzureRMVirtualMachine_linuxMachineWithSSH = `
  2306  resource "azurerm_resource_group" "test" {
  2307      name = "acctestrg%s"
  2308      location = "southcentralus"
  2309  }
  2310  
  2311  resource "azurerm_virtual_network" "test" {
  2312      name = "acctvn%s"
  2313      address_space = ["10.0.0.0/16"]
  2314      location = "southcentralus"
  2315      resource_group_name = "${azurerm_resource_group.test.name}"
  2316  }
  2317  
  2318  resource "azurerm_subnet" "test" {
  2319      name = "acctsub%s"
  2320      resource_group_name = "${azurerm_resource_group.test.name}"
  2321      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2322      address_prefix = "10.0.2.0/24"
  2323  }
  2324  
  2325  resource "azurerm_network_interface" "test" {
  2326      name = "acctni%s"
  2327      location = "southcentralus"
  2328      resource_group_name = "${azurerm_resource_group.test.name}"
  2329  
  2330      ip_configuration {
  2331      	name = "testconfiguration1"
  2332      	subnet_id = "${azurerm_subnet.test.id}"
  2333      	private_ip_address_allocation = "dynamic"
  2334      }
  2335  }
  2336  
  2337  resource "azurerm_storage_account" "test" {
  2338      name = "accsa%s"
  2339      resource_group_name = "${azurerm_resource_group.test.name}"
  2340      location = "southcentralus"
  2341      account_type = "Standard_LRS"
  2342  }
  2343  
  2344  resource "azurerm_storage_container" "test" {
  2345      name = "vhds"
  2346      resource_group_name = "${azurerm_resource_group.test.name}"
  2347      storage_account_name = "${azurerm_storage_account.test.name}"
  2348      container_access_type = "private"
  2349  }
  2350  
  2351  resource "azurerm_virtual_machine" "test" {
  2352      name = "acctvm%s"
  2353      location = "southcentralus"
  2354      resource_group_name = "${azurerm_resource_group.test.name}"
  2355      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2356      vm_size = "Standard_A0"
  2357  
  2358      storage_image_reference {
  2359          publisher = "Canonical"
  2360          offer = "UbuntuServer"
  2361          sku = "14.04.2-LTS"
  2362          version = "latest"
  2363      }
  2364  
  2365      storage_os_disk {
  2366          name = "myosdisk1"
  2367          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2368          caching = "ReadWrite"
  2369          create_option = "FromImage"
  2370          disk_size_gb = "45"
  2371      }
  2372  
  2373      os_profile {
  2374          computer_name = "hostname%s"
  2375          admin_username = "testadmin"
  2376          admin_password = "Password1234!"
  2377      }
  2378  
  2379      os_profile_linux_config {
  2380  	    disable_password_authentication = true
  2381          ssh_keys {
  2382              path = "/home/testadmin/.ssh/authorized_keys"
  2383              key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCfGyt5W1eJVpDIxlyvAWO594j/azEGohmlxYe7mgSfmUCWjuzILI6nHuHbxhpBDIZJhQ+JAeduXpii61dmThbI89ghGMhzea0OlT3p12e093zqa4goB9g40jdNKmJArER3pMVqs6hmv8y3GlUNkMDSmuoyI8AYzX4n26cUKZbwXQ== mk@mk3"
  2384          }
  2385      }
  2386  }
  2387  `
  2388  
  2389  var testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved = `
  2390  resource "azurerm_resource_group" "test" {
  2391      name = "acctestrg%s"
  2392      location = "southcentralus"
  2393  }
  2394  
  2395  resource "azurerm_virtual_network" "test" {
  2396      name = "acctvn%s"
  2397      address_space = ["10.0.0.0/16"]
  2398      location = "southcentralus"
  2399      resource_group_name = "${azurerm_resource_group.test.name}"
  2400  }
  2401  
  2402  resource "azurerm_subnet" "test" {
  2403      name = "acctsub%s"
  2404      resource_group_name = "${azurerm_resource_group.test.name}"
  2405      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2406      address_prefix = "10.0.2.0/24"
  2407  }
  2408  
  2409  resource "azurerm_network_interface" "test" {
  2410      name = "acctni%s"
  2411      location = "southcentralus"
  2412      resource_group_name = "${azurerm_resource_group.test.name}"
  2413  
  2414      ip_configuration {
  2415      	name = "testconfiguration1"
  2416      	subnet_id = "${azurerm_subnet.test.id}"
  2417      	private_ip_address_allocation = "dynamic"
  2418      }
  2419  }
  2420  
  2421  resource "azurerm_storage_account" "test" {
  2422      name = "accsa%s"
  2423      resource_group_name = "${azurerm_resource_group.test.name}"
  2424      location = "southcentralus"
  2425      account_type = "Standard_LRS"
  2426  }
  2427  
  2428  resource "azurerm_storage_container" "test" {
  2429      name = "vhds"
  2430      resource_group_name = "${azurerm_resource_group.test.name}"
  2431      storage_account_name = "${azurerm_storage_account.test.name}"
  2432      container_access_type = "private"
  2433  }
  2434  
  2435  resource "azurerm_virtual_machine" "test" {
  2436      name = "acctvm%s"
  2437      location = "southcentralus"
  2438      resource_group_name = "${azurerm_resource_group.test.name}"
  2439      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2440      vm_size = "Standard_A0"
  2441  
  2442      storage_image_reference {
  2443          publisher = "Canonical"
  2444          offer = "UbuntuServer"
  2445          sku = "14.04.2-LTS"
  2446          version = "latest"
  2447      }
  2448  
  2449      storage_os_disk {
  2450          name = "myosdisk1"
  2451          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2452          caching = "ReadWrite"
  2453          create_option = "FromImage"
  2454          disk_size_gb = "45"
  2455      }
  2456  
  2457      os_profile {
  2458          computer_name = "hostname%s"
  2459          admin_username = "testadmin"
  2460          admin_password = "Password1234!"
  2461      }
  2462  
  2463      os_profile_linux_config {
  2464  	    disable_password_authentication = true
  2465      }
  2466  }
  2467  `