github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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/Azure/azure-sdk-for-go/arm/disk"
    11  	"github.com/hashicorp/terraform/helper/acctest"
    12  	"github.com/hashicorp/terraform/helper/resource"
    13  	"github.com/hashicorp/terraform/terraform"
    14  	"regexp"
    15  )
    16  
    17  func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) {
    18  	var vm compute.VirtualMachine
    19  	ri := acctest.RandInt()
    20  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    21  	resource.Test(t, resource.TestCase{
    22  		PreCheck:     func() { testAccPreCheck(t) },
    23  		Providers:    testAccProviders,
    24  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    25  		Steps: []resource.TestStep{
    26  			{
    27  				Config: config,
    28  				Check: resource.ComposeTestCheckFunc(
    29  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    30  				),
    31  			},
    32  		},
    33  	})
    34  }
    35  
    36  func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(t *testing.T) {
    37  	var vm compute.VirtualMachine
    38  	ri := acctest.RandInt()
    39  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit, ri, ri, ri, ri, ri, ri, ri)
    40  	resource.Test(t, resource.TestCase{
    41  		PreCheck:     func() { testAccPreCheck(t) },
    42  		Providers:    testAccProviders,
    43  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    44  		Steps: []resource.TestStep{
    45  			{
    46  				Config: config,
    47  				Check: resource.ComposeTestCheckFunc(
    48  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    49  				),
    50  			},
    51  		},
    52  	})
    53  }
    54  
    55  func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(t *testing.T) {
    56  	var vm compute.VirtualMachine
    57  	ri := acctest.RandInt()
    58  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit, 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_basicLinuxMachine_managedDisk_attach(t *testing.T) {
    75  	var vm compute.VirtualMachine
    76  	ri := acctest.RandInt()
    77  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach, ri, ri, ri, ri, ri, ri, ri, ri)
    78  	resource.Test(t, resource.TestCase{
    79  		PreCheck:     func() { testAccPreCheck(t) },
    80  		Providers:    testAccProviders,
    81  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    82  		Steps: []resource.TestStep{
    83  			{
    84  				Config: config,
    85  				Check: resource.ComposeTestCheckFunc(
    86  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
    87  				),
    88  			},
    89  		},
    90  	})
    91  }
    92  
    93  func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) {
    94  	var vm compute.VirtualMachine
    95  	ri := acctest.RandInt()
    96  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    97  	resource.Test(t, resource.TestCase{
    98  		PreCheck:     func() { testAccPreCheck(t) },
    99  		Providers:    testAccProviders,
   100  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   101  		Steps: []resource.TestStep{
   102  			{
   103  				Config: config,
   104  				Check: resource.ComposeTestCheckFunc(
   105  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   106  					testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test"),
   107  				),
   108  				ExpectNonEmptyPlan: true,
   109  			},
   110  		},
   111  	})
   112  }
   113  
   114  func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) {
   115  	var vm compute.VirtualMachine
   116  
   117  	ri := acctest.RandInt()
   118  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri)
   119  	resource.Test(t, resource.TestCase{
   120  		PreCheck:     func() { testAccPreCheck(t) },
   121  		Providers:    testAccProviders,
   122  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   123  		Steps: []resource.TestStep{
   124  			{
   125  				Config: config,
   126  				Check: resource.ComposeTestCheckFunc(
   127  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   128  				),
   129  			},
   130  		},
   131  	})
   132  }
   133  
   134  func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(t *testing.T) {
   135  	var vm compute.VirtualMachine
   136  
   137  	ri := acctest.RandInt()
   138  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit, ri, ri, ri, ri, ri, ri, ri, ri)
   139  	resource.Test(t, resource.TestCase{
   140  		PreCheck:     func() { testAccPreCheck(t) },
   141  		Providers:    testAccProviders,
   142  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   143  		Steps: []resource.TestStep{
   144  			{
   145  				Config: config,
   146  				Check: resource.ComposeTestCheckFunc(
   147  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   148  				),
   149  			},
   150  		},
   151  	})
   152  }
   153  
   154  func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(t *testing.T) {
   155  	var vm compute.VirtualMachine
   156  
   157  	ri := acctest.RandInt()
   158  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit, ri, ri, ri, ri, ri, ri)
   159  	resource.Test(t, resource.TestCase{
   160  		PreCheck:     func() { testAccPreCheck(t) },
   161  		Providers:    testAccProviders,
   162  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   163  		Steps: []resource.TestStep{
   164  			{
   165  				Config: config,
   166  				Check: resource.ComposeTestCheckFunc(
   167  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   168  				),
   169  			},
   170  		},
   171  	})
   172  }
   173  
   174  func TestAccAzureRMVirtualMachine_tags(t *testing.T) {
   175  	var vm compute.VirtualMachine
   176  
   177  	ri := acctest.RandInt()
   178  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   179  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineUpdated, ri, ri, ri, ri, ri, ri, ri)
   180  	resource.Test(t, resource.TestCase{
   181  		PreCheck:     func() { testAccPreCheck(t) },
   182  		Providers:    testAccProviders,
   183  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   184  		Steps: []resource.TestStep{
   185  			{
   186  				Config: preConfig,
   187  				Check: resource.ComposeTestCheckFunc(
   188  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   189  					resource.TestCheckResourceAttr(
   190  						"azurerm_virtual_machine.test", "tags.%", "2"),
   191  					resource.TestCheckResourceAttr(
   192  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
   193  					resource.TestCheckResourceAttr(
   194  						"azurerm_virtual_machine.test", "tags.cost-center", "Ops"),
   195  				),
   196  			},
   197  
   198  			{
   199  				Config: postConfig,
   200  				Check: resource.ComposeTestCheckFunc(
   201  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   202  					resource.TestCheckResourceAttr(
   203  						"azurerm_virtual_machine.test", "tags.%", "1"),
   204  					resource.TestCheckResourceAttr(
   205  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
   206  				),
   207  			},
   208  		},
   209  	})
   210  }
   211  
   212  //This is a regression test around https://github.com/hashicorp/terraform/issues/6517
   213  //Because we use CreateOrUpdate, we were sending an empty password on update requests
   214  func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) {
   215  	var vm compute.VirtualMachine
   216  
   217  	ri := acctest.RandInt()
   218  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   219  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   220  	resource.Test(t, resource.TestCase{
   221  		PreCheck:     func() { testAccPreCheck(t) },
   222  		Providers:    testAccProviders,
   223  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   224  		Steps: []resource.TestStep{
   225  			{
   226  				Config: preConfig,
   227  				Check: resource.ComposeTestCheckFunc(
   228  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   229  					resource.TestCheckResourceAttr(
   230  						"azurerm_virtual_machine.test", "vm_size", "Standard_D1_v2"),
   231  				),
   232  			},
   233  			{
   234  				Config: postConfig,
   235  				Check: resource.ComposeTestCheckFunc(
   236  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   237  					resource.TestCheckResourceAttr(
   238  						"azurerm_virtual_machine.test", "vm_size", "Standard_D2_v2"),
   239  				),
   240  			},
   241  		},
   242  	})
   243  }
   244  
   245  func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) {
   246  	var vm compute.VirtualMachine
   247  	ri := acctest.RandInt()
   248  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicWindowsMachine, ri, ri, ri, ri, ri, ri)
   249  	resource.Test(t, resource.TestCase{
   250  		PreCheck:     func() { testAccPreCheck(t) },
   251  		Providers:    testAccProviders,
   252  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   253  		Steps: []resource.TestStep{
   254  			{
   255  				Config: config,
   256  				Check: resource.ComposeTestCheckFunc(
   257  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   258  				),
   259  			},
   260  		},
   261  	})
   262  }
   263  
   264  func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) {
   265  	var vm compute.VirtualMachine
   266  	ri := acctest.RandInt()
   267  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsUnattendedConfig, ri, ri, ri, ri, ri, ri)
   268  	resource.Test(t, resource.TestCase{
   269  		PreCheck:     func() { testAccPreCheck(t) },
   270  		Providers:    testAccProviders,
   271  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   272  		Steps: []resource.TestStep{
   273  			{
   274  				Config: config,
   275  				Check: resource.ComposeTestCheckFunc(
   276  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   277  				),
   278  			},
   279  		},
   280  	})
   281  }
   282  
   283  func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) {
   284  	var vm compute.VirtualMachine
   285  	ri := acctest.RandInt()
   286  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_diagnosticsProfile, ri, ri, ri, ri, ri, ri)
   287  	resource.Test(t, resource.TestCase{
   288  		PreCheck:     func() { testAccPreCheck(t) },
   289  		Providers:    testAccProviders,
   290  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   291  		Steps: []resource.TestStep{
   292  			{
   293  				Config: config,
   294  				Check: resource.ComposeTestCheckFunc(
   295  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   296  				),
   297  			},
   298  		},
   299  	})
   300  }
   301  
   302  func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) {
   303  	var vm compute.VirtualMachine
   304  	ri := acctest.RandInt()
   305  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_winRMConfig, ri, ri, ri, ri, ri, ri)
   306  	resource.Test(t, resource.TestCase{
   307  		PreCheck:     func() { testAccPreCheck(t) },
   308  		Providers:    testAccProviders,
   309  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   310  		Steps: []resource.TestStep{
   311  			{
   312  				Config: config,
   313  				Check: resource.ComposeTestCheckFunc(
   314  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   315  				),
   316  			},
   317  		},
   318  	})
   319  }
   320  
   321  func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) {
   322  	var vm compute.VirtualMachine
   323  	ri := acctest.RandInt()
   324  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri)
   325  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM, ri, ri, ri, ri, ri)
   326  	resource.Test(t, resource.TestCase{
   327  		PreCheck:     func() { testAccPreCheck(t) },
   328  		Providers:    testAccProviders,
   329  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   330  		Steps: []resource.TestStep{
   331  			{
   332  				Config: preConfig,
   333  				Check: resource.ComposeTestCheckFunc(
   334  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   335  				),
   336  			},
   337  			{
   338  				Config: postConfig,
   339  				Check: resource.ComposeTestCheckFunc(
   340  					testCheckAzureRMVirtualMachineVHDExistence("myosdisk1.vhd", true),
   341  					testCheckAzureRMVirtualMachineVHDExistence("mydatadisk1.vhd", true),
   342  				),
   343  			},
   344  		},
   345  	})
   346  }
   347  
   348  func TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut(t *testing.T) {
   349  	var vm compute.VirtualMachine
   350  	var osd string
   351  	var dtd string
   352  	ri := acctest.RandInt()
   353  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit, ri, ri, ri, ri, ri, ri)
   354  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk, ri, ri, ri, ri)
   355  	resource.Test(t, resource.TestCase{
   356  		PreCheck:     func() { testAccPreCheck(t) },
   357  		Providers:    testAccProviders,
   358  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   359  		Steps: []resource.TestStep{
   360  			{
   361  				Destroy: false,
   362  				Config:  preConfig,
   363  				Check: resource.ComposeTestCheckFunc(
   364  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   365  					testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd),
   366  					testLookupAzureRMVirtualMachineManagedDiskID(&vm, "mydatadisk1", &dtd),
   367  				),
   368  			},
   369  			{
   370  				Config: postConfig,
   371  				Check: resource.ComposeTestCheckFunc(
   372  					testCheckAzureRMVirtualMachineManagedDiskExists(&osd, true),
   373  					testCheckAzureRMVirtualMachineManagedDiskExists(&dtd, true),
   374  				),
   375  			},
   376  		},
   377  	})
   378  }
   379  
   380  func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) {
   381  	var vm compute.VirtualMachine
   382  	ri := acctest.RandInt()
   383  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore, ri, ri, ri, ri, ri, ri, ri, ri)
   384  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter, ri, ri, ri, ri, ri, ri)
   385  	resource.Test(t, resource.TestCase{
   386  		PreCheck:     func() { testAccPreCheck(t) },
   387  		Providers:    testAccProviders,
   388  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   389  		Steps: []resource.TestStep{
   390  			{
   391  				Config: preConfig,
   392  				Check: resource.ComposeTestCheckFunc(
   393  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   394  				),
   395  			},
   396  			{
   397  				Config: postConfig,
   398  				Check: resource.ComposeTestCheckFunc(
   399  					testCheckAzureRMVirtualMachineVHDExistence("myosdisk1.vhd", false),
   400  					testCheckAzureRMVirtualMachineVHDExistence("mydatadisk1.vhd", false),
   401  				),
   402  			},
   403  		},
   404  	})
   405  }
   406  
   407  func TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn(t *testing.T) {
   408  	var vm compute.VirtualMachine
   409  	var osd string
   410  	var dtd string
   411  	ri := acctest.RandInt()
   412  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore, ri, ri, ri, ri, ri, ri)
   413  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter, ri, ri, ri, ri)
   414  	resource.Test(t, resource.TestCase{
   415  		PreCheck:     func() { testAccPreCheck(t) },
   416  		Providers:    testAccProviders,
   417  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   418  		Steps: []resource.TestStep{
   419  			{
   420  				Destroy: false,
   421  				Config:  preConfig,
   422  				Check: resource.ComposeTestCheckFunc(
   423  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   424  					testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd),
   425  					testLookupAzureRMVirtualMachineManagedDiskID(&vm, "mydatadisk1", &dtd),
   426  				),
   427  			},
   428  			{
   429  				Config: postConfig,
   430  				Check: resource.ComposeTestCheckFunc(
   431  					testCheckAzureRMVirtualMachineManagedDiskExists(&osd, false),
   432  					testCheckAzureRMVirtualMachineManagedDiskExists(&dtd, false),
   433  				),
   434  			},
   435  		},
   436  	})
   437  }
   438  
   439  func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) {
   440  	var afterCreate, afterUpdate compute.VirtualMachine
   441  
   442  	ri := acctest.RandInt()
   443  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_machineNameBeforeUpdate, ri, ri, ri, ri, ri, ri, ri)
   444  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateMachineName, ri, ri, ri, ri, ri, ri, ri)
   445  	resource.Test(t, resource.TestCase{
   446  		PreCheck:     func() { testAccPreCheck(t) },
   447  		Providers:    testAccProviders,
   448  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   449  		Steps: []resource.TestStep{
   450  			{
   451  				Config: preConfig,
   452  				Check: resource.ComposeTestCheckFunc(
   453  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   454  				),
   455  			},
   456  
   457  			{
   458  				Config: postConfig,
   459  				Check: resource.ComposeTestCheckFunc(
   460  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   461  					testAccCheckVirtualMachineRecreated(
   462  						t, &afterCreate, &afterUpdate),
   463  				),
   464  			},
   465  		},
   466  	})
   467  }
   468  
   469  func TestAccAzureRMVirtualMachine_ChangeAvailabilitySet(t *testing.T) {
   470  	var afterCreate, afterUpdate compute.VirtualMachine
   471  
   472  	ri := acctest.RandInt()
   473  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri)
   474  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri)
   475  	resource.Test(t, resource.TestCase{
   476  		PreCheck:     func() { testAccPreCheck(t) },
   477  		Providers:    testAccProviders,
   478  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   479  		Steps: []resource.TestStep{
   480  			{
   481  				Config: preConfig,
   482  				Check: resource.ComposeTestCheckFunc(
   483  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   484  				),
   485  			},
   486  
   487  			{
   488  				Config: postConfig,
   489  				Check: resource.ComposeTestCheckFunc(
   490  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   491  					testAccCheckVirtualMachineRecreated(
   492  						t, &afterCreate, &afterUpdate),
   493  				),
   494  			},
   495  		},
   496  	})
   497  }
   498  
   499  func TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) {
   500  	var afterCreate, afterUpdate compute.VirtualMachine
   501  
   502  	ri := acctest.RandInt()
   503  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore, ri, ri, ri, ri, ri, ri, ri)
   504  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter, ri, ri, ri, ri, ri, ri, ri)
   505  	resource.Test(t, resource.TestCase{
   506  		PreCheck:     func() { testAccPreCheck(t) },
   507  		Providers:    testAccProviders,
   508  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   509  		Steps: []resource.TestStep{
   510  			{
   511  				Config: preConfig,
   512  				Check: resource.ComposeTestCheckFunc(
   513  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   514  				),
   515  			},
   516  
   517  			{
   518  				Config: postConfig,
   519  				Check: resource.ComposeTestCheckFunc(
   520  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   521  					testAccCheckVirtualMachineRecreated(
   522  						t, &afterCreate, &afterUpdate),
   523  				),
   524  			},
   525  		},
   526  	})
   527  }
   528  
   529  func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) {
   530  	var afterCreate, afterUpdate compute.VirtualMachine
   531  
   532  	ri := acctest.RandInt()
   533  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   534  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged, ri, ri, ri, ri, ri, ri, ri)
   535  	resource.Test(t, resource.TestCase{
   536  		PreCheck:     func() { testAccPreCheck(t) },
   537  		Providers:    testAccProviders,
   538  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   539  		Steps: []resource.TestStep{
   540  			{
   541  				Config: preConfig,
   542  				Check: resource.ComposeTestCheckFunc(
   543  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate),
   544  				),
   545  			},
   546  
   547  			{
   548  				Config: postConfig,
   549  				Check: resource.ComposeTestCheckFunc(
   550  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate),
   551  					testAccCheckVirtualMachineRecreated(
   552  						t, &afterCreate, &afterUpdate),
   553  				),
   554  			},
   555  		},
   556  	})
   557  }
   558  
   559  func TestAccAzureRMVirtualMachine_plan(t *testing.T) {
   560  	var vm compute.VirtualMachine
   561  	ri := acctest.RandInt()
   562  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_plan, ri, ri, ri, ri, ri, ri, ri)
   563  	resource.Test(t, resource.TestCase{
   564  		PreCheck:     func() { testAccPreCheck(t) },
   565  		Providers:    testAccProviders,
   566  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   567  		Steps: []resource.TestStep{
   568  			{
   569  				Config: config,
   570  				Check: resource.ComposeTestCheckFunc(
   571  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   572  				),
   573  			},
   574  		},
   575  	})
   576  }
   577  
   578  func TestAccAzureRMVirtualMachine_changeSSHKey(t *testing.T) {
   579  	var vm compute.VirtualMachine
   580  	ri := strings.ToLower(acctest.RandString(10))
   581  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_linuxMachineWithSSH, ri, ri, ri, ri, ri, ri, ri)
   582  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved, ri, ri, ri, ri, ri, ri, ri)
   583  	resource.Test(t, resource.TestCase{
   584  		PreCheck:     func() { testAccPreCheck(t) },
   585  		Providers:    testAccProviders,
   586  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   587  		Steps: []resource.TestStep{
   588  			{
   589  				Config: preConfig,
   590  				Check: resource.ComposeTestCheckFunc(
   591  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   592  				),
   593  			},
   594  			{
   595  				Config: postConfig,
   596  				Check: resource.ComposeTestCheckFunc(
   597  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   598  				),
   599  			},
   600  		},
   601  	})
   602  }
   603  
   604  func TestAccAzureRMVirtualMachine_osDiskTypeConflict(t *testing.T) {
   605  	ri := acctest.RandInt()
   606  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_osDiskTypeConflict, ri, ri, ri, ri, ri, ri, ri)
   607  	resource.Test(t, resource.TestCase{
   608  		PreCheck:     func() { testAccPreCheck(t) },
   609  		Providers:    testAccProviders,
   610  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   611  		Steps: []resource.TestStep{
   612  			{
   613  				Config:      config,
   614  				ExpectError: regexp.MustCompile("Conflict between `vhd_uri`"),
   615  				//Use below code instead once GH-13019 has been merged
   616  				//ExpectError: regexp.MustCompile("conflicts with storage_os_disk.0.vhd_uri"),
   617  			},
   618  		},
   619  	})
   620  }
   621  
   622  func TestAccAzureRMVirtualMachine_dataDiskTypeConflict(t *testing.T) {
   623  	ri := acctest.RandInt()
   624  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_dataDiskTypeConflict, ri, ri, ri, ri, ri, ri, ri)
   625  	resource.Test(t, resource.TestCase{
   626  		PreCheck:     func() { testAccPreCheck(t) },
   627  		Providers:    testAccProviders,
   628  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   629  		Steps: []resource.TestStep{
   630  			{
   631  				Config:      config,
   632  				ExpectError: regexp.MustCompile("Conflict between `vhd_uri`"),
   633  				//Use below code instead once GH-13019 has been merged
   634  				//ExpectError: regexp.MustCompile("conflicts with storage_data_disk.1.vhd_uri"),
   635  			},
   636  		},
   637  	})
   638  }
   639  
   640  func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) resource.TestCheckFunc {
   641  	return func(s *terraform.State) error {
   642  		// Ensure we have enough information in state to look up in API
   643  		rs, ok := s.RootModule().Resources[name]
   644  		if !ok {
   645  			return fmt.Errorf("Not found: %s", name)
   646  		}
   647  
   648  		vmName := rs.Primary.Attributes["name"]
   649  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   650  		if !hasResourceGroup {
   651  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   652  		}
   653  
   654  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   655  
   656  		resp, err := conn.Get(resourceGroup, vmName, "")
   657  		if err != nil {
   658  			return fmt.Errorf("Bad: Get on vmClient: %s", err)
   659  		}
   660  
   661  		if resp.StatusCode == http.StatusNotFound {
   662  			return fmt.Errorf("Bad: VirtualMachine %q (resource group: %q) does not exist", vmName, resourceGroup)
   663  		}
   664  
   665  		*vm = resp
   666  
   667  		return nil
   668  	}
   669  }
   670  
   671  func testCheckAzureRMVirtualMachineManagedDiskExists(managedDiskID *string, shouldExist bool) resource.TestCheckFunc {
   672  	return func(s *terraform.State) error {
   673  		d, err := testGetAzureRMVirtualMachineManagedDisk(managedDiskID)
   674  		if err != nil {
   675  			return fmt.Errorf("Error trying to retrieve Managed Disk %s, %s", *managedDiskID, err)
   676  		}
   677  		if d.StatusCode == http.StatusNotFound && shouldExist {
   678  			return fmt.Errorf("Unable to find Managed Disk %s", *managedDiskID)
   679  		}
   680  		if d.StatusCode != http.StatusNotFound && !shouldExist {
   681  			return fmt.Errorf("Found unexpected Managed Disk %s", *managedDiskID)
   682  		}
   683  
   684  		return nil
   685  	}
   686  }
   687  
   688  func testAccCheckVirtualMachineRecreated(t *testing.T,
   689  	before, after *compute.VirtualMachine) resource.TestCheckFunc {
   690  	return func(s *terraform.State) error {
   691  		if before.ID == after.ID {
   692  			t.Fatalf("Expected change of Virtual Machine IDs, but both were %v", before.ID)
   693  		}
   694  		return nil
   695  	}
   696  }
   697  
   698  func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error {
   699  	conn := testAccProvider.Meta().(*ArmClient).vmClient
   700  
   701  	for _, rs := range s.RootModule().Resources {
   702  		if rs.Type != "azurerm_virtual_machine" {
   703  			continue
   704  		}
   705  
   706  		name := rs.Primary.Attributes["name"]
   707  		resourceGroup := rs.Primary.Attributes["resource_group_name"]
   708  
   709  		resp, err := conn.Get(resourceGroup, name, "")
   710  
   711  		if err != nil {
   712  			return nil
   713  		}
   714  
   715  		if resp.StatusCode != http.StatusNotFound {
   716  			return fmt.Errorf("Virtual Machine still exists:\n%#v", resp.VirtualMachineProperties)
   717  		}
   718  	}
   719  
   720  	return nil
   721  }
   722  
   723  func testCheckAzureRMVirtualMachineVHDExistence(name string, shouldExist bool) resource.TestCheckFunc {
   724  	return func(s *terraform.State) error {
   725  		for _, rs := range s.RootModule().Resources {
   726  			if rs.Type != "azurerm_storage_container" {
   727  				continue
   728  			}
   729  
   730  			// fetch storage account and container name
   731  			resourceGroup := rs.Primary.Attributes["resource_group_name"]
   732  			storageAccountName := rs.Primary.Attributes["storage_account_name"]
   733  			containerName := rs.Primary.Attributes["name"]
   734  			storageClient, _, err := testAccProvider.Meta().(*ArmClient).getBlobStorageClientForStorageAccount(resourceGroup, storageAccountName)
   735  			if err != nil {
   736  				return fmt.Errorf("Error creating Blob storage client: %s", err)
   737  			}
   738  
   739  			exists, err := storageClient.BlobExists(containerName, name)
   740  			if err != nil {
   741  				return fmt.Errorf("Error checking if Disk VHD Blob exists: %s", err)
   742  			}
   743  
   744  			if exists && !shouldExist {
   745  				return fmt.Errorf("Disk VHD Blob still exists %s %s", containerName, name)
   746  			} else if !exists && shouldExist {
   747  				return fmt.Errorf("Disk VHD Blob should exist %s %s", containerName, name)
   748  			}
   749  		}
   750  
   751  		return nil
   752  	}
   753  }
   754  
   755  func testCheckAzureRMVirtualMachineDisappears(name string) resource.TestCheckFunc {
   756  	return func(s *terraform.State) error {
   757  		// Ensure we have enough information in state to look up in API
   758  		rs, ok := s.RootModule().Resources[name]
   759  		if !ok {
   760  			return fmt.Errorf("Not found: %s", name)
   761  		}
   762  
   763  		vmName := rs.Primary.Attributes["name"]
   764  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   765  		if !hasResourceGroup {
   766  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   767  		}
   768  
   769  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   770  
   771  		_, err := conn.Delete(resourceGroup, vmName, make(chan struct{}))
   772  		if err != nil {
   773  			return fmt.Errorf("Bad: Delete on vmClient: %s", err)
   774  		}
   775  
   776  		return nil
   777  	}
   778  }
   779  
   780  func TestAccAzureRMVirtualMachine_windowsLicenseType(t *testing.T) {
   781  	var vm compute.VirtualMachine
   782  	ri := acctest.RandInt()
   783  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsLicenseType, ri, ri, ri, ri, ri, ri)
   784  	resource.Test(t, resource.TestCase{
   785  		PreCheck:     func() { testAccPreCheck(t) },
   786  		Providers:    testAccProviders,
   787  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   788  		Steps: []resource.TestStep{
   789  			{
   790  				Config: config,
   791  				Check: resource.ComposeTestCheckFunc(
   792  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   793  				),
   794  			},
   795  		},
   796  	})
   797  }
   798  
   799  func TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId(t *testing.T) {
   800  	var vm compute.VirtualMachine
   801  	ri := acctest.RandInt()
   802  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_primaryNetworkInterfaceId, ri, ri, ri, ri, ri, ri, ri)
   803  	resource.Test(t, resource.TestCase{
   804  		PreCheck:     func() { testAccPreCheck(t) },
   805  		Providers:    testAccProviders,
   806  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   807  		Steps: []resource.TestStep{
   808  			{
   809  				Config: config,
   810  				Check: resource.ComposeTestCheckFunc(
   811  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   812  				),
   813  			},
   814  		},
   815  	})
   816  }
   817  
   818  func testLookupAzureRMVirtualMachineManagedDiskID(vm *compute.VirtualMachine, diskName string, managedDiskID *string) resource.TestCheckFunc {
   819  	return func(s *terraform.State) error {
   820  		if osd := vm.StorageProfile.OsDisk; osd != nil {
   821  			if strings.EqualFold(*osd.Name, diskName) {
   822  				if osd.ManagedDisk != nil {
   823  					id, err := findAzureRMVirtualMachineManagedDiskID(osd.ManagedDisk)
   824  					if err != nil {
   825  						return fmt.Errorf("Unable to parse Managed Disk ID for OS Disk %s, %s", diskName, err)
   826  					}
   827  					*managedDiskID = id
   828  					return nil
   829  				}
   830  			}
   831  		}
   832  
   833  		for _, dataDisk := range *vm.StorageProfile.DataDisks {
   834  			if strings.EqualFold(*dataDisk.Name, diskName) {
   835  				if dataDisk.ManagedDisk != nil {
   836  					id, err := findAzureRMVirtualMachineManagedDiskID(dataDisk.ManagedDisk)
   837  					if err != nil {
   838  						return fmt.Errorf("Unable to parse Managed Disk ID for Data Disk %s, %s", diskName, err)
   839  					}
   840  					*managedDiskID = id
   841  					return nil
   842  				}
   843  			}
   844  		}
   845  
   846  		return fmt.Errorf("Unable to locate disk %s on vm %s", diskName, *vm.Name)
   847  	}
   848  }
   849  
   850  func findAzureRMVirtualMachineManagedDiskID(md *compute.ManagedDiskParameters) (string, error) {
   851  	_, err := parseAzureResourceID(*md.ID)
   852  	if err != nil {
   853  		return "", err
   854  	}
   855  	return *md.ID, nil
   856  }
   857  
   858  func testGetAzureRMVirtualMachineManagedDisk(managedDiskID *string) (*disk.Model, error) {
   859  	armID, err := parseAzureResourceID(*managedDiskID)
   860  	if err != nil {
   861  		return nil, fmt.Errorf("Unable to parse Managed Disk ID %s, %s", *managedDiskID, err)
   862  	}
   863  	name := armID.Path["disks"]
   864  	resourceGroup := armID.ResourceGroup
   865  	conn := testAccProvider.Meta().(*ArmClient).diskClient
   866  	d, err := conn.Get(resourceGroup, name)
   867  	//check status first since sdk client returns error if not 200
   868  	if d.Response.StatusCode == http.StatusNotFound {
   869  		return &d, nil
   870  	}
   871  	if err != nil {
   872  		return nil, err
   873  	}
   874  
   875  	return &d, nil
   876  }
   877  
   878  var testAccAzureRMVirtualMachine_basicLinuxMachine = `
   879  resource "azurerm_resource_group" "test" {
   880      name = "acctestRG-%d"
   881      location = "West US 2"
   882  }
   883  
   884  resource "azurerm_virtual_network" "test" {
   885      name = "acctvn-%d"
   886      address_space = ["10.0.0.0/16"]
   887      location = "West US 2"
   888      resource_group_name = "${azurerm_resource_group.test.name}"
   889  }
   890  
   891  resource "azurerm_subnet" "test" {
   892      name = "acctsub-%d"
   893      resource_group_name = "${azurerm_resource_group.test.name}"
   894      virtual_network_name = "${azurerm_virtual_network.test.name}"
   895      address_prefix = "10.0.2.0/24"
   896  }
   897  
   898  resource "azurerm_network_interface" "test" {
   899      name = "acctni-%d"
   900      location = "West US 2"
   901      resource_group_name = "${azurerm_resource_group.test.name}"
   902  
   903      ip_configuration {
   904      	name = "testconfiguration1"
   905      	subnet_id = "${azurerm_subnet.test.id}"
   906      	private_ip_address_allocation = "dynamic"
   907      }
   908  }
   909  
   910  resource "azurerm_storage_account" "test" {
   911      name = "accsa%d"
   912      resource_group_name = "${azurerm_resource_group.test.name}"
   913      location = "West US 2"
   914      account_type = "Standard_LRS"
   915  
   916      tags {
   917          environment = "staging"
   918      }
   919  }
   920  
   921  resource "azurerm_storage_container" "test" {
   922      name = "vhds"
   923      resource_group_name = "${azurerm_resource_group.test.name}"
   924      storage_account_name = "${azurerm_storage_account.test.name}"
   925      container_access_type = "private"
   926  }
   927  
   928  resource "azurerm_virtual_machine" "test" {
   929      name = "acctvm-%d"
   930      location = "West US 2"
   931      resource_group_name = "${azurerm_resource_group.test.name}"
   932      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   933      vm_size = "Standard_D1_v2"
   934  
   935      storage_image_reference {
   936  	publisher = "Canonical"
   937  	offer = "UbuntuServer"
   938  	sku = "14.04.2-LTS"
   939  	version = "latest"
   940      }
   941  
   942      storage_os_disk {
   943          name = "myosdisk1"
   944          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   945          caching = "ReadWrite"
   946          create_option = "FromImage"
   947          disk_size_gb = "45"
   948      }
   949  
   950      os_profile {
   951  	computer_name = "hn%d"
   952  	admin_username = "testadmin"
   953  	admin_password = "Password1234!"
   954      }
   955  
   956      os_profile_linux_config {
   957  	disable_password_authentication = false
   958      }
   959  
   960      tags {
   961      	environment = "Production"
   962      	cost-center = "Ops"
   963      }
   964  }
   965  `
   966  
   967  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit = `
   968  resource "azurerm_resource_group" "test" {
   969      name = "acctestRG-%d"
   970      location = "West US 2"
   971  }
   972  
   973  resource "azurerm_virtual_network" "test" {
   974      name = "acctvn-%d"
   975      address_space = ["10.0.0.0/16"]
   976      location = "West US 2"
   977      resource_group_name = "${azurerm_resource_group.test.name}"
   978  }
   979  
   980  resource "azurerm_subnet" "test" {
   981      name = "acctsub-%d"
   982      resource_group_name = "${azurerm_resource_group.test.name}"
   983      virtual_network_name = "${azurerm_virtual_network.test.name}"
   984      address_prefix = "10.0.2.0/24"
   985  }
   986  
   987  resource "azurerm_network_interface" "test" {
   988      name = "acctni-%d"
   989      location = "West US 2"
   990      resource_group_name = "${azurerm_resource_group.test.name}"
   991  
   992      ip_configuration {
   993      	name = "testconfiguration1"
   994      	subnet_id = "${azurerm_subnet.test.id}"
   995      	private_ip_address_allocation = "dynamic"
   996      }
   997  }
   998  
   999  resource "azurerm_virtual_machine" "test" {
  1000      name = "acctvm-%d"
  1001      location = "West US 2"
  1002      resource_group_name = "${azurerm_resource_group.test.name}"
  1003      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1004      vm_size = "Standard_D1_v2"
  1005  
  1006      storage_image_reference {
  1007  	publisher = "Canonical"
  1008  	offer = "UbuntuServer"
  1009  	sku = "14.04.2-LTS"
  1010  	version = "latest"
  1011      }
  1012  
  1013      storage_os_disk {
  1014          name = "osd-%d"
  1015          caching = "ReadWrite"
  1016          create_option = "FromImage"
  1017          disk_size_gb = "10"
  1018          managed_disk_type = "Standard_LRS"
  1019      }
  1020  
  1021      os_profile {
  1022  	computer_name = "hn%d"
  1023  	admin_username = "testadmin"
  1024  	admin_password = "Password1234!"
  1025      }
  1026  
  1027      os_profile_linux_config {
  1028  	disable_password_authentication = false
  1029      }
  1030  
  1031      tags {
  1032      	environment = "Production"
  1033      	cost-center = "Ops"
  1034      }
  1035  }
  1036  `
  1037  
  1038  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit = `
  1039  resource "azurerm_resource_group" "test" {
  1040      name = "acctestRG-%d"
  1041      location = "West US 2"
  1042  }
  1043  
  1044  resource "azurerm_virtual_network" "test" {
  1045      name = "acctvn-%d"
  1046      address_space = ["10.0.0.0/16"]
  1047      location = "West US 2"
  1048      resource_group_name = "${azurerm_resource_group.test.name}"
  1049  }
  1050  
  1051  resource "azurerm_subnet" "test" {
  1052      name = "acctsub-%d"
  1053      resource_group_name = "${azurerm_resource_group.test.name}"
  1054      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1055      address_prefix = "10.0.2.0/24"
  1056  }
  1057  
  1058  resource "azurerm_network_interface" "test" {
  1059      name = "acctni-%d"
  1060      location = "West US 2"
  1061      resource_group_name = "${azurerm_resource_group.test.name}"
  1062  
  1063      ip_configuration {
  1064      	name = "testconfiguration1"
  1065      	subnet_id = "${azurerm_subnet.test.id}"
  1066      	private_ip_address_allocation = "dynamic"
  1067      }
  1068  }
  1069  
  1070  resource "azurerm_virtual_machine" "test" {
  1071      name = "acctvm-%d"
  1072      location = "West US 2"
  1073      resource_group_name = "${azurerm_resource_group.test.name}"
  1074      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1075      vm_size = "Standard_D1_v2"
  1076  
  1077      storage_image_reference {
  1078  	publisher = "Canonical"
  1079  	offer = "UbuntuServer"
  1080  	sku = "14.04.2-LTS"
  1081  	version = "latest"
  1082      }
  1083  
  1084      storage_os_disk {
  1085          name = "osd-%d"
  1086          caching = "ReadWrite"
  1087          create_option = "FromImage"
  1088          disk_size_gb = "10"
  1089      }
  1090  
  1091      os_profile {
  1092  	computer_name = "hn%d"
  1093  	admin_username = "testadmin"
  1094  	admin_password = "Password1234!"
  1095      }
  1096  
  1097      os_profile_linux_config {
  1098  	disable_password_authentication = false
  1099      }
  1100  
  1101      tags {
  1102      	environment = "Production"
  1103      	cost-center = "Ops"
  1104      }
  1105  }
  1106  `
  1107  
  1108  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach = `
  1109  resource "azurerm_resource_group" "test" {
  1110      name = "acctestRG-%d"
  1111      location = "West US 2"
  1112  }
  1113  
  1114  resource "azurerm_virtual_network" "test" {
  1115      name = "acctvn-%d"
  1116      address_space = ["10.0.0.0/16"]
  1117      location = "West US 2"
  1118      resource_group_name = "${azurerm_resource_group.test.name}"
  1119  }
  1120  
  1121  resource "azurerm_subnet" "test" {
  1122      name = "acctsub-%d"
  1123      resource_group_name = "${azurerm_resource_group.test.name}"
  1124      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1125      address_prefix = "10.0.2.0/24"
  1126  }
  1127  
  1128  resource "azurerm_network_interface" "test" {
  1129      name = "acctni-%d"
  1130      location = "West US 2"
  1131      resource_group_name = "${azurerm_resource_group.test.name}"
  1132  
  1133      ip_configuration {
  1134      	name = "testconfiguration1"
  1135      	subnet_id = "${azurerm_subnet.test.id}"
  1136      	private_ip_address_allocation = "dynamic"
  1137      }
  1138  }
  1139  
  1140  resource "azurerm_managed_disk" "test" {
  1141      name = "acctmd-%d"
  1142      location = "West US 2"
  1143      resource_group_name = "${azurerm_resource_group.test.name}"
  1144      storage_account_type = "Standard_LRS"
  1145      create_option = "Empty"
  1146      disk_size_gb = "1"
  1147  }
  1148  
  1149  resource "azurerm_virtual_machine" "test" {
  1150      name = "acctvm-%d"
  1151      location = "West US 2"
  1152      resource_group_name = "${azurerm_resource_group.test.name}"
  1153      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1154      vm_size = "Standard_D1_v2"
  1155  
  1156      storage_image_reference {
  1157  	publisher = "Canonical"
  1158  	offer = "UbuntuServer"
  1159  	sku = "14.04.2-LTS"
  1160  	version = "latest"
  1161      }
  1162  
  1163      storage_os_disk {
  1164          name = "osd-%d"
  1165          caching = "ReadWrite"
  1166          create_option = "FromImage"
  1167          disk_size_gb = "10"
  1168          managed_disk_type = "Standard_LRS"
  1169      }
  1170  
  1171      storage_data_disk {
  1172          name = "${azurerm_managed_disk.test.name}"
  1173      	create_option = "Attach"
  1174      	disk_size_gb = "1"
  1175      	lun = 0
  1176          managed_disk_id = "${azurerm_managed_disk.test.id}"
  1177      }
  1178  
  1179      os_profile {
  1180  	computer_name = "hn%d"
  1181  	admin_username = "testadmin"
  1182  	admin_password = "Password1234!"
  1183      }
  1184  
  1185      os_profile_linux_config {
  1186  	disable_password_authentication = false
  1187      }
  1188  
  1189      tags {
  1190      	environment = "Production"
  1191      	cost-center = "Ops"
  1192      }
  1193  }
  1194  `
  1195  
  1196  var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = `
  1197  resource "azurerm_resource_group" "test" {
  1198      name = "acctestRG-%d"
  1199      location = "West US 2"
  1200  }
  1201  
  1202  resource "azurerm_virtual_network" "test" {
  1203      name = "acctvn-%d"
  1204      address_space = ["10.0.0.0/16"]
  1205      location = "West US 2"
  1206      resource_group_name = "${azurerm_resource_group.test.name}"
  1207  }
  1208  
  1209  resource "azurerm_subnet" "test" {
  1210      name = "acctsub-%d"
  1211      resource_group_name = "${azurerm_resource_group.test.name}"
  1212      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1213      address_prefix = "10.0.2.0/24"
  1214  }
  1215  
  1216  resource "azurerm_network_interface" "test" {
  1217      name = "acctni-%d"
  1218      location = "West US 2"
  1219      resource_group_name = "${azurerm_resource_group.test.name}"
  1220  
  1221      ip_configuration {
  1222      	name = "testconfiguration1"
  1223      	subnet_id = "${azurerm_subnet.test.id}"
  1224      	private_ip_address_allocation = "dynamic"
  1225      }
  1226  }
  1227  
  1228  resource "azurerm_storage_account" "test" {
  1229      name = "accsa%d"
  1230      resource_group_name = "${azurerm_resource_group.test.name}"
  1231      location = "West US 2"
  1232      account_type = "Standard_LRS"
  1233  
  1234      tags {
  1235          environment = "staging"
  1236      }
  1237  }
  1238  
  1239  resource "azurerm_storage_container" "test" {
  1240      name = "vhds"
  1241      resource_group_name = "${azurerm_resource_group.test.name}"
  1242      storage_account_name = "${azurerm_storage_account.test.name}"
  1243      container_access_type = "private"
  1244  }
  1245  
  1246  resource "azurerm_virtual_machine" "test" {
  1247      name = "acctvm-%d"
  1248      location = "West US 2"
  1249      resource_group_name = "${azurerm_resource_group.test.name}"
  1250      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1251      vm_size = "Standard_D1_v2"
  1252      delete_os_disk_on_termination = true
  1253  
  1254      storage_image_reference {
  1255  	publisher = "Canonical"
  1256  	offer = "UbuntuServer"
  1257  	sku = "14.04.2-LTS"
  1258  	version = "latest"
  1259      }
  1260  
  1261      storage_os_disk {
  1262          name = "myosdisk1"
  1263          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1264          caching = "ReadWrite"
  1265          create_option = "FromImage"
  1266      }
  1267  
  1268      os_profile {
  1269  	computer_name = "hn%d"
  1270  	admin_username = "testadmin"
  1271  	admin_password = "Password1234!"
  1272      }
  1273  
  1274      os_profile_linux_config {
  1275  	disable_password_authentication = false
  1276      }
  1277  
  1278      tags {
  1279      	environment = "Production"
  1280      	cost-center = "Ops"
  1281      }
  1282  }
  1283  `
  1284  
  1285  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore = `
  1286  resource "azurerm_resource_group" "test" {
  1287      name = "acctestRG-%d"
  1288      location = "West US 2"
  1289  }
  1290  
  1291  resource "azurerm_resource_group" "test-sa" {
  1292      name = "acctestRG-sa-%d"
  1293      location = "West US 2"
  1294  }
  1295  
  1296  resource "azurerm_virtual_network" "test" {
  1297      name = "acctvn-%d"
  1298      address_space = ["10.0.0.0/16"]
  1299      location = "West US 2"
  1300      resource_group_name = "${azurerm_resource_group.test.name}"
  1301  }
  1302  
  1303  resource "azurerm_subnet" "test" {
  1304      name = "acctsub-%d"
  1305      resource_group_name = "${azurerm_resource_group.test.name}"
  1306      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1307      address_prefix = "10.0.2.0/24"
  1308  }
  1309  
  1310  resource "azurerm_network_interface" "test" {
  1311      name = "acctni-%d"
  1312      location = "West US 2"
  1313      resource_group_name = "${azurerm_resource_group.test.name}"
  1314  
  1315      ip_configuration {
  1316      	name = "testconfiguration1"
  1317      	subnet_id = "${azurerm_subnet.test.id}"
  1318      	private_ip_address_allocation = "dynamic"
  1319      }
  1320  }
  1321  
  1322  resource "azurerm_storage_account" "test" {
  1323      name = "accsa%d"
  1324      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1325      location = "West US 2"
  1326      account_type = "Standard_LRS"
  1327  
  1328      tags {
  1329          environment = "staging"
  1330      }
  1331  }
  1332  
  1333  resource "azurerm_storage_container" "test" {
  1334      name = "vhds"
  1335      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1336      storage_account_name = "${azurerm_storage_account.test.name}"
  1337      container_access_type = "private"
  1338  }
  1339  
  1340  resource "azurerm_virtual_machine" "test" {
  1341      name = "acctvm-%d"
  1342      location = "West US 2"
  1343      resource_group_name = "${azurerm_resource_group.test.name}"
  1344      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1345      vm_size = "Standard_D1_v2"
  1346  
  1347      storage_image_reference {
  1348  	publisher = "Canonical"
  1349  	offer = "UbuntuServer"
  1350  	sku = "14.04.2-LTS"
  1351  	version = "latest"
  1352      }
  1353  
  1354      storage_os_disk {
  1355          name = "myosdisk1"
  1356          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1357          caching = "ReadWrite"
  1358          create_option = "FromImage"
  1359      }
  1360  
  1361      delete_os_disk_on_termination = true
  1362  
  1363      storage_data_disk {
  1364          name          = "mydatadisk1"
  1365          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
  1366      	disk_size_gb  = "1"
  1367      	create_option = "Empty"
  1368      	lun           = 0
  1369      }
  1370  
  1371      delete_data_disks_on_termination = true
  1372  
  1373      os_profile {
  1374  	computer_name = "hn%d"
  1375  	admin_username = "testadmin"
  1376  	admin_password = "Password1234!"
  1377      }
  1378  
  1379      os_profile_linux_config {
  1380  	disable_password_authentication = false
  1381      }
  1382  
  1383      tags {
  1384      	environment = "Production"
  1385      	cost-center = "Ops"
  1386      }
  1387  }
  1388  `
  1389  
  1390  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore = `
  1391  resource "azurerm_resource_group" "test" {
  1392      name = "acctestRG-%d"
  1393      location = "West US 2"
  1394  }
  1395  
  1396  resource "azurerm_virtual_network" "test" {
  1397      name = "acctvn-%d"
  1398      address_space = ["10.0.0.0/16"]
  1399      location = "West US 2"
  1400      resource_group_name = "${azurerm_resource_group.test.name}"
  1401  }
  1402  
  1403  resource "azurerm_subnet" "test" {
  1404      name = "acctsub-%d"
  1405      resource_group_name = "${azurerm_resource_group.test.name}"
  1406      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1407      address_prefix = "10.0.2.0/24"
  1408  }
  1409  
  1410  resource "azurerm_network_interface" "test" {
  1411      name = "acctni-%d"
  1412      location = "West US 2"
  1413      resource_group_name = "${azurerm_resource_group.test.name}"
  1414  
  1415      ip_configuration {
  1416      	name = "testconfiguration1"
  1417      	subnet_id = "${azurerm_subnet.test.id}"
  1418      	private_ip_address_allocation = "dynamic"
  1419      }
  1420  }
  1421  
  1422  resource "azurerm_virtual_machine" "test" {
  1423      name = "acctvm-%d"
  1424      location = "West US 2"
  1425      resource_group_name = "${azurerm_resource_group.test.name}"
  1426      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1427      vm_size = "Standard_D1_v2"
  1428  
  1429      storage_image_reference {
  1430  	publisher = "Canonical"
  1431  	offer = "UbuntuServer"
  1432  	sku = "14.04.2-LTS"
  1433  	version = "latest"
  1434      }
  1435  
  1436      storage_os_disk {
  1437          name = "myosdisk1"
  1438          caching = "ReadWrite"
  1439          create_option = "FromImage"
  1440      }
  1441  
  1442      delete_os_disk_on_termination = true
  1443  
  1444      storage_data_disk {
  1445          name          = "mydatadisk1"
  1446      	disk_size_gb  = "1"
  1447      	create_option = "Empty"
  1448      	lun           = 0
  1449      }
  1450  
  1451      delete_data_disks_on_termination = true
  1452  
  1453      os_profile {
  1454  	computer_name = "hn%d"
  1455  	admin_username = "testadmin"
  1456  	admin_password = "Password1234!"
  1457      }
  1458  
  1459      os_profile_linux_config {
  1460  	disable_password_authentication = false
  1461      }
  1462  
  1463      tags {
  1464      	environment = "Production"
  1465      	cost-center = "Ops"
  1466      }
  1467  }
  1468  `
  1469  
  1470  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter = `
  1471  resource "azurerm_resource_group" "test" {
  1472      name = "acctestRG-%d"
  1473      location = "West US 2"
  1474  }
  1475  
  1476  resource "azurerm_resource_group" "test-sa" {
  1477      name = "acctestRG-sa-%d"
  1478      location = "West US 2"
  1479  }
  1480  
  1481  resource "azurerm_virtual_network" "test" {
  1482      name = "acctvn-%d"
  1483      address_space = ["10.0.0.0/16"]
  1484      location = "West US 2"
  1485      resource_group_name = "${azurerm_resource_group.test.name}"
  1486  }
  1487  
  1488  resource "azurerm_subnet" "test" {
  1489      name = "acctsub-%d"
  1490      resource_group_name = "${azurerm_resource_group.test.name}"
  1491      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1492      address_prefix = "10.0.2.0/24"
  1493  }
  1494  
  1495  resource "azurerm_network_interface" "test" {
  1496      name = "acctni-%d"
  1497      location = "West US 2"
  1498      resource_group_name = "${azurerm_resource_group.test.name}"
  1499  
  1500      ip_configuration {
  1501      	name = "testconfiguration1"
  1502      	subnet_id = "${azurerm_subnet.test.id}"
  1503      	private_ip_address_allocation = "dynamic"
  1504      }
  1505  }
  1506  
  1507  resource "azurerm_storage_account" "test" {
  1508      name = "accsa%d"
  1509      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1510      location = "West US 2"
  1511      account_type = "Standard_LRS"
  1512  
  1513      tags {
  1514          environment = "staging"
  1515      }
  1516  }
  1517  
  1518  resource "azurerm_storage_container" "test" {
  1519      name = "vhds"
  1520      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1521      storage_account_name = "${azurerm_storage_account.test.name}"
  1522      container_access_type = "private"
  1523  }
  1524  `
  1525  
  1526  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter = `
  1527  resource "azurerm_resource_group" "test" {
  1528      name = "acctestRG-%d"
  1529      location = "West US 2"
  1530  }
  1531  
  1532  resource "azurerm_virtual_network" "test" {
  1533      name = "acctvn-%d"
  1534      address_space = ["10.0.0.0/16"]
  1535      location = "West US 2"
  1536      resource_group_name = "${azurerm_resource_group.test.name}"
  1537  }
  1538  
  1539  resource "azurerm_subnet" "test" {
  1540      name = "acctsub-%d"
  1541      resource_group_name = "${azurerm_resource_group.test.name}"
  1542      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1543      address_prefix = "10.0.2.0/24"
  1544  }
  1545  
  1546  resource "azurerm_network_interface" "test" {
  1547      name = "acctni-%d"
  1548      location = "West US 2"
  1549      resource_group_name = "${azurerm_resource_group.test.name}"
  1550  
  1551      ip_configuration {
  1552      	name = "testconfiguration1"
  1553      	subnet_id = "${azurerm_subnet.test.id}"
  1554      	private_ip_address_allocation = "dynamic"
  1555      }
  1556  }
  1557  `
  1558  
  1559  var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = `
  1560  resource "azurerm_resource_group" "test" {
  1561      name = "acctestRG-%d"
  1562      location = "West US 2"
  1563  }
  1564  
  1565  resource "azurerm_virtual_network" "test" {
  1566      name = "acctvn-%d"
  1567      address_space = ["10.0.0.0/16"]
  1568      location = "West US 2"
  1569      resource_group_name = "${azurerm_resource_group.test.name}"
  1570  }
  1571  
  1572  resource "azurerm_subnet" "test" {
  1573      name = "acctsub-%d"
  1574      resource_group_name = "${azurerm_resource_group.test.name}"
  1575      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1576      address_prefix = "10.0.2.0/24"
  1577  }
  1578  
  1579  resource "azurerm_network_interface" "test" {
  1580      name = "acctni-%d"
  1581      location = "West US 2"
  1582      resource_group_name = "${azurerm_resource_group.test.name}"
  1583  
  1584      ip_configuration {
  1585      	name = "testconfiguration1"
  1586      	subnet_id = "${azurerm_subnet.test.id}"
  1587      	private_ip_address_allocation = "dynamic"
  1588      }
  1589  }
  1590  
  1591  resource "azurerm_storage_account" "test" {
  1592      name = "accsa%d"
  1593      resource_group_name = "${azurerm_resource_group.test.name}"
  1594      location = "West US 2"
  1595      account_type = "Standard_LRS"
  1596  
  1597      tags {
  1598          environment = "staging"
  1599      }
  1600  }
  1601  
  1602  resource "azurerm_storage_container" "test" {
  1603      name = "vhds"
  1604      resource_group_name = "${azurerm_resource_group.test.name}"
  1605      storage_account_name = "${azurerm_storage_account.test.name}"
  1606      container_access_type = "private"
  1607  }
  1608  `
  1609  
  1610  var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk = `
  1611  resource "azurerm_resource_group" "test" {
  1612      name = "acctestRG-%d"
  1613      location = "West US 2"
  1614  }
  1615  
  1616  resource "azurerm_virtual_network" "test" {
  1617      name = "acctvn-%d"
  1618      address_space = ["10.0.0.0/16"]
  1619      location = "West US 2"
  1620      resource_group_name = "${azurerm_resource_group.test.name}"
  1621  }
  1622  
  1623  resource "azurerm_subnet" "test" {
  1624      name = "acctsub-%d"
  1625      resource_group_name = "${azurerm_resource_group.test.name}"
  1626      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1627      address_prefix = "10.0.2.0/24"
  1628  }
  1629  
  1630  resource "azurerm_network_interface" "test" {
  1631      name = "acctni-%d"
  1632      location = "West US 2"
  1633      resource_group_name = "${azurerm_resource_group.test.name}"
  1634  
  1635      ip_configuration {
  1636      	name = "testconfiguration1"
  1637      	subnet_id = "${azurerm_subnet.test.id}"
  1638      	private_ip_address_allocation = "dynamic"
  1639      }
  1640  }
  1641  `
  1642  
  1643  var testAccAzureRMVirtualMachine_withDataDisk = `
  1644  resource "azurerm_resource_group" "test" {
  1645      name = "acctestRG-%d"
  1646      location = "West US 2"
  1647  }
  1648  
  1649  resource "azurerm_virtual_network" "test" {
  1650      name = "acctvn-%d"
  1651      address_space = ["10.0.0.0/16"]
  1652      location = "West US 2"
  1653      resource_group_name = "${azurerm_resource_group.test.name}"
  1654  }
  1655  
  1656  resource "azurerm_subnet" "test" {
  1657      name = "acctsub-%d"
  1658      resource_group_name = "${azurerm_resource_group.test.name}"
  1659      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1660      address_prefix = "10.0.2.0/24"
  1661  }
  1662  
  1663  resource "azurerm_network_interface" "test" {
  1664      name = "acctni-%d"
  1665      location = "West US 2"
  1666      resource_group_name = "${azurerm_resource_group.test.name}"
  1667  
  1668      ip_configuration {
  1669      	name = "testconfiguration1"
  1670      	subnet_id = "${azurerm_subnet.test.id}"
  1671      	private_ip_address_allocation = "dynamic"
  1672      }
  1673  }
  1674  
  1675  resource "azurerm_storage_account" "test" {
  1676      name = "accsa%d"
  1677      resource_group_name = "${azurerm_resource_group.test.name}"
  1678      location = "West US 2"
  1679      account_type = "Standard_LRS"
  1680  
  1681      tags {
  1682          environment = "staging"
  1683      }
  1684  }
  1685  
  1686  resource "azurerm_storage_container" "test" {
  1687      name = "vhds"
  1688      resource_group_name = "${azurerm_resource_group.test.name}"
  1689      storage_account_name = "${azurerm_storage_account.test.name}"
  1690      container_access_type = "private"
  1691  }
  1692  
  1693  resource "azurerm_virtual_machine" "test" {
  1694      name = "acctvm-%d"
  1695      location = "West US 2"
  1696      resource_group_name = "${azurerm_resource_group.test.name}"
  1697      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1698      vm_size = "Standard_D1_v2"
  1699  
  1700      storage_image_reference {
  1701  	publisher = "Canonical"
  1702  	offer = "UbuntuServer"
  1703  	sku = "14.04.2-LTS"
  1704  	version = "latest"
  1705      }
  1706  
  1707      storage_os_disk {
  1708          name = "myosdisk1"
  1709          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1710          caching = "ReadWrite"
  1711          create_option = "FromImage"
  1712      }
  1713  
  1714      storage_data_disk {
  1715          name          = "mydatadisk1"
  1716          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
  1717      	disk_size_gb  = "1"
  1718      	create_option = "Empty"
  1719          caching       = "ReadWrite"
  1720      	lun           = 0
  1721      }
  1722  
  1723      os_profile {
  1724  	computer_name = "hn%d"
  1725  	admin_username = "testadmin"
  1726  	admin_password = "Password1234!"
  1727      }
  1728  
  1729      os_profile_linux_config {
  1730  	disable_password_authentication = false
  1731      }
  1732  
  1733      tags {
  1734      	environment = "Production"
  1735      	cost-center = "Ops"
  1736      }
  1737  }
  1738  `
  1739  
  1740  var testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit = `
  1741  resource "azurerm_resource_group" "test" {
  1742      name = "acctestRG-%d"
  1743      location = "West US 2"
  1744  }
  1745  
  1746  resource "azurerm_virtual_network" "test" {
  1747      name = "acctvn-%d"
  1748      address_space = ["10.0.0.0/16"]
  1749      location = "West US 2"
  1750      resource_group_name = "${azurerm_resource_group.test.name}"
  1751  }
  1752  
  1753  resource "azurerm_subnet" "test" {
  1754      name = "acctsub-%d"
  1755      resource_group_name = "${azurerm_resource_group.test.name}"
  1756      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1757      address_prefix = "10.0.2.0/24"
  1758  }
  1759  
  1760  resource "azurerm_network_interface" "test" {
  1761      name = "acctni-%d"
  1762      location = "West US 2"
  1763      resource_group_name = "${azurerm_resource_group.test.name}"
  1764  
  1765      ip_configuration {
  1766      	name = "testconfiguration1"
  1767      	subnet_id = "${azurerm_subnet.test.id}"
  1768      	private_ip_address_allocation = "dynamic"
  1769      }
  1770  }
  1771  
  1772  resource "azurerm_virtual_machine" "test" {
  1773      name = "acctvm-%d"
  1774      location = "West US 2"
  1775      resource_group_name = "${azurerm_resource_group.test.name}"
  1776      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1777      vm_size = "Standard_D1_v2"
  1778  
  1779      storage_image_reference {
  1780  	publisher = "Canonical"
  1781  	offer = "UbuntuServer"
  1782  	sku = "14.04.2-LTS"
  1783  	version = "latest"
  1784      }
  1785  
  1786      storage_os_disk {
  1787          name = "osd-%d"
  1788          caching = "ReadWrite"
  1789          create_option = "FromImage"
  1790          managed_disk_type = "Standard_LRS"
  1791      }
  1792  
  1793      storage_data_disk {
  1794          name          = "dtd-%d"
  1795      	disk_size_gb  = "1"
  1796      	create_option = "Empty"
  1797          caching       = "ReadWrite"
  1798      	lun           = 0
  1799      	managed_disk_type = "Standard_LRS"
  1800      }
  1801  
  1802      os_profile {
  1803  	computer_name = "hn%d"
  1804  	admin_username = "testadmin"
  1805  	admin_password = "Password1234!"
  1806      }
  1807  
  1808      os_profile_linux_config {
  1809  	disable_password_authentication = false
  1810      }
  1811  
  1812      tags {
  1813      	environment = "Production"
  1814      	cost-center = "Ops"
  1815      }
  1816  }
  1817  `
  1818  
  1819  var testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit = `
  1820  resource "azurerm_resource_group" "test" {
  1821      name = "acctestRG-%d"
  1822      location = "West US 2"
  1823  }
  1824  
  1825  resource "azurerm_virtual_network" "test" {
  1826      name = "acctvn-%d"
  1827      address_space = ["10.0.0.0/16"]
  1828      location = "West US 2"
  1829      resource_group_name = "${azurerm_resource_group.test.name}"
  1830  }
  1831  
  1832  resource "azurerm_subnet" "test" {
  1833      name = "acctsub-%d"
  1834      resource_group_name = "${azurerm_resource_group.test.name}"
  1835      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1836      address_prefix = "10.0.2.0/24"
  1837  }
  1838  
  1839  resource "azurerm_network_interface" "test" {
  1840      name = "acctni-%d"
  1841      location = "West US 2"
  1842      resource_group_name = "${azurerm_resource_group.test.name}"
  1843  
  1844      ip_configuration {
  1845      	name = "testconfiguration1"
  1846      	subnet_id = "${azurerm_subnet.test.id}"
  1847      	private_ip_address_allocation = "dynamic"
  1848      }
  1849  }
  1850  
  1851  resource "azurerm_virtual_machine" "test" {
  1852      name = "acctvm-%d"
  1853      location = "West US 2"
  1854      resource_group_name = "${azurerm_resource_group.test.name}"
  1855      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1856      vm_size = "Standard_D1_v2"
  1857  
  1858      storage_image_reference {
  1859  	publisher = "Canonical"
  1860  	offer = "UbuntuServer"
  1861  	sku = "14.04.2-LTS"
  1862  	version = "latest"
  1863      }
  1864  
  1865      storage_os_disk {
  1866          name = "myosdisk1"
  1867          caching = "ReadWrite"
  1868          create_option = "FromImage"
  1869      }
  1870  
  1871      storage_data_disk {
  1872          name          = "mydatadisk1"
  1873      	disk_size_gb  = "1"
  1874      	create_option = "Empty"
  1875          caching       = "ReadWrite"
  1876      	lun           = 0
  1877      }
  1878  
  1879      os_profile {
  1880  	computer_name = "hn%d"
  1881  	admin_username = "testadmin"
  1882  	admin_password = "Password1234!"
  1883      }
  1884  
  1885      os_profile_linux_config {
  1886  	disable_password_authentication = false
  1887      }
  1888  
  1889      tags {
  1890      	environment = "Production"
  1891      	cost-center = "Ops"
  1892      }
  1893  }
  1894  `
  1895  
  1896  var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = `
  1897  resource "azurerm_resource_group" "test" {
  1898      name = "acctestRG-%d"
  1899      location = "West US 2"
  1900  }
  1901  
  1902  resource "azurerm_virtual_network" "test" {
  1903      name = "acctvn-%d"
  1904      address_space = ["10.0.0.0/16"]
  1905      location = "West US 2"
  1906      resource_group_name = "${azurerm_resource_group.test.name}"
  1907  }
  1908  
  1909  resource "azurerm_subnet" "test" {
  1910      name = "acctsub-%d"
  1911      resource_group_name = "${azurerm_resource_group.test.name}"
  1912      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1913      address_prefix = "10.0.2.0/24"
  1914  }
  1915  
  1916  resource "azurerm_network_interface" "test" {
  1917      name = "acctni-%d"
  1918      location = "West US 2"
  1919      resource_group_name = "${azurerm_resource_group.test.name}"
  1920  
  1921      ip_configuration {
  1922      	name = "testconfiguration1"
  1923      	subnet_id = "${azurerm_subnet.test.id}"
  1924      	private_ip_address_allocation = "dynamic"
  1925      }
  1926  }
  1927  
  1928  resource "azurerm_storage_account" "test" {
  1929      name = "accsa%d"
  1930      resource_group_name = "${azurerm_resource_group.test.name}"
  1931      location = "West US 2"
  1932      account_type = "Standard_LRS"
  1933  
  1934      tags {
  1935          environment = "staging"
  1936      }
  1937  }
  1938  
  1939  resource "azurerm_storage_container" "test" {
  1940      name = "vhds"
  1941      resource_group_name = "${azurerm_resource_group.test.name}"
  1942      storage_account_name = "${azurerm_storage_account.test.name}"
  1943      container_access_type = "private"
  1944  }
  1945  
  1946  resource "azurerm_virtual_machine" "test" {
  1947      name = "acctvm-%d"
  1948      location = "West US 2"
  1949      resource_group_name = "${azurerm_resource_group.test.name}"
  1950      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1951      vm_size = "Standard_D1_v2"
  1952  
  1953      storage_image_reference {
  1954  	publisher = "Canonical"
  1955  	offer = "UbuntuServer"
  1956  	sku = "14.04.2-LTS"
  1957  	version = "latest"
  1958      }
  1959  
  1960      storage_os_disk {
  1961          name = "myosdisk1"
  1962          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1963          caching = "ReadWrite"
  1964          create_option = "FromImage"
  1965      }
  1966  
  1967      os_profile {
  1968  	computer_name = "hn%d"
  1969  	admin_username = "testadmin"
  1970  	admin_password = "Password1234!"
  1971      }
  1972  
  1973      os_profile_linux_config {
  1974  	disable_password_authentication = false
  1975      }
  1976  
  1977      tags {
  1978      	environment = "Production"
  1979      }
  1980  }
  1981  `
  1982  
  1983  var testAccAzureRMVirtualMachine_updatedLinuxMachine = `
  1984  resource "azurerm_resource_group" "test" {
  1985      name = "acctestRG-%d"
  1986      location = "West US 2"
  1987  }
  1988  
  1989  resource "azurerm_virtual_network" "test" {
  1990      name = "acctvn-%d"
  1991      address_space = ["10.0.0.0/16"]
  1992      location = "West US 2"
  1993      resource_group_name = "${azurerm_resource_group.test.name}"
  1994  }
  1995  
  1996  resource "azurerm_subnet" "test" {
  1997      name = "acctsub-%d"
  1998      resource_group_name = "${azurerm_resource_group.test.name}"
  1999      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2000      address_prefix = "10.0.2.0/24"
  2001  }
  2002  
  2003  resource "azurerm_network_interface" "test" {
  2004      name = "acctni-%d"
  2005      location = "West US 2"
  2006      resource_group_name = "${azurerm_resource_group.test.name}"
  2007  
  2008      ip_configuration {
  2009      	name = "testconfiguration1"
  2010      	subnet_id = "${azurerm_subnet.test.id}"
  2011      	private_ip_address_allocation = "dynamic"
  2012      }
  2013  }
  2014  
  2015  resource "azurerm_storage_account" "test" {
  2016      name = "accsa%d"
  2017      resource_group_name = "${azurerm_resource_group.test.name}"
  2018      location = "West US 2"
  2019      account_type = "Standard_LRS"
  2020  
  2021      tags {
  2022          environment = "staging"
  2023      }
  2024  }
  2025  
  2026  resource "azurerm_storage_container" "test" {
  2027      name = "vhds"
  2028      resource_group_name = "${azurerm_resource_group.test.name}"
  2029      storage_account_name = "${azurerm_storage_account.test.name}"
  2030      container_access_type = "private"
  2031  }
  2032  
  2033  resource "azurerm_virtual_machine" "test" {
  2034      name = "acctvm-%d"
  2035      location = "West US 2"
  2036      resource_group_name = "${azurerm_resource_group.test.name}"
  2037      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2038      vm_size = "Standard_D2_v2"
  2039  
  2040      storage_image_reference {
  2041  	publisher = "Canonical"
  2042  	offer = "UbuntuServer"
  2043  	sku = "14.04.2-LTS"
  2044  	version = "latest"
  2045      }
  2046  
  2047      storage_os_disk {
  2048          name = "myosdisk1"
  2049          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2050          caching = "ReadWrite"
  2051          create_option = "FromImage"
  2052      }
  2053  
  2054      os_profile {
  2055  	computer_name = "hn%d"
  2056  	admin_username = "testadmin"
  2057  	admin_password = "Password1234!"
  2058      }
  2059  
  2060      os_profile_linux_config {
  2061  	disable_password_authentication = false
  2062      }
  2063  }
  2064  `
  2065  
  2066  var testAccAzureRMVirtualMachine_basicWindowsMachine = `
  2067  resource "azurerm_resource_group" "test" {
  2068      name = "acctestRG-%d"
  2069      location = "West US 2"
  2070  }
  2071  
  2072  resource "azurerm_virtual_network" "test" {
  2073      name = "acctvn-%d"
  2074      address_space = ["10.0.0.0/16"]
  2075      location = "West US 2"
  2076      resource_group_name = "${azurerm_resource_group.test.name}"
  2077  }
  2078  
  2079  resource "azurerm_subnet" "test" {
  2080      name = "acctsub-%d"
  2081      resource_group_name = "${azurerm_resource_group.test.name}"
  2082      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2083      address_prefix = "10.0.2.0/24"
  2084  }
  2085  
  2086  resource "azurerm_network_interface" "test" {
  2087      name = "acctni-%d"
  2088      location = "West US 2"
  2089      resource_group_name = "${azurerm_resource_group.test.name}"
  2090  
  2091      ip_configuration {
  2092      	name = "testconfiguration1"
  2093      	subnet_id = "${azurerm_subnet.test.id}"
  2094      	private_ip_address_allocation = "dynamic"
  2095      }
  2096  }
  2097  
  2098  resource "azurerm_storage_account" "test" {
  2099      name = "accsa%d"
  2100      resource_group_name = "${azurerm_resource_group.test.name}"
  2101      location = "West US 2"
  2102      account_type = "Standard_LRS"
  2103  
  2104      tags {
  2105          environment = "staging"
  2106      }
  2107  }
  2108  
  2109  resource "azurerm_storage_container" "test" {
  2110      name = "vhds"
  2111      resource_group_name = "${azurerm_resource_group.test.name}"
  2112      storage_account_name = "${azurerm_storage_account.test.name}"
  2113      container_access_type = "private"
  2114  }
  2115  
  2116  resource "azurerm_virtual_machine" "test" {
  2117      name = "acctvm-%d"
  2118      location = "West US 2"
  2119      resource_group_name = "${azurerm_resource_group.test.name}"
  2120      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2121      vm_size = "Standard_D1_v2"
  2122  
  2123      storage_image_reference {
  2124  	publisher = "MicrosoftWindowsServer"
  2125  	offer = "WindowsServer"
  2126  	sku = "2012-Datacenter"
  2127  	version = "latest"
  2128      }
  2129  
  2130      storage_os_disk {
  2131          name = "myosdisk1"
  2132          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2133          caching = "ReadWrite"
  2134          create_option = "FromImage"
  2135      }
  2136  
  2137      os_profile {
  2138  	computer_name = "winhost01"
  2139  	admin_username = "testadmin"
  2140  	admin_password = "Password1234!"
  2141      }
  2142  
  2143      os_profile_windows_config {
  2144  	enable_automatic_upgrades = false
  2145  	provision_vm_agent = true
  2146      }
  2147  }
  2148  `
  2149  
  2150  var testAccAzureRMVirtualMachine_windowsUnattendedConfig = `
  2151  resource "azurerm_resource_group" "test" {
  2152      name = "acctestRG-%d"
  2153      location = "West US 2"
  2154  }
  2155  
  2156  resource "azurerm_virtual_network" "test" {
  2157      name = "acctvn-%d"
  2158      address_space = ["10.0.0.0/16"]
  2159      location = "West US 2"
  2160      resource_group_name = "${azurerm_resource_group.test.name}"
  2161  }
  2162  
  2163  resource "azurerm_subnet" "test" {
  2164      name = "acctsub-%d"
  2165      resource_group_name = "${azurerm_resource_group.test.name}"
  2166      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2167      address_prefix = "10.0.2.0/24"
  2168  }
  2169  
  2170  resource "azurerm_network_interface" "test" {
  2171      name = "acctni-%d"
  2172      location = "West US 2"
  2173      resource_group_name = "${azurerm_resource_group.test.name}"
  2174  
  2175      ip_configuration {
  2176      	name = "testconfiguration1"
  2177      	subnet_id = "${azurerm_subnet.test.id}"
  2178      	private_ip_address_allocation = "dynamic"
  2179      }
  2180  }
  2181  
  2182  resource "azurerm_storage_account" "test" {
  2183      name = "accsa%d"
  2184      resource_group_name = "${azurerm_resource_group.test.name}"
  2185      location = "West US 2"
  2186      account_type = "Standard_LRS"
  2187  
  2188      tags {
  2189          environment = "staging"
  2190      }
  2191  }
  2192  
  2193  resource "azurerm_storage_container" "test" {
  2194      name = "vhds"
  2195      resource_group_name = "${azurerm_resource_group.test.name}"
  2196      storage_account_name = "${azurerm_storage_account.test.name}"
  2197      container_access_type = "private"
  2198  }
  2199  
  2200  resource "azurerm_virtual_machine" "test" {
  2201      name = "acctvm-%d"
  2202      location = "West US 2"
  2203      resource_group_name = "${azurerm_resource_group.test.name}"
  2204      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2205      vm_size = "Standard_D1_v2"
  2206  
  2207      storage_image_reference {
  2208  	publisher = "MicrosoftWindowsServer"
  2209  	offer = "WindowsServer"
  2210  	sku = "2012-Datacenter"
  2211  	version = "latest"
  2212      }
  2213  
  2214      storage_os_disk {
  2215          name = "myosdisk1"
  2216          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2217          caching = "ReadWrite"
  2218          create_option = "FromImage"
  2219      }
  2220  
  2221      os_profile {
  2222  	computer_name = "winhost01"
  2223  	admin_username = "testadmin"
  2224  	admin_password = "Password1234!"
  2225      }
  2226  
  2227      os_profile_windows_config {
  2228          provision_vm_agent = true
  2229          additional_unattend_config {
  2230              pass = "oobeSystem"
  2231              component = "Microsoft-Windows-Shell-Setup"
  2232              setting_name = "FirstLogonCommands"
  2233              content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
  2234          }
  2235      }
  2236  
  2237  }
  2238  `
  2239  
  2240  var testAccAzureRMVirtualMachine_diagnosticsProfile = `
  2241  resource "azurerm_resource_group" "test" {
  2242      name = "acctestRG-%d"
  2243      location = "West US 2"
  2244  }
  2245  
  2246  resource "azurerm_virtual_network" "test" {
  2247      name = "acctvn-%d"
  2248      address_space = ["10.0.0.0/16"]
  2249      location = "West US 2"
  2250      resource_group_name = "${azurerm_resource_group.test.name}"
  2251  }
  2252  
  2253  resource "azurerm_subnet" "test" {
  2254      name = "acctsub-%d"
  2255      resource_group_name = "${azurerm_resource_group.test.name}"
  2256      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2257      address_prefix = "10.0.2.0/24"
  2258  }
  2259  
  2260  resource "azurerm_network_interface" "test" {
  2261      name = "acctni-%d"
  2262      location = "West US 2"
  2263      resource_group_name = "${azurerm_resource_group.test.name}"
  2264  
  2265      ip_configuration {
  2266          name = "testconfiguration1"
  2267          subnet_id = "${azurerm_subnet.test.id}"
  2268          private_ip_address_allocation = "dynamic"
  2269      }
  2270  }
  2271  
  2272  resource "azurerm_storage_account" "test" {
  2273      name = "accsa%d"
  2274      resource_group_name = "${azurerm_resource_group.test.name}"
  2275      location = "West US 2"
  2276      account_type = "Standard_LRS"
  2277  
  2278      tags {
  2279          environment = "staging"
  2280      }
  2281  }
  2282  
  2283  resource "azurerm_storage_container" "test" {
  2284      name = "vhds"
  2285      resource_group_name = "${azurerm_resource_group.test.name}"
  2286      storage_account_name = "${azurerm_storage_account.test.name}"
  2287      container_access_type = "private"
  2288  }
  2289  
  2290  resource "azurerm_virtual_machine" "test" {
  2291      name = "acctvm-%d"
  2292      location = "West US 2"
  2293      resource_group_name = "${azurerm_resource_group.test.name}"
  2294      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2295      vm_size = "Standard_D1_v2"
  2296  
  2297      storage_image_reference {
  2298  	publisher = "MicrosoftWindowsServer"
  2299  	offer = "WindowsServer"
  2300  	sku = "2012-Datacenter"
  2301  	version = "latest"
  2302      }
  2303  
  2304      storage_os_disk {
  2305          name = "myosdisk1"
  2306          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2307          caching = "ReadWrite"
  2308          create_option = "FromImage"
  2309      }
  2310  
  2311      os_profile {
  2312  	computer_name = "winhost01"
  2313  	admin_username = "testadmin"
  2314  	admin_password = "Password1234!"
  2315      }
  2316  
  2317      boot_diagnostics {
  2318          enabled = true
  2319          storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}"
  2320      }
  2321  
  2322      os_profile_windows_config {
  2323          winrm {
  2324  	  protocol = "http"
  2325          }
  2326      }
  2327  }
  2328  
  2329  `
  2330  
  2331  var testAccAzureRMVirtualMachine_winRMConfig = `
  2332  resource "azurerm_resource_group" "test" {
  2333      name = "acctestRG-%d"
  2334      location = "West US 2"
  2335  }
  2336  
  2337  resource "azurerm_virtual_network" "test" {
  2338      name = "acctvn-%d"
  2339      address_space = ["10.0.0.0/16"]
  2340      location = "West US 2"
  2341      resource_group_name = "${azurerm_resource_group.test.name}"
  2342  }
  2343  
  2344  resource "azurerm_subnet" "test" {
  2345      name = "acctsub-%d"
  2346      resource_group_name = "${azurerm_resource_group.test.name}"
  2347      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2348      address_prefix = "10.0.2.0/24"
  2349  }
  2350  
  2351  resource "azurerm_network_interface" "test" {
  2352      name = "acctni-%d"
  2353      location = "West US 2"
  2354      resource_group_name = "${azurerm_resource_group.test.name}"
  2355  
  2356      ip_configuration {
  2357      	name = "testconfiguration1"
  2358      	subnet_id = "${azurerm_subnet.test.id}"
  2359      	private_ip_address_allocation = "dynamic"
  2360      }
  2361  }
  2362  
  2363  resource "azurerm_storage_account" "test" {
  2364      name = "accsa%d"
  2365      resource_group_name = "${azurerm_resource_group.test.name}"
  2366      location = "West US 2"
  2367      account_type = "Standard_LRS"
  2368  
  2369      tags {
  2370          environment = "staging"
  2371      }
  2372  }
  2373  
  2374  resource "azurerm_storage_container" "test" {
  2375      name = "vhds"
  2376      resource_group_name = "${azurerm_resource_group.test.name}"
  2377      storage_account_name = "${azurerm_storage_account.test.name}"
  2378      container_access_type = "private"
  2379  }
  2380  
  2381  resource "azurerm_virtual_machine" "test" {
  2382      name = "acctvm-%d"
  2383      location = "West US 2"
  2384      resource_group_name = "${azurerm_resource_group.test.name}"
  2385      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2386      vm_size = "Standard_D1_v2"
  2387  
  2388      storage_image_reference {
  2389  	publisher = "MicrosoftWindowsServer"
  2390  	offer = "WindowsServer"
  2391  	sku = "2012-Datacenter"
  2392  	version = "latest"
  2393      }
  2394  
  2395      storage_os_disk {
  2396          name = "myosdisk1"
  2397          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2398          caching = "ReadWrite"
  2399          create_option = "FromImage"
  2400      }
  2401  
  2402      os_profile {
  2403  	computer_name = "winhost01"
  2404  	admin_username = "testadmin"
  2405  	admin_password = "Password1234!"
  2406      }
  2407  
  2408      os_profile_windows_config {
  2409          winrm {
  2410  	  protocol = "http"
  2411          }
  2412      }
  2413  }
  2414  `
  2415  
  2416  var testAccAzureRMVirtualMachine_withAvailabilitySet = `
  2417   resource "azurerm_resource_group" "test" {
  2418       name = "acctestRG-%d"
  2419       location = "West US 2"
  2420   }
  2421  
  2422   resource "azurerm_virtual_network" "test" {
  2423       name = "acctvn-%d"
  2424       address_space = ["10.0.0.0/16"]
  2425       location = "West US 2"
  2426       resource_group_name = "${azurerm_resource_group.test.name}"
  2427   }
  2428  
  2429   resource "azurerm_subnet" "test" {
  2430       name = "acctsub-%d"
  2431       resource_group_name = "${azurerm_resource_group.test.name}"
  2432       virtual_network_name = "${azurerm_virtual_network.test.name}"
  2433       address_prefix = "10.0.2.0/24"
  2434   }
  2435  
  2436   resource "azurerm_network_interface" "test" {
  2437       name = "acctni-%d"
  2438       location = "West US 2"
  2439       resource_group_name = "${azurerm_resource_group.test.name}"
  2440  
  2441       ip_configuration {
  2442       	name = "testconfiguration1"
  2443       	subnet_id = "${azurerm_subnet.test.id}"
  2444       	private_ip_address_allocation = "dynamic"
  2445       }
  2446   }
  2447  
  2448   resource "azurerm_storage_account" "test" {
  2449       name = "accsa%d"
  2450       resource_group_name = "${azurerm_resource_group.test.name}"
  2451       location = "West US 2"
  2452       account_type = "Standard_LRS"
  2453  
  2454       tags {
  2455           environment = "staging"
  2456       }
  2457   }
  2458  
  2459   resource "azurerm_availability_set" "test" {
  2460      name = "availabilityset%d"
  2461      location = "West US 2"
  2462      resource_group_name = "${azurerm_resource_group.test.name}"
  2463  }
  2464  
  2465   resource "azurerm_storage_container" "test" {
  2466       name = "vhds"
  2467       resource_group_name = "${azurerm_resource_group.test.name}"
  2468       storage_account_name = "${azurerm_storage_account.test.name}"
  2469       container_access_type = "private"
  2470   }
  2471  
  2472   resource "azurerm_virtual_machine" "test" {
  2473       name = "acctvm-%d"
  2474       location = "West US 2"
  2475       resource_group_name = "${azurerm_resource_group.test.name}"
  2476       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2477       vm_size = "Standard_D1_v2"
  2478       availability_set_id = "${azurerm_availability_set.test.id}"
  2479       delete_os_disk_on_termination = true
  2480  
  2481       storage_image_reference {
  2482   	publisher = "Canonical"
  2483   	offer = "UbuntuServer"
  2484   	sku = "14.04.2-LTS"
  2485   	version = "latest"
  2486       }
  2487  
  2488       storage_os_disk {
  2489           name = "myosdisk1"
  2490           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2491           caching = "ReadWrite"
  2492           create_option = "FromImage"
  2493       }
  2494  
  2495       os_profile {
  2496   	computer_name = "hn%d"
  2497   	admin_username = "testadmin"
  2498   	admin_password = "Password1234!"
  2499       }
  2500  
  2501       os_profile_linux_config {
  2502   	disable_password_authentication = false
  2503       }
  2504   }
  2505  `
  2506  
  2507  var testAccAzureRMVirtualMachine_updateAvailabilitySet = `
  2508   resource "azurerm_resource_group" "test" {
  2509       name = "acctestRG-%d"
  2510       location = "West US 2"
  2511   }
  2512  
  2513   resource "azurerm_virtual_network" "test" {
  2514       name = "acctvn-%d"
  2515       address_space = ["10.0.0.0/16"]
  2516       location = "West US 2"
  2517       resource_group_name = "${azurerm_resource_group.test.name}"
  2518   }
  2519  
  2520   resource "azurerm_subnet" "test" {
  2521       name = "acctsub-%d"
  2522       resource_group_name = "${azurerm_resource_group.test.name}"
  2523       virtual_network_name = "${azurerm_virtual_network.test.name}"
  2524       address_prefix = "10.0.2.0/24"
  2525   }
  2526  
  2527   resource "azurerm_network_interface" "test" {
  2528       name = "acctni-%d"
  2529       location = "West US 2"
  2530       resource_group_name = "${azurerm_resource_group.test.name}"
  2531  
  2532       ip_configuration {
  2533       	name = "testconfiguration1"
  2534       	subnet_id = "${azurerm_subnet.test.id}"
  2535       	private_ip_address_allocation = "dynamic"
  2536       }
  2537   }
  2538  
  2539   resource "azurerm_storage_account" "test" {
  2540       name = "accsa%d"
  2541       resource_group_name = "${azurerm_resource_group.test.name}"
  2542       location = "West US 2"
  2543       account_type = "Standard_LRS"
  2544  
  2545       tags {
  2546           environment = "staging"
  2547       }
  2548   }
  2549  
  2550   resource "azurerm_availability_set" "test" {
  2551      name = "updatedAvailabilitySet%d"
  2552      location = "West US 2"
  2553      resource_group_name = "${azurerm_resource_group.test.name}"
  2554  }
  2555  
  2556   resource "azurerm_storage_container" "test" {
  2557       name = "vhds"
  2558       resource_group_name = "${azurerm_resource_group.test.name}"
  2559       storage_account_name = "${azurerm_storage_account.test.name}"
  2560       container_access_type = "private"
  2561   }
  2562  
  2563   resource "azurerm_virtual_machine" "test" {
  2564       name = "acctvm-%d"
  2565       location = "West US 2"
  2566       resource_group_name = "${azurerm_resource_group.test.name}"
  2567       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2568       vm_size = "Standard_D1_v2"
  2569       availability_set_id = "${azurerm_availability_set.test.id}"
  2570       delete_os_disk_on_termination = true
  2571  
  2572       storage_image_reference {
  2573   	publisher = "Canonical"
  2574   	offer = "UbuntuServer"
  2575   	sku = "14.04.2-LTS"
  2576   	version = "latest"
  2577       }
  2578  
  2579       storage_os_disk {
  2580           name = "myosdisk1"
  2581           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2582           caching = "ReadWrite"
  2583           create_option = "FromImage"
  2584       }
  2585  
  2586       os_profile {
  2587   	computer_name = "hn%d"
  2588   	admin_username = "testadmin"
  2589   	admin_password = "Password1234!"
  2590       }
  2591  
  2592       os_profile_linux_config {
  2593   	disable_password_authentication = false
  2594       }
  2595   }
  2596  `
  2597  
  2598  var testAccAzureRMVirtualMachine_updateMachineName = `
  2599   resource "azurerm_resource_group" "test" {
  2600       name = "acctestRG-%d"
  2601       location = "West US 2"
  2602   }
  2603  
  2604   resource "azurerm_virtual_network" "test" {
  2605       name = "acctvn-%d"
  2606       address_space = ["10.0.0.0/16"]
  2607       location = "West US 2"
  2608       resource_group_name = "${azurerm_resource_group.test.name}"
  2609   }
  2610  
  2611   resource "azurerm_subnet" "test" {
  2612       name = "acctsub-%d"
  2613       resource_group_name = "${azurerm_resource_group.test.name}"
  2614       virtual_network_name = "${azurerm_virtual_network.test.name}"
  2615       address_prefix = "10.0.2.0/24"
  2616   }
  2617  
  2618   resource "azurerm_network_interface" "test" {
  2619       name = "acctni-%d"
  2620       location = "West US 2"
  2621       resource_group_name = "${azurerm_resource_group.test.name}"
  2622  
  2623       ip_configuration {
  2624       	name = "testconfiguration1"
  2625       	subnet_id = "${azurerm_subnet.test.id}"
  2626       	private_ip_address_allocation = "dynamic"
  2627       }
  2628   }
  2629  
  2630   resource "azurerm_storage_account" "test" {
  2631       name = "accsa%d"
  2632       resource_group_name = "${azurerm_resource_group.test.name}"
  2633       location = "West US 2"
  2634       account_type = "Standard_LRS"
  2635  
  2636       tags {
  2637           environment = "staging"
  2638       }
  2639   }
  2640  
  2641   resource "azurerm_storage_container" "test" {
  2642       name = "vhds"
  2643       resource_group_name = "${azurerm_resource_group.test.name}"
  2644       storage_account_name = "${azurerm_storage_account.test.name}"
  2645       container_access_type = "private"
  2646   }
  2647  
  2648   resource "azurerm_virtual_machine" "test" {
  2649       name = "acctvm-%d"
  2650       location = "West US 2"
  2651       resource_group_name = "${azurerm_resource_group.test.name}"
  2652       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2653       vm_size = "Standard_D1_v2"
  2654        delete_os_disk_on_termination = true
  2655  
  2656       storage_image_reference {
  2657   	publisher = "Canonical"
  2658   	offer = "UbuntuServer"
  2659   	sku = "14.04.2-LTS"
  2660   	version = "latest"
  2661       }
  2662  
  2663       storage_os_disk {
  2664           name = "myosdisk1"
  2665           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2666           caching = "ReadWrite"
  2667           create_option = "FromImage"
  2668       }
  2669  
  2670       os_profile {
  2671   	computer_name = "newhostname%d"
  2672   	admin_username = "testadmin"
  2673   	admin_password = "Password1234!"
  2674       }
  2675  
  2676       os_profile_linux_config {
  2677   	disable_password_authentication = false
  2678       }
  2679   }
  2680   `
  2681  
  2682  var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore = `
  2683  resource "azurerm_resource_group" "test" {
  2684      name = "acctestRG-%d"
  2685      location = "West US 2"
  2686  }
  2687  
  2688  resource "azurerm_virtual_network" "test" {
  2689      name = "acctvn-%d"
  2690      address_space = ["10.0.0.0/16"]
  2691      location = "West US 2"
  2692      resource_group_name = "${azurerm_resource_group.test.name}"
  2693  }
  2694  
  2695  resource "azurerm_subnet" "test" {
  2696      name = "acctsub-%d"
  2697      resource_group_name = "${azurerm_resource_group.test.name}"
  2698      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2699      address_prefix = "10.0.2.0/24"
  2700  }
  2701  
  2702  resource "azurerm_network_interface" "test" {
  2703      name = "acctni-%d"
  2704      location = "West US 2"
  2705      resource_group_name = "${azurerm_resource_group.test.name}"
  2706  
  2707      ip_configuration {
  2708      	name = "testconfiguration1"
  2709      	subnet_id = "${azurerm_subnet.test.id}"
  2710      	private_ip_address_allocation = "dynamic"
  2711      }
  2712  }
  2713  
  2714  resource "azurerm_storage_account" "test" {
  2715      name = "accsa%d"
  2716      resource_group_name = "${azurerm_resource_group.test.name}"
  2717      location = "West US 2"
  2718      account_type = "Standard_LRS"
  2719  
  2720      tags {
  2721          environment = "staging"
  2722      }
  2723  }
  2724  
  2725  resource "azurerm_storage_container" "test" {
  2726      name = "vhds"
  2727      resource_group_name = "${azurerm_resource_group.test.name}"
  2728      storage_account_name = "${azurerm_storage_account.test.name}"
  2729      container_access_type = "private"
  2730  }
  2731  
  2732  resource "azurerm_virtual_machine" "test" {
  2733      name = "acctvm-%d"
  2734      location = "West US 2"
  2735      resource_group_name = "${azurerm_resource_group.test.name}"
  2736      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2737      vm_size = "Standard_D1_v2"
  2738      delete_os_disk_on_termination = true
  2739  
  2740      storage_image_reference {
  2741  	publisher = "Canonical"
  2742  	offer = "UbuntuServer"
  2743  	sku = "14.04.2-LTS"
  2744  	version = "latest"
  2745      }
  2746  
  2747      storage_os_disk {
  2748          name = "myosdisk1"
  2749          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2750          caching = "ReadWrite"
  2751          create_option = "FromImage"
  2752          disk_size_gb = "45"
  2753      }
  2754  
  2755      os_profile {
  2756  	computer_name = "hn%d"
  2757  	admin_username = "testadmin"
  2758  	admin_password = "Password1234!"
  2759      }
  2760  
  2761      os_profile_linux_config {
  2762  	disable_password_authentication = false
  2763      }
  2764  
  2765      tags {
  2766      	environment = "Production"
  2767      	cost-center = "Ops"
  2768      }
  2769  }
  2770  `
  2771  
  2772  var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter = `
  2773  resource "azurerm_resource_group" "test" {
  2774      name = "acctestRG-%d"
  2775      location = "West US 2"
  2776  }
  2777  
  2778  resource "azurerm_virtual_network" "test" {
  2779      name = "acctvn-%d"
  2780      address_space = ["10.0.0.0/16"]
  2781      location = "West US 2"
  2782      resource_group_name = "${azurerm_resource_group.test.name}"
  2783  }
  2784  
  2785  resource "azurerm_subnet" "test" {
  2786      name = "acctsub-%d"
  2787      resource_group_name = "${azurerm_resource_group.test.name}"
  2788      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2789      address_prefix = "10.0.2.0/24"
  2790  }
  2791  
  2792  resource "azurerm_network_interface" "test" {
  2793      name = "acctni-%d"
  2794      location = "West US 2"
  2795      resource_group_name = "${azurerm_resource_group.test.name}"
  2796  
  2797      ip_configuration {
  2798      	name = "testconfiguration1"
  2799      	subnet_id = "${azurerm_subnet.test.id}"
  2800      	private_ip_address_allocation = "dynamic"
  2801      }
  2802  }
  2803  
  2804  resource "azurerm_storage_account" "test" {
  2805      name = "accsa%d"
  2806      resource_group_name = "${azurerm_resource_group.test.name}"
  2807      location = "West US 2"
  2808      account_type = "Standard_LRS"
  2809  
  2810      tags {
  2811          environment = "staging"
  2812      }
  2813  }
  2814  
  2815  resource "azurerm_storage_container" "test" {
  2816      name = "vhds"
  2817      resource_group_name = "${azurerm_resource_group.test.name}"
  2818      storage_account_name = "${azurerm_storage_account.test.name}"
  2819      container_access_type = "private"
  2820  }
  2821  
  2822  resource "azurerm_virtual_machine" "test" {
  2823      name = "acctvm-%d"
  2824      location = "West US 2"
  2825      resource_group_name = "${azurerm_resource_group.test.name}"
  2826      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2827      vm_size = "Standard_D1_v2"
  2828      delete_os_disk_on_termination = true
  2829  
  2830      storage_image_reference {
  2831  	publisher = "CoreOS"
  2832  	offer = "CoreOS"
  2833  	sku = "Stable"
  2834  	version = "latest"
  2835      }
  2836  
  2837      storage_os_disk {
  2838          name = "myosdisk1"
  2839          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2840          caching = "ReadWrite"
  2841          create_option = "FromImage"
  2842          disk_size_gb = "45"
  2843      }
  2844  
  2845      os_profile {
  2846  	computer_name = "hn%d"
  2847  	admin_username = "testadmin"
  2848  	admin_password = "Password1234!"
  2849      }
  2850  
  2851      os_profile_linux_config {
  2852  	disable_password_authentication = false
  2853      }
  2854  
  2855      tags {
  2856      	environment = "Production"
  2857      	cost-center = "Ops"
  2858      }
  2859  }
  2860  `
  2861  
  2862  var testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged = `
  2863  resource "azurerm_resource_group" "test" {
  2864      name = "acctestRG-%d"
  2865      location = "West US 2"
  2866  }
  2867  
  2868  resource "azurerm_virtual_network" "test" {
  2869      name = "acctvn-%d"
  2870      address_space = ["10.0.0.0/16"]
  2871      location = "West US 2"
  2872      resource_group_name = "${azurerm_resource_group.test.name}"
  2873  }
  2874  
  2875  resource "azurerm_subnet" "test" {
  2876      name = "acctsub-%d"
  2877      resource_group_name = "${azurerm_resource_group.test.name}"
  2878      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2879      address_prefix = "10.0.2.0/24"
  2880  }
  2881  
  2882  resource "azurerm_network_interface" "test" {
  2883      name = "acctni-%d"
  2884      location = "West US 2"
  2885      resource_group_name = "${azurerm_resource_group.test.name}"
  2886  
  2887      ip_configuration {
  2888      	name = "testconfiguration1"
  2889      	subnet_id = "${azurerm_subnet.test.id}"
  2890      	private_ip_address_allocation = "dynamic"
  2891      }
  2892  }
  2893  
  2894  resource "azurerm_storage_account" "test" {
  2895      name = "accsa%d"
  2896      resource_group_name = "${azurerm_resource_group.test.name}"
  2897      location = "West US 2"
  2898      account_type = "Standard_LRS"
  2899  
  2900      tags {
  2901          environment = "staging"
  2902      }
  2903  }
  2904  
  2905  resource "azurerm_storage_container" "test" {
  2906      name = "vhds"
  2907      resource_group_name = "${azurerm_resource_group.test.name}"
  2908      storage_account_name = "${azurerm_storage_account.test.name}"
  2909      container_access_type = "private"
  2910  }
  2911  
  2912  resource "azurerm_virtual_machine" "test" {
  2913      name = "acctvm-%d"
  2914      location = "West US 2"
  2915      resource_group_name = "${azurerm_resource_group.test.name}"
  2916      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2917      vm_size = "Standard_D1_v2"
  2918  
  2919      storage_image_reference {
  2920  	publisher = "Canonical"
  2921  	offer = "UbuntuServer"
  2922  	sku = "14.04.2-LTS"
  2923  	version = "latest"
  2924      }
  2925  
  2926      storage_os_disk {
  2927          name = "myosdisk1"
  2928          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdiskchanged2.vhd"
  2929          caching = "ReadWrite"
  2930          create_option = "FromImage"
  2931          disk_size_gb = "45"
  2932      }
  2933  
  2934      os_profile {
  2935  	computer_name = "hn%d"
  2936  	admin_username = "testadmin"
  2937  	admin_password = "Password1234!"
  2938      }
  2939  
  2940      os_profile_linux_config {
  2941  	disable_password_authentication = false
  2942      }
  2943  
  2944      tags {
  2945      	environment = "Production"
  2946      	cost-center = "Ops"
  2947      }
  2948  }
  2949  `
  2950  
  2951  var testAccAzureRMVirtualMachine_windowsLicenseType = `
  2952  resource "azurerm_resource_group" "test" {
  2953      name = "acctestRG-%d"
  2954      location = "West US 2"
  2955  }
  2956  
  2957  resource "azurerm_virtual_network" "test" {
  2958      name = "acctvn-%d"
  2959      address_space = ["10.0.0.0/16"]
  2960      location = "West US 2"
  2961      resource_group_name = "${azurerm_resource_group.test.name}"
  2962  }
  2963  
  2964  resource "azurerm_subnet" "test" {
  2965      name = "acctsub-%d"
  2966      resource_group_name = "${azurerm_resource_group.test.name}"
  2967      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2968      address_prefix = "10.0.2.0/24"
  2969  }
  2970  
  2971  resource "azurerm_network_interface" "test" {
  2972      name = "acctni-%d"
  2973      location = "West US 2"
  2974      resource_group_name = "${azurerm_resource_group.test.name}"
  2975  
  2976      ip_configuration {
  2977      	name = "testconfiguration1"
  2978      	subnet_id = "${azurerm_subnet.test.id}"
  2979      	private_ip_address_allocation = "dynamic"
  2980      }
  2981  }
  2982  
  2983  resource "azurerm_storage_account" "test" {
  2984      name = "accsa%d"
  2985      resource_group_name = "${azurerm_resource_group.test.name}"
  2986      location = "West US 2"
  2987      account_type = "Standard_LRS"
  2988  
  2989      tags {
  2990          environment = "staging"
  2991      }
  2992  }
  2993  
  2994  resource "azurerm_storage_container" "test" {
  2995      name = "vhds"
  2996      resource_group_name = "${azurerm_resource_group.test.name}"
  2997      storage_account_name = "${azurerm_storage_account.test.name}"
  2998      container_access_type = "private"
  2999  }
  3000  
  3001  resource "azurerm_virtual_machine" "test" {
  3002      name = "acctvm-%d"
  3003      location = "West US 2"
  3004      resource_group_name = "${azurerm_resource_group.test.name}"
  3005      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3006      vm_size = "Standard_D1_v2"
  3007      license_type = "Windows_Server"
  3008  
  3009      storage_image_reference {
  3010  	publisher = "MicrosoftWindowsServer"
  3011  	offer = "WindowsServer-HUB"
  3012  	sku = "2008-R2-SP1-HUB"
  3013  	version = "latest"
  3014      }
  3015  
  3016      storage_os_disk {
  3017          name = "myosdisk1"
  3018          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3019          caching = "ReadWrite"
  3020          create_option = "FromImage"
  3021      }
  3022  
  3023      os_profile {
  3024  	computer_name = "winhost01"
  3025  	admin_username = "testadmin"
  3026  	admin_password = "Password1234!"
  3027      }
  3028  
  3029      os_profile_windows_config {
  3030  	enable_automatic_upgrades = false
  3031  	provision_vm_agent = true
  3032      }
  3033  }
  3034  `
  3035  
  3036  var testAccAzureRMVirtualMachine_plan = `
  3037  resource "azurerm_resource_group" "test" {
  3038      name = "acctestRG-%d"
  3039      location = "West US 2"
  3040  }
  3041  
  3042  resource "azurerm_virtual_network" "test" {
  3043      name = "acctvn-%d"
  3044      address_space = ["10.0.0.0/16"]
  3045      location = "West US 2"
  3046      resource_group_name = "${azurerm_resource_group.test.name}"
  3047  }
  3048  
  3049  resource "azurerm_subnet" "test" {
  3050      name = "acctsub-%d"
  3051      resource_group_name = "${azurerm_resource_group.test.name}"
  3052      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3053      address_prefix = "10.0.2.0/24"
  3054  }
  3055  
  3056  resource "azurerm_network_interface" "test" {
  3057      name = "acctni-%d"
  3058      location = "West US 2"
  3059      resource_group_name = "${azurerm_resource_group.test.name}"
  3060  
  3061      ip_configuration {
  3062      	name = "testconfiguration1"
  3063      	subnet_id = "${azurerm_subnet.test.id}"
  3064      	private_ip_address_allocation = "dynamic"
  3065      }
  3066  }
  3067  
  3068  resource "azurerm_storage_account" "test" {
  3069      name = "accsa%d"
  3070      resource_group_name = "${azurerm_resource_group.test.name}"
  3071      location = "West US 2"
  3072      account_type = "Standard_LRS"
  3073  
  3074      tags {
  3075          environment = "staging"
  3076      }
  3077  }
  3078  
  3079  resource "azurerm_storage_container" "test" {
  3080      name = "vhds"
  3081      resource_group_name = "${azurerm_resource_group.test.name}"
  3082      storage_account_name = "${azurerm_storage_account.test.name}"
  3083      container_access_type = "private"
  3084  }
  3085  
  3086  resource "azurerm_virtual_machine" "test" {
  3087      name = "acctvm-%d"
  3088      location = "West US 2"
  3089      resource_group_name = "${azurerm_resource_group.test.name}"
  3090      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3091      vm_size = "Standard_DS1_v2"
  3092  
  3093      storage_image_reference {
  3094  	publisher = "kemptech"
  3095  	offer = "vlm-azure"
  3096  	sku = "freeloadmaster"
  3097  	version = "latest"
  3098      }
  3099  
  3100      storage_os_disk {
  3101          name = "myosdisk1"
  3102          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3103          caching = "ReadWrite"
  3104          create_option = "FromImage"
  3105          disk_size_gb = "45"
  3106      }
  3107  
  3108      os_profile {
  3109  	computer_name = "hn%d"
  3110  	admin_username = "testadmin"
  3111  	admin_password = "Password1234!"
  3112      }
  3113  
  3114      os_profile_linux_config {
  3115  	disable_password_authentication = false
  3116      }
  3117  
  3118      plan {
  3119          name = "freeloadmaster"
  3120          publisher = "kemptech"
  3121          product = "vlm-azure"
  3122      }
  3123  
  3124      tags {
  3125      	environment = "Production"
  3126      	cost-center = "Ops"
  3127      }
  3128  }
  3129  `
  3130  
  3131  var testAccAzureRMVirtualMachine_linuxMachineWithSSH = `
  3132  resource "azurerm_resource_group" "test" {
  3133      name = "acctestrg%s"
  3134      location = "southcentralus"
  3135  }
  3136  
  3137  resource "azurerm_virtual_network" "test" {
  3138      name = "acctvn%s"
  3139      address_space = ["10.0.0.0/16"]
  3140      location = "southcentralus"
  3141      resource_group_name = "${azurerm_resource_group.test.name}"
  3142  }
  3143  
  3144  resource "azurerm_subnet" "test" {
  3145      name = "acctsub%s"
  3146      resource_group_name = "${azurerm_resource_group.test.name}"
  3147      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3148      address_prefix = "10.0.2.0/24"
  3149  }
  3150  
  3151  resource "azurerm_network_interface" "test" {
  3152      name = "acctni%s"
  3153      location = "southcentralus"
  3154      resource_group_name = "${azurerm_resource_group.test.name}"
  3155  
  3156      ip_configuration {
  3157      	name = "testconfiguration1"
  3158      	subnet_id = "${azurerm_subnet.test.id}"
  3159      	private_ip_address_allocation = "dynamic"
  3160      }
  3161  }
  3162  
  3163  resource "azurerm_storage_account" "test" {
  3164      name = "accsa%s"
  3165      resource_group_name = "${azurerm_resource_group.test.name}"
  3166      location = "southcentralus"
  3167      account_type = "Standard_LRS"
  3168  }
  3169  
  3170  resource "azurerm_storage_container" "test" {
  3171      name = "vhds"
  3172      resource_group_name = "${azurerm_resource_group.test.name}"
  3173      storage_account_name = "${azurerm_storage_account.test.name}"
  3174      container_access_type = "private"
  3175  }
  3176  
  3177  resource "azurerm_virtual_machine" "test" {
  3178      name = "acctvm%s"
  3179      location = "southcentralus"
  3180      resource_group_name = "${azurerm_resource_group.test.name}"
  3181      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3182      vm_size = "Standard_D1_v2"
  3183  
  3184      storage_image_reference {
  3185          publisher = "Canonical"
  3186          offer = "UbuntuServer"
  3187          sku = "14.04.2-LTS"
  3188          version = "latest"
  3189      }
  3190  
  3191      storage_os_disk {
  3192          name = "myosdisk1"
  3193          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3194          caching = "ReadWrite"
  3195          create_option = "FromImage"
  3196          disk_size_gb = "45"
  3197      }
  3198  
  3199      os_profile {
  3200          computer_name = "hostname%s"
  3201          admin_username = "testadmin"
  3202          admin_password = "Password1234!"
  3203      }
  3204  
  3205      os_profile_linux_config {
  3206  	    disable_password_authentication = true
  3207          ssh_keys {
  3208              path = "/home/testadmin/.ssh/authorized_keys"
  3209              key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCfGyt5W1eJVpDIxlyvAWO594j/azEGohmlxYe7mgSfmUCWjuzILI6nHuHbxhpBDIZJhQ+JAeduXpii61dmThbI89ghGMhzea0OlT3p12e093zqa4goB9g40jdNKmJArER3pMVqs6hmv8y3GlUNkMDSmuoyI8AYzX4n26cUKZbwXQ== mk@mk3"
  3210          }
  3211      }
  3212  }
  3213  `
  3214  
  3215  var testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved = `
  3216  resource "azurerm_resource_group" "test" {
  3217      name = "acctestrg%s"
  3218      location = "southcentralus"
  3219  }
  3220  
  3221  resource "azurerm_virtual_network" "test" {
  3222      name = "acctvn%s"
  3223      address_space = ["10.0.0.0/16"]
  3224      location = "southcentralus"
  3225      resource_group_name = "${azurerm_resource_group.test.name}"
  3226  }
  3227  
  3228  resource "azurerm_subnet" "test" {
  3229      name = "acctsub%s"
  3230      resource_group_name = "${azurerm_resource_group.test.name}"
  3231      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3232      address_prefix = "10.0.2.0/24"
  3233  }
  3234  
  3235  resource "azurerm_network_interface" "test" {
  3236      name = "acctni%s"
  3237      location = "southcentralus"
  3238      resource_group_name = "${azurerm_resource_group.test.name}"
  3239  
  3240      ip_configuration {
  3241      	name = "testconfiguration1"
  3242      	subnet_id = "${azurerm_subnet.test.id}"
  3243      	private_ip_address_allocation = "dynamic"
  3244      }
  3245  }
  3246  
  3247  resource "azurerm_storage_account" "test" {
  3248      name = "accsa%s"
  3249      resource_group_name = "${azurerm_resource_group.test.name}"
  3250      location = "southcentralus"
  3251      account_type = "Standard_LRS"
  3252  }
  3253  
  3254  resource "azurerm_storage_container" "test" {
  3255      name = "vhds"
  3256      resource_group_name = "${azurerm_resource_group.test.name}"
  3257      storage_account_name = "${azurerm_storage_account.test.name}"
  3258      container_access_type = "private"
  3259  }
  3260  
  3261  resource "azurerm_virtual_machine" "test" {
  3262      name = "acctvm%s"
  3263      location = "southcentralus"
  3264      resource_group_name = "${azurerm_resource_group.test.name}"
  3265      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3266      vm_size = "Standard_D1_v2"
  3267  
  3268      storage_image_reference {
  3269          publisher = "Canonical"
  3270          offer = "UbuntuServer"
  3271          sku = "14.04.2-LTS"
  3272          version = "latest"
  3273      }
  3274  
  3275      storage_os_disk {
  3276          name = "myosdisk1"
  3277          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3278          caching = "ReadWrite"
  3279          create_option = "FromImage"
  3280          disk_size_gb = "45"
  3281      }
  3282  
  3283      os_profile {
  3284          computer_name = "hostname%s"
  3285          admin_username = "testadmin"
  3286          admin_password = "Password1234!"
  3287      }
  3288  
  3289      os_profile_linux_config {
  3290  	    disable_password_authentication = true
  3291      }
  3292  }
  3293  `
  3294  var testAccAzureRMVirtualMachine_osDiskTypeConflict = `
  3295  resource "azurerm_resource_group" "test" {
  3296      name = "acctestRG-%d"
  3297      location = "West US 2"
  3298  }
  3299  
  3300  resource "azurerm_virtual_network" "test" {
  3301      name = "acctvn-%d"
  3302      address_space = ["10.0.0.0/16"]
  3303      location = "West US 2"
  3304      resource_group_name = "${azurerm_resource_group.test.name}"
  3305  }
  3306  
  3307  resource "azurerm_subnet" "test" {
  3308      name = "acctsub-%d"
  3309      resource_group_name = "${azurerm_resource_group.test.name}"
  3310      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3311      address_prefix = "10.0.2.0/24"
  3312  }
  3313  
  3314  resource "azurerm_network_interface" "test" {
  3315      name = "acctni-%d"
  3316      location = "West US 2"
  3317      resource_group_name = "${azurerm_resource_group.test.name}"
  3318  
  3319      ip_configuration {
  3320      	name = "testconfiguration1"
  3321      	subnet_id = "${azurerm_subnet.test.id}"
  3322      	private_ip_address_allocation = "dynamic"
  3323      }
  3324  }
  3325  
  3326  resource "azurerm_virtual_machine" "test" {
  3327      name = "acctvm-%d"
  3328      location = "West US 2"
  3329      resource_group_name = "${azurerm_resource_group.test.name}"
  3330      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3331      vm_size = "Standard_D1_v2"
  3332  
  3333      storage_image_reference {
  3334  	publisher = "Canonical"
  3335  	offer = "UbuntuServer"
  3336  	sku = "14.04.2-LTS"
  3337  	version = "latest"
  3338      }
  3339  
  3340      storage_os_disk {
  3341          name = "osd-%d"
  3342          caching = "ReadWrite"
  3343          create_option = "FromImage"
  3344          disk_size_gb = "10"
  3345          managed_disk_type = "Standard_LRS"
  3346          vhd_uri = "should_cause_conflict"
  3347      }
  3348  
  3349      storage_data_disk {
  3350          name = "mydatadisk1"
  3351          caching = "ReadWrite"
  3352          create_option = "Empty"
  3353          disk_size_gb = "45"
  3354          managed_disk_type = "Standard_LRS"
  3355          lun = "0"
  3356      }
  3357  
  3358      os_profile {
  3359  	computer_name = "hn%d"
  3360  	admin_username = "testadmin"
  3361  	admin_password = "Password1234!"
  3362      }
  3363  
  3364      os_profile_linux_config {
  3365  	disable_password_authentication = false
  3366      }
  3367  
  3368      tags {
  3369      	environment = "Production"
  3370      	cost-center = "Ops"
  3371      }
  3372  }
  3373  `
  3374  
  3375  var testAccAzureRMVirtualMachine_dataDiskTypeConflict = `
  3376  resource "azurerm_resource_group" "test" {
  3377      name = "acctestRG-%d"
  3378      location = "West US 2"
  3379  }
  3380  
  3381  resource "azurerm_virtual_network" "test" {
  3382      name = "acctvn-%d"
  3383      address_space = ["10.0.0.0/16"]
  3384      location = "West US 2"
  3385      resource_group_name = "${azurerm_resource_group.test.name}"
  3386  }
  3387  
  3388  resource "azurerm_subnet" "test" {
  3389      name = "acctsub-%d"
  3390      resource_group_name = "${azurerm_resource_group.test.name}"
  3391      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3392      address_prefix = "10.0.2.0/24"
  3393  }
  3394  
  3395  resource "azurerm_network_interface" "test" {
  3396      name = "acctni-%d"
  3397      location = "West US 2"
  3398      resource_group_name = "${azurerm_resource_group.test.name}"
  3399  
  3400      ip_configuration {
  3401      	name = "testconfiguration1"
  3402      	subnet_id = "${azurerm_subnet.test.id}"
  3403      	private_ip_address_allocation = "dynamic"
  3404      }
  3405  }
  3406  
  3407  resource "azurerm_virtual_machine" "test" {
  3408      name = "acctvm-%d"
  3409      location = "West US 2"
  3410      resource_group_name = "${azurerm_resource_group.test.name}"
  3411      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3412      vm_size = "Standard_D1_v2"
  3413  
  3414      storage_image_reference {
  3415  	publisher = "Canonical"
  3416  	offer = "UbuntuServer"
  3417  	sku = "14.04.2-LTS"
  3418  	version = "latest"
  3419      }
  3420  
  3421      storage_os_disk {
  3422          name = "osd-%d"
  3423          caching = "ReadWrite"
  3424          create_option = "FromImage"
  3425          disk_size_gb = "10"
  3426          managed_disk_type = "Standard_LRS"
  3427      }
  3428  
  3429      storage_data_disk {
  3430          name = "mydatadisk1"
  3431          caching = "ReadWrite"
  3432          create_option = "Empty"
  3433          disk_size_gb = "45"
  3434          managed_disk_type = "Standard_LRS"
  3435          lun = "0"
  3436      }
  3437  
  3438      storage_data_disk {
  3439          name = "mydatadisk1"
  3440          vhd_uri = "should_cause_conflict"
  3441          caching = "ReadWrite"
  3442          create_option = "Empty"
  3443          disk_size_gb = "45"
  3444          managed_disk_type = "Standard_LRS"
  3445          lun = "1"
  3446      }
  3447  
  3448      os_profile {
  3449  	computer_name = "hn%d"
  3450  	admin_username = "testadmin"
  3451  	admin_password = "Password1234!"
  3452      }
  3453  
  3454      os_profile_linux_config {
  3455  	disable_password_authentication = false
  3456      }
  3457  
  3458      tags {
  3459      	environment = "Production"
  3460      	cost-center = "Ops"
  3461      }
  3462  }
  3463  `
  3464  
  3465  var testAccAzureRMVirtualMachine_primaryNetworkInterfaceId = `
  3466  resource "azurerm_resource_group" "test" {
  3467      name = "acctestRG-%d"
  3468      location = "West US"
  3469  }
  3470  
  3471  resource "azurerm_virtual_network" "test" {
  3472      name = "acctvn-%d"
  3473      address_space = ["10.0.0.0/16"]
  3474      location = "West US"
  3475      resource_group_name = "${azurerm_resource_group.test.name}"
  3476  }
  3477  
  3478  resource "azurerm_subnet" "test" {
  3479      name = "acctsub-%d"
  3480      resource_group_name = "${azurerm_resource_group.test.name}"
  3481      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3482      address_prefix = "10.0.2.0/24"
  3483  }
  3484  
  3485  resource "azurerm_network_interface" "test" {
  3486      name = "acctni-%d"
  3487      location = "West US"
  3488      resource_group_name = "${azurerm_resource_group.test.name}"
  3489  
  3490      ip_configuration {
  3491      	name = "testconfiguration1"
  3492      	subnet_id = "${azurerm_subnet.test.id}"
  3493      	private_ip_address_allocation = "dynamic"
  3494      }
  3495  }
  3496  
  3497  resource "azurerm_network_interface" "test2" {
  3498      name = "acctni2-%d"
  3499      location = "West US"
  3500      resource_group_name = "${azurerm_resource_group.test.name}"
  3501  
  3502      ip_configuration {
  3503      	name = "testconfiguration2"
  3504      	subnet_id = "${azurerm_subnet.test.id}"
  3505      	private_ip_address_allocation = "dynamic"
  3506      }
  3507  }
  3508  
  3509  resource "azurerm_storage_account" "test" {
  3510      name = "accsa%d"
  3511      resource_group_name = "${azurerm_resource_group.test.name}"
  3512      location = "westus"
  3513      account_type = "Standard_LRS"
  3514  
  3515      tags {
  3516          environment = "staging"
  3517      }
  3518  }
  3519  
  3520  resource "azurerm_storage_container" "test" {
  3521      name = "vhds"
  3522      resource_group_name = "${azurerm_resource_group.test.name}"
  3523      storage_account_name = "${azurerm_storage_account.test.name}"
  3524      container_access_type = "private"
  3525  }
  3526  
  3527  resource "azurerm_virtual_machine" "test" {
  3528      name = "acctvm-%d"
  3529      location = "West US"
  3530      resource_group_name = "${azurerm_resource_group.test.name}"
  3531      network_interface_ids = ["${azurerm_network_interface.test.id}","${azurerm_network_interface.test2.id}"]
  3532      primary_network_interface_id = "${azurerm_network_interface.test.id}"
  3533      vm_size = "Standard_A3"
  3534  
  3535      storage_image_reference {
  3536  	publisher = "Canonical"
  3537  	offer = "UbuntuServer"
  3538  	sku = "14.04.2-LTS"
  3539  	version = "latest"
  3540      }
  3541  
  3542      storage_os_disk {
  3543          name = "myosdisk1"
  3544          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3545          caching = "ReadWrite"
  3546          create_option = "FromImage"
  3547          disk_size_gb = "45"
  3548      }
  3549  
  3550      os_profile {
  3551  	computer_name = "hostname"
  3552  	admin_username = "testadmin"
  3553  	admin_password = "Password1234!"
  3554      }
  3555  
  3556      os_profile_linux_config {
  3557  	disable_password_authentication = false
  3558      }
  3559  
  3560      tags {
  3561      	environment = "Production"
  3562      	cost-center = "Ops"
  3563      }
  3564  }
  3565  `