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