github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/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  			container := storageClient.GetContainerReference(containerName)
   741  			blob := container.GetBlobReference(name)
   742  			exists, err := blob.Exists()
   743  			if err != nil {
   744  				return fmt.Errorf("Error checking if Disk VHD Blob exists: %s", err)
   745  			}
   746  
   747  			if exists && !shouldExist {
   748  				return fmt.Errorf("Disk VHD Blob still exists %s %s", containerName, name)
   749  			} else if !exists && shouldExist {
   750  				return fmt.Errorf("Disk VHD Blob should exist %s %s", containerName, name)
   751  			}
   752  		}
   753  
   754  		return nil
   755  	}
   756  }
   757  
   758  func testCheckAzureRMVirtualMachineDisappears(name string) resource.TestCheckFunc {
   759  	return func(s *terraform.State) error {
   760  		// Ensure we have enough information in state to look up in API
   761  		rs, ok := s.RootModule().Resources[name]
   762  		if !ok {
   763  			return fmt.Errorf("Not found: %s", name)
   764  		}
   765  
   766  		vmName := rs.Primary.Attributes["name"]
   767  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   768  		if !hasResourceGroup {
   769  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   770  		}
   771  
   772  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   773  
   774  		_, error := conn.Delete(resourceGroup, vmName, make(chan struct{}))
   775  		err := <-error
   776  		if err != nil {
   777  			return fmt.Errorf("Bad: Delete on vmClient: %s", err)
   778  		}
   779  
   780  		return nil
   781  	}
   782  }
   783  
   784  func TestAccAzureRMVirtualMachine_windowsLicenseType(t *testing.T) {
   785  	var vm compute.VirtualMachine
   786  	ri := acctest.RandInt()
   787  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsLicenseType, ri, ri, ri, ri, ri, ri)
   788  	resource.Test(t, resource.TestCase{
   789  		PreCheck:     func() { testAccPreCheck(t) },
   790  		Providers:    testAccProviders,
   791  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   792  		Steps: []resource.TestStep{
   793  			{
   794  				Config: config,
   795  				Check: resource.ComposeTestCheckFunc(
   796  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   797  				),
   798  			},
   799  		},
   800  	})
   801  }
   802  
   803  func TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId(t *testing.T) {
   804  	var vm compute.VirtualMachine
   805  	ri := acctest.RandInt()
   806  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_primaryNetworkInterfaceId, ri, ri, ri, ri, ri, ri, ri)
   807  	resource.Test(t, resource.TestCase{
   808  		PreCheck:     func() { testAccPreCheck(t) },
   809  		Providers:    testAccProviders,
   810  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   811  		Steps: []resource.TestStep{
   812  			{
   813  				Config: config,
   814  				Check: resource.ComposeTestCheckFunc(
   815  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   816  				),
   817  			},
   818  		},
   819  	})
   820  }
   821  
   822  func TestAccAzureRMVirtualMachine_optionalOSProfile(t *testing.T) {
   823  	var vm compute.VirtualMachine
   824  
   825  	ri := acctest.RandInt()
   826  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
   827  	prepConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_destroy, ri, ri, ri, ri, ri)
   828  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine_attach_without_osProfile, ri, ri, ri, ri, ri, ri)
   829  	resource.Test(t, resource.TestCase{
   830  		PreCheck:     func() { testAccPreCheck(t) },
   831  		Providers:    testAccProviders,
   832  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   833  		Steps: []resource.TestStep{
   834  			{
   835  				Destroy: false,
   836  				Config:  preConfig,
   837  				Check: resource.ComposeTestCheckFunc(
   838  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   839  				),
   840  			},
   841  			{
   842  				Destroy: false,
   843  				Config:  prepConfig,
   844  				Check: func(s *terraform.State) error {
   845  					testCheckAzureRMVirtualMachineDestroy(s)
   846  					return nil
   847  				},
   848  			},
   849  			{
   850  				Config: config,
   851  				Check: resource.ComposeTestCheckFunc(
   852  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
   853  				),
   854  			},
   855  		},
   856  	})
   857  }
   858  
   859  func testLookupAzureRMVirtualMachineManagedDiskID(vm *compute.VirtualMachine, diskName string, managedDiskID *string) resource.TestCheckFunc {
   860  	return func(s *terraform.State) error {
   861  		if osd := vm.StorageProfile.OsDisk; osd != nil {
   862  			if strings.EqualFold(*osd.Name, diskName) {
   863  				if osd.ManagedDisk != nil {
   864  					id, err := findAzureRMVirtualMachineManagedDiskID(osd.ManagedDisk)
   865  					if err != nil {
   866  						return fmt.Errorf("Unable to parse Managed Disk ID for OS Disk %s, %s", diskName, err)
   867  					}
   868  					*managedDiskID = id
   869  					return nil
   870  				}
   871  			}
   872  		}
   873  
   874  		for _, dataDisk := range *vm.StorageProfile.DataDisks {
   875  			if strings.EqualFold(*dataDisk.Name, diskName) {
   876  				if dataDisk.ManagedDisk != nil {
   877  					id, err := findAzureRMVirtualMachineManagedDiskID(dataDisk.ManagedDisk)
   878  					if err != nil {
   879  						return fmt.Errorf("Unable to parse Managed Disk ID for Data Disk %s, %s", diskName, err)
   880  					}
   881  					*managedDiskID = id
   882  					return nil
   883  				}
   884  			}
   885  		}
   886  
   887  		return fmt.Errorf("Unable to locate disk %s on vm %s", diskName, *vm.Name)
   888  	}
   889  }
   890  
   891  func findAzureRMVirtualMachineManagedDiskID(md *compute.ManagedDiskParameters) (string, error) {
   892  	_, err := parseAzureResourceID(*md.ID)
   893  	if err != nil {
   894  		return "", err
   895  	}
   896  	return *md.ID, nil
   897  }
   898  
   899  func testGetAzureRMVirtualMachineManagedDisk(managedDiskID *string) (*disk.Model, error) {
   900  	armID, err := parseAzureResourceID(*managedDiskID)
   901  	if err != nil {
   902  		return nil, fmt.Errorf("Unable to parse Managed Disk ID %s, %s", *managedDiskID, err)
   903  	}
   904  	name := armID.Path["disks"]
   905  	resourceGroup := armID.ResourceGroup
   906  	conn := testAccProvider.Meta().(*ArmClient).diskClient
   907  	d, err := conn.Get(resourceGroup, name)
   908  	//check status first since sdk client returns error if not 200
   909  	if d.Response.StatusCode == http.StatusNotFound {
   910  		return &d, nil
   911  	}
   912  	if err != nil {
   913  		return nil, err
   914  	}
   915  
   916  	return &d, nil
   917  }
   918  
   919  var testAccAzureRMVirtualMachine_basicLinuxMachine = `
   920  resource "azurerm_resource_group" "test" {
   921      name = "acctestRG-%d"
   922      location = "West US 2"
   923  }
   924  
   925  resource "azurerm_virtual_network" "test" {
   926      name = "acctvn-%d"
   927      address_space = ["10.0.0.0/16"]
   928      location = "West US 2"
   929      resource_group_name = "${azurerm_resource_group.test.name}"
   930  }
   931  
   932  resource "azurerm_subnet" "test" {
   933      name = "acctsub-%d"
   934      resource_group_name = "${azurerm_resource_group.test.name}"
   935      virtual_network_name = "${azurerm_virtual_network.test.name}"
   936      address_prefix = "10.0.2.0/24"
   937  }
   938  
   939  resource "azurerm_network_interface" "test" {
   940      name = "acctni-%d"
   941      location = "West US 2"
   942      resource_group_name = "${azurerm_resource_group.test.name}"
   943  
   944      ip_configuration {
   945      	name = "testconfiguration1"
   946      	subnet_id = "${azurerm_subnet.test.id}"
   947      	private_ip_address_allocation = "dynamic"
   948      }
   949  }
   950  
   951  resource "azurerm_storage_account" "test" {
   952      name = "accsa%d"
   953      resource_group_name = "${azurerm_resource_group.test.name}"
   954      location = "West US 2"
   955      account_type = "Standard_LRS"
   956  
   957      tags {
   958          environment = "staging"
   959      }
   960  }
   961  
   962  resource "azurerm_storage_container" "test" {
   963      name = "vhds"
   964      resource_group_name = "${azurerm_resource_group.test.name}"
   965      storage_account_name = "${azurerm_storage_account.test.name}"
   966      container_access_type = "private"
   967  }
   968  
   969  resource "azurerm_virtual_machine" "test" {
   970      name = "acctvm-%d"
   971      location = "West US 2"
   972      resource_group_name = "${azurerm_resource_group.test.name}"
   973      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   974      vm_size = "Standard_D1_v2"
   975  
   976      storage_image_reference {
   977  	publisher = "Canonical"
   978  	offer = "UbuntuServer"
   979  	sku = "14.04.2-LTS"
   980  	version = "latest"
   981      }
   982  
   983      storage_os_disk {
   984          name = "myosdisk1"
   985          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   986          caching = "ReadWrite"
   987          create_option = "FromImage"
   988          disk_size_gb = "45"
   989      }
   990  
   991      os_profile {
   992  	computer_name = "hn%d"
   993  	admin_username = "testadmin"
   994  	admin_password = "Password1234!"
   995      }
   996  
   997      os_profile_linux_config {
   998  	disable_password_authentication = false
   999      }
  1000  
  1001      tags {
  1002      	environment = "Production"
  1003      	cost-center = "Ops"
  1004      }
  1005  }
  1006  `
  1007  
  1008  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit = `
  1009  resource "azurerm_resource_group" "test" {
  1010      name = "acctestRG-%d"
  1011      location = "West US 2"
  1012  }
  1013  
  1014  resource "azurerm_virtual_network" "test" {
  1015      name = "acctvn-%d"
  1016      address_space = ["10.0.0.0/16"]
  1017      location = "West US 2"
  1018      resource_group_name = "${azurerm_resource_group.test.name}"
  1019  }
  1020  
  1021  resource "azurerm_subnet" "test" {
  1022      name = "acctsub-%d"
  1023      resource_group_name = "${azurerm_resource_group.test.name}"
  1024      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1025      address_prefix = "10.0.2.0/24"
  1026  }
  1027  
  1028  resource "azurerm_network_interface" "test" {
  1029      name = "acctni-%d"
  1030      location = "West US 2"
  1031      resource_group_name = "${azurerm_resource_group.test.name}"
  1032  
  1033      ip_configuration {
  1034      	name = "testconfiguration1"
  1035      	subnet_id = "${azurerm_subnet.test.id}"
  1036      	private_ip_address_allocation = "dynamic"
  1037      }
  1038  }
  1039  
  1040  resource "azurerm_virtual_machine" "test" {
  1041      name = "acctvm-%d"
  1042      location = "West US 2"
  1043      resource_group_name = "${azurerm_resource_group.test.name}"
  1044      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1045      vm_size = "Standard_D1_v2"
  1046  
  1047      storage_image_reference {
  1048  	publisher = "Canonical"
  1049  	offer = "UbuntuServer"
  1050  	sku = "14.04.2-LTS"
  1051  	version = "latest"
  1052      }
  1053  
  1054      storage_os_disk {
  1055          name = "osd-%d"
  1056          caching = "ReadWrite"
  1057          create_option = "FromImage"
  1058          disk_size_gb = "50"
  1059          managed_disk_type = "Standard_LRS"
  1060      }
  1061  
  1062      os_profile {
  1063  	computer_name = "hn%d"
  1064  	admin_username = "testadmin"
  1065  	admin_password = "Password1234!"
  1066      }
  1067  
  1068      os_profile_linux_config {
  1069  	disable_password_authentication = false
  1070      }
  1071  
  1072      tags {
  1073      	environment = "Production"
  1074      	cost-center = "Ops"
  1075      }
  1076  }
  1077  `
  1078  
  1079  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit = `
  1080  resource "azurerm_resource_group" "test" {
  1081      name = "acctestRG-%d"
  1082      location = "West US 2"
  1083  }
  1084  
  1085  resource "azurerm_virtual_network" "test" {
  1086      name = "acctvn-%d"
  1087      address_space = ["10.0.0.0/16"]
  1088      location = "West US 2"
  1089      resource_group_name = "${azurerm_resource_group.test.name}"
  1090  }
  1091  
  1092  resource "azurerm_subnet" "test" {
  1093      name = "acctsub-%d"
  1094      resource_group_name = "${azurerm_resource_group.test.name}"
  1095      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1096      address_prefix = "10.0.2.0/24"
  1097  }
  1098  
  1099  resource "azurerm_network_interface" "test" {
  1100      name = "acctni-%d"
  1101      location = "West US 2"
  1102      resource_group_name = "${azurerm_resource_group.test.name}"
  1103  
  1104      ip_configuration {
  1105      	name = "testconfiguration1"
  1106      	subnet_id = "${azurerm_subnet.test.id}"
  1107      	private_ip_address_allocation = "dynamic"
  1108      }
  1109  }
  1110  
  1111  resource "azurerm_virtual_machine" "test" {
  1112      name = "acctvm-%d"
  1113      location = "West US 2"
  1114      resource_group_name = "${azurerm_resource_group.test.name}"
  1115      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1116      vm_size = "Standard_D1_v2"
  1117  
  1118      storage_image_reference {
  1119  	publisher = "Canonical"
  1120  	offer = "UbuntuServer"
  1121  	sku = "14.04.2-LTS"
  1122  	version = "latest"
  1123      }
  1124  
  1125      storage_os_disk {
  1126          name = "osd-%d"
  1127          caching = "ReadWrite"
  1128          create_option = "FromImage"
  1129          disk_size_gb = "50"
  1130      }
  1131  
  1132      os_profile {
  1133  	computer_name = "hn%d"
  1134  	admin_username = "testadmin"
  1135  	admin_password = "Password1234!"
  1136      }
  1137  
  1138      os_profile_linux_config {
  1139  	disable_password_authentication = false
  1140      }
  1141  
  1142      tags {
  1143      	environment = "Production"
  1144      	cost-center = "Ops"
  1145      }
  1146  }
  1147  `
  1148  
  1149  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach = `
  1150  resource "azurerm_resource_group" "test" {
  1151      name = "acctestRG-%d"
  1152      location = "West US 2"
  1153  }
  1154  
  1155  resource "azurerm_virtual_network" "test" {
  1156      name = "acctvn-%d"
  1157      address_space = ["10.0.0.0/16"]
  1158      location = "West US 2"
  1159      resource_group_name = "${azurerm_resource_group.test.name}"
  1160  }
  1161  
  1162  resource "azurerm_subnet" "test" {
  1163      name = "acctsub-%d"
  1164      resource_group_name = "${azurerm_resource_group.test.name}"
  1165      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1166      address_prefix = "10.0.2.0/24"
  1167  }
  1168  
  1169  resource "azurerm_network_interface" "test" {
  1170      name = "acctni-%d"
  1171      location = "West US 2"
  1172      resource_group_name = "${azurerm_resource_group.test.name}"
  1173  
  1174      ip_configuration {
  1175      	name = "testconfiguration1"
  1176      	subnet_id = "${azurerm_subnet.test.id}"
  1177      	private_ip_address_allocation = "dynamic"
  1178      }
  1179  }
  1180  
  1181  resource "azurerm_managed_disk" "test" {
  1182      name = "acctmd-%d"
  1183      location = "West US 2"
  1184      resource_group_name = "${azurerm_resource_group.test.name}"
  1185      storage_account_type = "Standard_LRS"
  1186      create_option = "Empty"
  1187      disk_size_gb = "1"
  1188  }
  1189  
  1190  resource "azurerm_virtual_machine" "test" {
  1191      name = "acctvm-%d"
  1192      location = "West US 2"
  1193      resource_group_name = "${azurerm_resource_group.test.name}"
  1194      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1195      vm_size = "Standard_D1_v2"
  1196  
  1197      storage_image_reference {
  1198  	publisher = "Canonical"
  1199  	offer = "UbuntuServer"
  1200  	sku = "14.04.2-LTS"
  1201  	version = "latest"
  1202      }
  1203  
  1204      storage_os_disk {
  1205          name = "osd-%d"
  1206          caching = "ReadWrite"
  1207          create_option = "FromImage"
  1208          disk_size_gb = "50"
  1209          managed_disk_type = "Standard_LRS"
  1210      }
  1211  
  1212      storage_data_disk {
  1213          name = "${azurerm_managed_disk.test.name}"
  1214      	create_option = "Attach"
  1215      	disk_size_gb = "1"
  1216      	lun = 0
  1217          managed_disk_id = "${azurerm_managed_disk.test.id}"
  1218      }
  1219  
  1220      os_profile {
  1221  	computer_name = "hn%d"
  1222  	admin_username = "testadmin"
  1223  	admin_password = "Password1234!"
  1224      }
  1225  
  1226      os_profile_linux_config {
  1227  	disable_password_authentication = false
  1228      }
  1229  
  1230      tags {
  1231      	environment = "Production"
  1232      	cost-center = "Ops"
  1233      }
  1234  }
  1235  `
  1236  
  1237  var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = `
  1238  resource "azurerm_resource_group" "test" {
  1239      name = "acctestRG-%d"
  1240      location = "West US 2"
  1241  }
  1242  
  1243  resource "azurerm_virtual_network" "test" {
  1244      name = "acctvn-%d"
  1245      address_space = ["10.0.0.0/16"]
  1246      location = "West US 2"
  1247      resource_group_name = "${azurerm_resource_group.test.name}"
  1248  }
  1249  
  1250  resource "azurerm_subnet" "test" {
  1251      name = "acctsub-%d"
  1252      resource_group_name = "${azurerm_resource_group.test.name}"
  1253      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1254      address_prefix = "10.0.2.0/24"
  1255  }
  1256  
  1257  resource "azurerm_network_interface" "test" {
  1258      name = "acctni-%d"
  1259      location = "West US 2"
  1260      resource_group_name = "${azurerm_resource_group.test.name}"
  1261  
  1262      ip_configuration {
  1263      	name = "testconfiguration1"
  1264      	subnet_id = "${azurerm_subnet.test.id}"
  1265      	private_ip_address_allocation = "dynamic"
  1266      }
  1267  }
  1268  
  1269  resource "azurerm_storage_account" "test" {
  1270      name = "accsa%d"
  1271      resource_group_name = "${azurerm_resource_group.test.name}"
  1272      location = "West US 2"
  1273      account_type = "Standard_LRS"
  1274  
  1275      tags {
  1276          environment = "staging"
  1277      }
  1278  }
  1279  
  1280  resource "azurerm_storage_container" "test" {
  1281      name = "vhds"
  1282      resource_group_name = "${azurerm_resource_group.test.name}"
  1283      storage_account_name = "${azurerm_storage_account.test.name}"
  1284      container_access_type = "private"
  1285  }
  1286  
  1287  resource "azurerm_virtual_machine" "test" {
  1288      name = "acctvm-%d"
  1289      location = "West US 2"
  1290      resource_group_name = "${azurerm_resource_group.test.name}"
  1291      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1292      vm_size = "Standard_D1_v2"
  1293      delete_os_disk_on_termination = true
  1294  
  1295      storage_image_reference {
  1296  	publisher = "Canonical"
  1297  	offer = "UbuntuServer"
  1298  	sku = "14.04.2-LTS"
  1299  	version = "latest"
  1300      }
  1301  
  1302      storage_os_disk {
  1303          name = "myosdisk1"
  1304          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1305          caching = "ReadWrite"
  1306          create_option = "FromImage"
  1307      }
  1308  
  1309      os_profile {
  1310  	computer_name = "hn%d"
  1311  	admin_username = "testadmin"
  1312  	admin_password = "Password1234!"
  1313      }
  1314  
  1315      os_profile_linux_config {
  1316  	disable_password_authentication = false
  1317      }
  1318  
  1319      tags {
  1320      	environment = "Production"
  1321      	cost-center = "Ops"
  1322      }
  1323  }
  1324  `
  1325  
  1326  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore = `
  1327  resource "azurerm_resource_group" "test" {
  1328      name = "acctestRG-%d"
  1329      location = "West US 2"
  1330  }
  1331  
  1332  resource "azurerm_resource_group" "test-sa" {
  1333      name = "acctestRG-sa-%d"
  1334      location = "West US 2"
  1335  }
  1336  
  1337  resource "azurerm_virtual_network" "test" {
  1338      name = "acctvn-%d"
  1339      address_space = ["10.0.0.0/16"]
  1340      location = "West US 2"
  1341      resource_group_name = "${azurerm_resource_group.test.name}"
  1342  }
  1343  
  1344  resource "azurerm_subnet" "test" {
  1345      name = "acctsub-%d"
  1346      resource_group_name = "${azurerm_resource_group.test.name}"
  1347      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1348      address_prefix = "10.0.2.0/24"
  1349  }
  1350  
  1351  resource "azurerm_network_interface" "test" {
  1352      name = "acctni-%d"
  1353      location = "West US 2"
  1354      resource_group_name = "${azurerm_resource_group.test.name}"
  1355  
  1356      ip_configuration {
  1357      	name = "testconfiguration1"
  1358      	subnet_id = "${azurerm_subnet.test.id}"
  1359      	private_ip_address_allocation = "dynamic"
  1360      }
  1361  }
  1362  
  1363  resource "azurerm_storage_account" "test" {
  1364      name = "accsa%d"
  1365      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1366      location = "West US 2"
  1367      account_type = "Standard_LRS"
  1368  
  1369      tags {
  1370          environment = "staging"
  1371      }
  1372  }
  1373  
  1374  resource "azurerm_storage_container" "test" {
  1375      name = "vhds"
  1376      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1377      storage_account_name = "${azurerm_storage_account.test.name}"
  1378      container_access_type = "private"
  1379  }
  1380  
  1381  resource "azurerm_virtual_machine" "test" {
  1382      name = "acctvm-%d"
  1383      location = "West US 2"
  1384      resource_group_name = "${azurerm_resource_group.test.name}"
  1385      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1386      vm_size = "Standard_D1_v2"
  1387  
  1388      storage_image_reference {
  1389  	publisher = "Canonical"
  1390  	offer = "UbuntuServer"
  1391  	sku = "14.04.2-LTS"
  1392  	version = "latest"
  1393      }
  1394  
  1395      storage_os_disk {
  1396          name = "myosdisk1"
  1397          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1398          caching = "ReadWrite"
  1399          create_option = "FromImage"
  1400      }
  1401  
  1402      delete_os_disk_on_termination = true
  1403  
  1404      storage_data_disk {
  1405          name          = "mydatadisk1"
  1406          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
  1407      	disk_size_gb  = "1"
  1408      	create_option = "Empty"
  1409      	lun           = 0
  1410      }
  1411  
  1412      delete_data_disks_on_termination = true
  1413  
  1414      os_profile {
  1415  	computer_name = "hn%d"
  1416  	admin_username = "testadmin"
  1417  	admin_password = "Password1234!"
  1418      }
  1419  
  1420      os_profile_linux_config {
  1421  	disable_password_authentication = false
  1422      }
  1423  
  1424      tags {
  1425      	environment = "Production"
  1426      	cost-center = "Ops"
  1427      }
  1428  }
  1429  `
  1430  
  1431  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore = `
  1432  resource "azurerm_resource_group" "test" {
  1433      name = "acctestRG-%d"
  1434      location = "West US 2"
  1435  }
  1436  
  1437  resource "azurerm_virtual_network" "test" {
  1438      name = "acctvn-%d"
  1439      address_space = ["10.0.0.0/16"]
  1440      location = "West US 2"
  1441      resource_group_name = "${azurerm_resource_group.test.name}"
  1442  }
  1443  
  1444  resource "azurerm_subnet" "test" {
  1445      name = "acctsub-%d"
  1446      resource_group_name = "${azurerm_resource_group.test.name}"
  1447      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1448      address_prefix = "10.0.2.0/24"
  1449  }
  1450  
  1451  resource "azurerm_network_interface" "test" {
  1452      name = "acctni-%d"
  1453      location = "West US 2"
  1454      resource_group_name = "${azurerm_resource_group.test.name}"
  1455  
  1456      ip_configuration {
  1457      	name = "testconfiguration1"
  1458      	subnet_id = "${azurerm_subnet.test.id}"
  1459      	private_ip_address_allocation = "dynamic"
  1460      }
  1461  }
  1462  
  1463  resource "azurerm_virtual_machine" "test" {
  1464      name = "acctvm-%d"
  1465      location = "West US 2"
  1466      resource_group_name = "${azurerm_resource_group.test.name}"
  1467      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1468      vm_size = "Standard_D1_v2"
  1469  
  1470      storage_image_reference {
  1471  	publisher = "Canonical"
  1472  	offer = "UbuntuServer"
  1473  	sku = "14.04.2-LTS"
  1474  	version = "latest"
  1475      }
  1476  
  1477      storage_os_disk {
  1478          name = "myosdisk1"
  1479          caching = "ReadWrite"
  1480          create_option = "FromImage"
  1481      }
  1482  
  1483      delete_os_disk_on_termination = true
  1484  
  1485      storage_data_disk {
  1486          name          = "mydatadisk1"
  1487      	disk_size_gb  = "1"
  1488      	create_option = "Empty"
  1489      	lun           = 0
  1490      }
  1491  
  1492      delete_data_disks_on_termination = true
  1493  
  1494      os_profile {
  1495  	computer_name = "hn%d"
  1496  	admin_username = "testadmin"
  1497  	admin_password = "Password1234!"
  1498      }
  1499  
  1500      os_profile_linux_config {
  1501  	disable_password_authentication = false
  1502      }
  1503  
  1504      tags {
  1505      	environment = "Production"
  1506      	cost-center = "Ops"
  1507      }
  1508  }
  1509  `
  1510  
  1511  var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter = `
  1512  resource "azurerm_resource_group" "test" {
  1513      name = "acctestRG-%d"
  1514      location = "West US 2"
  1515  }
  1516  
  1517  resource "azurerm_resource_group" "test-sa" {
  1518      name = "acctestRG-sa-%d"
  1519      location = "West US 2"
  1520  }
  1521  
  1522  resource "azurerm_virtual_network" "test" {
  1523      name = "acctvn-%d"
  1524      address_space = ["10.0.0.0/16"]
  1525      location = "West US 2"
  1526      resource_group_name = "${azurerm_resource_group.test.name}"
  1527  }
  1528  
  1529  resource "azurerm_subnet" "test" {
  1530      name = "acctsub-%d"
  1531      resource_group_name = "${azurerm_resource_group.test.name}"
  1532      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1533      address_prefix = "10.0.2.0/24"
  1534  }
  1535  
  1536  resource "azurerm_network_interface" "test" {
  1537      name = "acctni-%d"
  1538      location = "West US 2"
  1539      resource_group_name = "${azurerm_resource_group.test.name}"
  1540  
  1541      ip_configuration {
  1542      	name = "testconfiguration1"
  1543      	subnet_id = "${azurerm_subnet.test.id}"
  1544      	private_ip_address_allocation = "dynamic"
  1545      }
  1546  }
  1547  
  1548  resource "azurerm_storage_account" "test" {
  1549      name = "accsa%d"
  1550      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1551      location = "West US 2"
  1552      account_type = "Standard_LRS"
  1553  
  1554      tags {
  1555          environment = "staging"
  1556      }
  1557  }
  1558  
  1559  resource "azurerm_storage_container" "test" {
  1560      name = "vhds"
  1561      resource_group_name = "${azurerm_resource_group.test-sa.name}"
  1562      storage_account_name = "${azurerm_storage_account.test.name}"
  1563      container_access_type = "private"
  1564  }
  1565  `
  1566  
  1567  var testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter = `
  1568  resource "azurerm_resource_group" "test" {
  1569      name = "acctestRG-%d"
  1570      location = "West US 2"
  1571  }
  1572  
  1573  resource "azurerm_virtual_network" "test" {
  1574      name = "acctvn-%d"
  1575      address_space = ["10.0.0.0/16"]
  1576      location = "West US 2"
  1577      resource_group_name = "${azurerm_resource_group.test.name}"
  1578  }
  1579  
  1580  resource "azurerm_subnet" "test" {
  1581      name = "acctsub-%d"
  1582      resource_group_name = "${azurerm_resource_group.test.name}"
  1583      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1584      address_prefix = "10.0.2.0/24"
  1585  }
  1586  
  1587  resource "azurerm_network_interface" "test" {
  1588      name = "acctni-%d"
  1589      location = "West US 2"
  1590      resource_group_name = "${azurerm_resource_group.test.name}"
  1591  
  1592      ip_configuration {
  1593      	name = "testconfiguration1"
  1594      	subnet_id = "${azurerm_subnet.test.id}"
  1595      	private_ip_address_allocation = "dynamic"
  1596      }
  1597  }
  1598  `
  1599  
  1600  var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = `
  1601  resource "azurerm_resource_group" "test" {
  1602      name = "acctestRG-%d"
  1603      location = "West US 2"
  1604  }
  1605  
  1606  resource "azurerm_virtual_network" "test" {
  1607      name = "acctvn-%d"
  1608      address_space = ["10.0.0.0/16"]
  1609      location = "West US 2"
  1610      resource_group_name = "${azurerm_resource_group.test.name}"
  1611  }
  1612  
  1613  resource "azurerm_subnet" "test" {
  1614      name = "acctsub-%d"
  1615      resource_group_name = "${azurerm_resource_group.test.name}"
  1616      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1617      address_prefix = "10.0.2.0/24"
  1618  }
  1619  
  1620  resource "azurerm_network_interface" "test" {
  1621      name = "acctni-%d"
  1622      location = "West US 2"
  1623      resource_group_name = "${azurerm_resource_group.test.name}"
  1624  
  1625      ip_configuration {
  1626      	name = "testconfiguration1"
  1627      	subnet_id = "${azurerm_subnet.test.id}"
  1628      	private_ip_address_allocation = "dynamic"
  1629      }
  1630  }
  1631  
  1632  resource "azurerm_storage_account" "test" {
  1633      name = "accsa%d"
  1634      resource_group_name = "${azurerm_resource_group.test.name}"
  1635      location = "West US 2"
  1636      account_type = "Standard_LRS"
  1637  
  1638      tags {
  1639          environment = "staging"
  1640      }
  1641  }
  1642  
  1643  resource "azurerm_storage_container" "test" {
  1644      name = "vhds"
  1645      resource_group_name = "${azurerm_resource_group.test.name}"
  1646      storage_account_name = "${azurerm_storage_account.test.name}"
  1647      container_access_type = "private"
  1648  }
  1649  `
  1650  
  1651  var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk = `
  1652  resource "azurerm_resource_group" "test" {
  1653      name = "acctestRG-%d"
  1654      location = "West US 2"
  1655  }
  1656  
  1657  resource "azurerm_virtual_network" "test" {
  1658      name = "acctvn-%d"
  1659      address_space = ["10.0.0.0/16"]
  1660      location = "West US 2"
  1661      resource_group_name = "${azurerm_resource_group.test.name}"
  1662  }
  1663  
  1664  resource "azurerm_subnet" "test" {
  1665      name = "acctsub-%d"
  1666      resource_group_name = "${azurerm_resource_group.test.name}"
  1667      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1668      address_prefix = "10.0.2.0/24"
  1669  }
  1670  
  1671  resource "azurerm_network_interface" "test" {
  1672      name = "acctni-%d"
  1673      location = "West US 2"
  1674      resource_group_name = "${azurerm_resource_group.test.name}"
  1675  
  1676      ip_configuration {
  1677      	name = "testconfiguration1"
  1678      	subnet_id = "${azurerm_subnet.test.id}"
  1679      	private_ip_address_allocation = "dynamic"
  1680      }
  1681  }
  1682  `
  1683  
  1684  var testAccAzureRMVirtualMachine_withDataDisk = `
  1685  resource "azurerm_resource_group" "test" {
  1686      name = "acctestRG-%d"
  1687      location = "West US 2"
  1688  }
  1689  
  1690  resource "azurerm_virtual_network" "test" {
  1691      name = "acctvn-%d"
  1692      address_space = ["10.0.0.0/16"]
  1693      location = "West US 2"
  1694      resource_group_name = "${azurerm_resource_group.test.name}"
  1695  }
  1696  
  1697  resource "azurerm_subnet" "test" {
  1698      name = "acctsub-%d"
  1699      resource_group_name = "${azurerm_resource_group.test.name}"
  1700      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1701      address_prefix = "10.0.2.0/24"
  1702  }
  1703  
  1704  resource "azurerm_network_interface" "test" {
  1705      name = "acctni-%d"
  1706      location = "West US 2"
  1707      resource_group_name = "${azurerm_resource_group.test.name}"
  1708  
  1709      ip_configuration {
  1710      	name = "testconfiguration1"
  1711      	subnet_id = "${azurerm_subnet.test.id}"
  1712      	private_ip_address_allocation = "dynamic"
  1713      }
  1714  }
  1715  
  1716  resource "azurerm_storage_account" "test" {
  1717      name = "accsa%d"
  1718      resource_group_name = "${azurerm_resource_group.test.name}"
  1719      location = "West US 2"
  1720      account_type = "Standard_LRS"
  1721  
  1722      tags {
  1723          environment = "staging"
  1724      }
  1725  }
  1726  
  1727  resource "azurerm_storage_container" "test" {
  1728      name = "vhds"
  1729      resource_group_name = "${azurerm_resource_group.test.name}"
  1730      storage_account_name = "${azurerm_storage_account.test.name}"
  1731      container_access_type = "private"
  1732  }
  1733  
  1734  resource "azurerm_virtual_machine" "test" {
  1735      name = "acctvm-%d"
  1736      location = "West US 2"
  1737      resource_group_name = "${azurerm_resource_group.test.name}"
  1738      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1739      vm_size = "Standard_D1_v2"
  1740  
  1741      storage_image_reference {
  1742  	publisher = "Canonical"
  1743  	offer = "UbuntuServer"
  1744  	sku = "14.04.2-LTS"
  1745  	version = "latest"
  1746      }
  1747  
  1748      storage_os_disk {
  1749          name = "myosdisk1"
  1750          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  1751          caching = "ReadWrite"
  1752          create_option = "FromImage"
  1753      }
  1754  
  1755      storage_data_disk {
  1756          name          = "mydatadisk1"
  1757          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
  1758      	disk_size_gb  = "1"
  1759      	create_option = "Empty"
  1760          caching       = "ReadWrite"
  1761      	lun           = 0
  1762      }
  1763  
  1764      os_profile {
  1765  	computer_name = "hn%d"
  1766  	admin_username = "testadmin"
  1767  	admin_password = "Password1234!"
  1768      }
  1769  
  1770      os_profile_linux_config {
  1771  	disable_password_authentication = false
  1772      }
  1773  
  1774      tags {
  1775      	environment = "Production"
  1776      	cost-center = "Ops"
  1777      }
  1778  }
  1779  `
  1780  
  1781  var testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit = `
  1782  resource "azurerm_resource_group" "test" {
  1783      name = "acctestRG-%d"
  1784      location = "West US 2"
  1785  }
  1786  
  1787  resource "azurerm_virtual_network" "test" {
  1788      name = "acctvn-%d"
  1789      address_space = ["10.0.0.0/16"]
  1790      location = "West US 2"
  1791      resource_group_name = "${azurerm_resource_group.test.name}"
  1792  }
  1793  
  1794  resource "azurerm_subnet" "test" {
  1795      name = "acctsub-%d"
  1796      resource_group_name = "${azurerm_resource_group.test.name}"
  1797      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1798      address_prefix = "10.0.2.0/24"
  1799  }
  1800  
  1801  resource "azurerm_network_interface" "test" {
  1802      name = "acctni-%d"
  1803      location = "West US 2"
  1804      resource_group_name = "${azurerm_resource_group.test.name}"
  1805  
  1806      ip_configuration {
  1807      	name = "testconfiguration1"
  1808      	subnet_id = "${azurerm_subnet.test.id}"
  1809      	private_ip_address_allocation = "dynamic"
  1810      }
  1811  }
  1812  
  1813  resource "azurerm_virtual_machine" "test" {
  1814      name = "acctvm-%d"
  1815      location = "West US 2"
  1816      resource_group_name = "${azurerm_resource_group.test.name}"
  1817      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1818      vm_size = "Standard_D1_v2"
  1819  
  1820      storage_image_reference {
  1821  	publisher = "Canonical"
  1822  	offer = "UbuntuServer"
  1823  	sku = "14.04.2-LTS"
  1824  	version = "latest"
  1825      }
  1826  
  1827      storage_os_disk {
  1828          name = "osd-%d"
  1829          caching = "ReadWrite"
  1830          create_option = "FromImage"
  1831          managed_disk_type = "Standard_LRS"
  1832      }
  1833  
  1834      storage_data_disk {
  1835          name          = "dtd-%d"
  1836      	disk_size_gb  = "1"
  1837      	create_option = "Empty"
  1838          caching       = "ReadWrite"
  1839      	lun           = 0
  1840      	managed_disk_type = "Standard_LRS"
  1841      }
  1842  
  1843      os_profile {
  1844  	computer_name = "hn%d"
  1845  	admin_username = "testadmin"
  1846  	admin_password = "Password1234!"
  1847      }
  1848  
  1849      os_profile_linux_config {
  1850  	disable_password_authentication = false
  1851      }
  1852  
  1853      tags {
  1854      	environment = "Production"
  1855      	cost-center = "Ops"
  1856      }
  1857  }
  1858  `
  1859  
  1860  var testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit = `
  1861  resource "azurerm_resource_group" "test" {
  1862      name = "acctestRG-%d"
  1863      location = "West US 2"
  1864  }
  1865  
  1866  resource "azurerm_virtual_network" "test" {
  1867      name = "acctvn-%d"
  1868      address_space = ["10.0.0.0/16"]
  1869      location = "West US 2"
  1870      resource_group_name = "${azurerm_resource_group.test.name}"
  1871  }
  1872  
  1873  resource "azurerm_subnet" "test" {
  1874      name = "acctsub-%d"
  1875      resource_group_name = "${azurerm_resource_group.test.name}"
  1876      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1877      address_prefix = "10.0.2.0/24"
  1878  }
  1879  
  1880  resource "azurerm_network_interface" "test" {
  1881      name = "acctni-%d"
  1882      location = "West US 2"
  1883      resource_group_name = "${azurerm_resource_group.test.name}"
  1884  
  1885      ip_configuration {
  1886      	name = "testconfiguration1"
  1887      	subnet_id = "${azurerm_subnet.test.id}"
  1888      	private_ip_address_allocation = "dynamic"
  1889      }
  1890  }
  1891  
  1892  resource "azurerm_virtual_machine" "test" {
  1893      name = "acctvm-%d"
  1894      location = "West US 2"
  1895      resource_group_name = "${azurerm_resource_group.test.name}"
  1896      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1897      vm_size = "Standard_D1_v2"
  1898  
  1899      storage_image_reference {
  1900  	publisher = "Canonical"
  1901  	offer = "UbuntuServer"
  1902  	sku = "14.04.2-LTS"
  1903  	version = "latest"
  1904      }
  1905  
  1906      storage_os_disk {
  1907          name = "myosdisk1"
  1908          caching = "ReadWrite"
  1909          create_option = "FromImage"
  1910      }
  1911  
  1912      storage_data_disk {
  1913          name          = "mydatadisk1"
  1914      	disk_size_gb  = "1"
  1915      	create_option = "Empty"
  1916          caching       = "ReadWrite"
  1917      	lun           = 0
  1918      }
  1919  
  1920      os_profile {
  1921  	computer_name = "hn%d"
  1922  	admin_username = "testadmin"
  1923  	admin_password = "Password1234!"
  1924      }
  1925  
  1926      os_profile_linux_config {
  1927  	disable_password_authentication = false
  1928      }
  1929  
  1930      tags {
  1931      	environment = "Production"
  1932      	cost-center = "Ops"
  1933      }
  1934  }
  1935  `
  1936  
  1937  var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = `
  1938  resource "azurerm_resource_group" "test" {
  1939      name = "acctestRG-%d"
  1940      location = "West US 2"
  1941  }
  1942  
  1943  resource "azurerm_virtual_network" "test" {
  1944      name = "acctvn-%d"
  1945      address_space = ["10.0.0.0/16"]
  1946      location = "West US 2"
  1947      resource_group_name = "${azurerm_resource_group.test.name}"
  1948  }
  1949  
  1950  resource "azurerm_subnet" "test" {
  1951      name = "acctsub-%d"
  1952      resource_group_name = "${azurerm_resource_group.test.name}"
  1953      virtual_network_name = "${azurerm_virtual_network.test.name}"
  1954      address_prefix = "10.0.2.0/24"
  1955  }
  1956  
  1957  resource "azurerm_network_interface" "test" {
  1958      name = "acctni-%d"
  1959      location = "West US 2"
  1960      resource_group_name = "${azurerm_resource_group.test.name}"
  1961  
  1962      ip_configuration {
  1963      	name = "testconfiguration1"
  1964      	subnet_id = "${azurerm_subnet.test.id}"
  1965      	private_ip_address_allocation = "dynamic"
  1966      }
  1967  }
  1968  
  1969  resource "azurerm_storage_account" "test" {
  1970      name = "accsa%d"
  1971      resource_group_name = "${azurerm_resource_group.test.name}"
  1972      location = "West US 2"
  1973      account_type = "Standard_LRS"
  1974  
  1975      tags {
  1976          environment = "staging"
  1977      }
  1978  }
  1979  
  1980  resource "azurerm_storage_container" "test" {
  1981      name = "vhds"
  1982      resource_group_name = "${azurerm_resource_group.test.name}"
  1983      storage_account_name = "${azurerm_storage_account.test.name}"
  1984      container_access_type = "private"
  1985  }
  1986  
  1987  resource "azurerm_virtual_machine" "test" {
  1988      name = "acctvm-%d"
  1989      location = "West US 2"
  1990      resource_group_name = "${azurerm_resource_group.test.name}"
  1991      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  1992      vm_size = "Standard_D1_v2"
  1993  
  1994      storage_image_reference {
  1995  	publisher = "Canonical"
  1996  	offer = "UbuntuServer"
  1997  	sku = "14.04.2-LTS"
  1998  	version = "latest"
  1999      }
  2000  
  2001      storage_os_disk {
  2002          name = "myosdisk1"
  2003          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2004          caching = "ReadWrite"
  2005          create_option = "FromImage"
  2006      }
  2007  
  2008      os_profile {
  2009  	computer_name = "hn%d"
  2010  	admin_username = "testadmin"
  2011  	admin_password = "Password1234!"
  2012      }
  2013  
  2014      os_profile_linux_config {
  2015  	disable_password_authentication = false
  2016      }
  2017  
  2018      tags {
  2019      	environment = "Production"
  2020      }
  2021  }
  2022  `
  2023  
  2024  var testAccAzureRMVirtualMachine_updatedLinuxMachine = `
  2025  resource "azurerm_resource_group" "test" {
  2026      name = "acctestRG-%d"
  2027      location = "West US 2"
  2028  }
  2029  
  2030  resource "azurerm_virtual_network" "test" {
  2031      name = "acctvn-%d"
  2032      address_space = ["10.0.0.0/16"]
  2033      location = "West US 2"
  2034      resource_group_name = "${azurerm_resource_group.test.name}"
  2035  }
  2036  
  2037  resource "azurerm_subnet" "test" {
  2038      name = "acctsub-%d"
  2039      resource_group_name = "${azurerm_resource_group.test.name}"
  2040      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2041      address_prefix = "10.0.2.0/24"
  2042  }
  2043  
  2044  resource "azurerm_network_interface" "test" {
  2045      name = "acctni-%d"
  2046      location = "West US 2"
  2047      resource_group_name = "${azurerm_resource_group.test.name}"
  2048  
  2049      ip_configuration {
  2050      	name = "testconfiguration1"
  2051      	subnet_id = "${azurerm_subnet.test.id}"
  2052      	private_ip_address_allocation = "dynamic"
  2053      }
  2054  }
  2055  
  2056  resource "azurerm_storage_account" "test" {
  2057      name = "accsa%d"
  2058      resource_group_name = "${azurerm_resource_group.test.name}"
  2059      location = "West US 2"
  2060      account_type = "Standard_LRS"
  2061  
  2062      tags {
  2063          environment = "staging"
  2064      }
  2065  }
  2066  
  2067  resource "azurerm_storage_container" "test" {
  2068      name = "vhds"
  2069      resource_group_name = "${azurerm_resource_group.test.name}"
  2070      storage_account_name = "${azurerm_storage_account.test.name}"
  2071      container_access_type = "private"
  2072  }
  2073  
  2074  resource "azurerm_virtual_machine" "test" {
  2075      name = "acctvm-%d"
  2076      location = "West US 2"
  2077      resource_group_name = "${azurerm_resource_group.test.name}"
  2078      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2079      vm_size = "Standard_D2_v2"
  2080  
  2081      storage_image_reference {
  2082  	publisher = "Canonical"
  2083  	offer = "UbuntuServer"
  2084  	sku = "14.04.2-LTS"
  2085  	version = "latest"
  2086      }
  2087  
  2088      storage_os_disk {
  2089          name = "myosdisk1"
  2090          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2091          caching = "ReadWrite"
  2092          create_option = "FromImage"
  2093      }
  2094  
  2095      os_profile {
  2096  	computer_name = "hn%d"
  2097  	admin_username = "testadmin"
  2098  	admin_password = "Password1234!"
  2099      }
  2100  
  2101      os_profile_linux_config {
  2102  	disable_password_authentication = false
  2103      }
  2104  }
  2105  `
  2106  
  2107  var testAccAzureRMVirtualMachine_basicWindowsMachine = `
  2108  resource "azurerm_resource_group" "test" {
  2109      name = "acctestRG-%d"
  2110      location = "West US 2"
  2111  }
  2112  
  2113  resource "azurerm_virtual_network" "test" {
  2114      name = "acctvn-%d"
  2115      address_space = ["10.0.0.0/16"]
  2116      location = "West US 2"
  2117      resource_group_name = "${azurerm_resource_group.test.name}"
  2118  }
  2119  
  2120  resource "azurerm_subnet" "test" {
  2121      name = "acctsub-%d"
  2122      resource_group_name = "${azurerm_resource_group.test.name}"
  2123      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2124      address_prefix = "10.0.2.0/24"
  2125  }
  2126  
  2127  resource "azurerm_network_interface" "test" {
  2128      name = "acctni-%d"
  2129      location = "West US 2"
  2130      resource_group_name = "${azurerm_resource_group.test.name}"
  2131  
  2132      ip_configuration {
  2133      	name = "testconfiguration1"
  2134      	subnet_id = "${azurerm_subnet.test.id}"
  2135      	private_ip_address_allocation = "dynamic"
  2136      }
  2137  }
  2138  
  2139  resource "azurerm_storage_account" "test" {
  2140      name = "accsa%d"
  2141      resource_group_name = "${azurerm_resource_group.test.name}"
  2142      location = "West US 2"
  2143      account_type = "Standard_LRS"
  2144  
  2145      tags {
  2146          environment = "staging"
  2147      }
  2148  }
  2149  
  2150  resource "azurerm_storage_container" "test" {
  2151      name = "vhds"
  2152      resource_group_name = "${azurerm_resource_group.test.name}"
  2153      storage_account_name = "${azurerm_storage_account.test.name}"
  2154      container_access_type = "private"
  2155  }
  2156  
  2157  resource "azurerm_virtual_machine" "test" {
  2158      name = "acctvm-%d"
  2159      location = "West US 2"
  2160      resource_group_name = "${azurerm_resource_group.test.name}"
  2161      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2162      vm_size = "Standard_D1_v2"
  2163  
  2164      storage_image_reference {
  2165  	publisher = "MicrosoftWindowsServer"
  2166  	offer = "WindowsServer"
  2167  	sku = "2012-Datacenter"
  2168  	version = "latest"
  2169      }
  2170  
  2171      storage_os_disk {
  2172          name = "myosdisk1"
  2173          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2174          caching = "ReadWrite"
  2175          create_option = "FromImage"
  2176      }
  2177  
  2178      os_profile {
  2179  	computer_name = "winhost01"
  2180  	admin_username = "testadmin"
  2181  	admin_password = "Password1234!"
  2182      }
  2183  
  2184      os_profile_windows_config {
  2185  	enable_automatic_upgrades = false
  2186  	provision_vm_agent = true
  2187      }
  2188  }
  2189  `
  2190  
  2191  var testAccAzureRMVirtualMachine_windowsUnattendedConfig = `
  2192  resource "azurerm_resource_group" "test" {
  2193      name = "acctestRG-%d"
  2194      location = "West US 2"
  2195  }
  2196  
  2197  resource "azurerm_virtual_network" "test" {
  2198      name = "acctvn-%d"
  2199      address_space = ["10.0.0.0/16"]
  2200      location = "West US 2"
  2201      resource_group_name = "${azurerm_resource_group.test.name}"
  2202  }
  2203  
  2204  resource "azurerm_subnet" "test" {
  2205      name = "acctsub-%d"
  2206      resource_group_name = "${azurerm_resource_group.test.name}"
  2207      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2208      address_prefix = "10.0.2.0/24"
  2209  }
  2210  
  2211  resource "azurerm_network_interface" "test" {
  2212      name = "acctni-%d"
  2213      location = "West US 2"
  2214      resource_group_name = "${azurerm_resource_group.test.name}"
  2215  
  2216      ip_configuration {
  2217      	name = "testconfiguration1"
  2218      	subnet_id = "${azurerm_subnet.test.id}"
  2219      	private_ip_address_allocation = "dynamic"
  2220      }
  2221  }
  2222  
  2223  resource "azurerm_storage_account" "test" {
  2224      name = "accsa%d"
  2225      resource_group_name = "${azurerm_resource_group.test.name}"
  2226      location = "West US 2"
  2227      account_type = "Standard_LRS"
  2228  
  2229      tags {
  2230          environment = "staging"
  2231      }
  2232  }
  2233  
  2234  resource "azurerm_storage_container" "test" {
  2235      name = "vhds"
  2236      resource_group_name = "${azurerm_resource_group.test.name}"
  2237      storage_account_name = "${azurerm_storage_account.test.name}"
  2238      container_access_type = "private"
  2239  }
  2240  
  2241  resource "azurerm_virtual_machine" "test" {
  2242      name = "acctvm-%d"
  2243      location = "West US 2"
  2244      resource_group_name = "${azurerm_resource_group.test.name}"
  2245      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2246      vm_size = "Standard_D1_v2"
  2247  
  2248      storage_image_reference {
  2249  	publisher = "MicrosoftWindowsServer"
  2250  	offer = "WindowsServer"
  2251  	sku = "2012-Datacenter"
  2252  	version = "latest"
  2253      }
  2254  
  2255      storage_os_disk {
  2256          name = "myosdisk1"
  2257          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2258          caching = "ReadWrite"
  2259          create_option = "FromImage"
  2260      }
  2261  
  2262      os_profile {
  2263  	computer_name = "winhost01"
  2264  	admin_username = "testadmin"
  2265  	admin_password = "Password1234!"
  2266      }
  2267  
  2268      os_profile_windows_config {
  2269          provision_vm_agent = true
  2270          additional_unattend_config {
  2271              pass = "oobeSystem"
  2272              component = "Microsoft-Windows-Shell-Setup"
  2273              setting_name = "FirstLogonCommands"
  2274              content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
  2275          }
  2276      }
  2277  
  2278  }
  2279  `
  2280  
  2281  var testAccAzureRMVirtualMachine_diagnosticsProfile = `
  2282  resource "azurerm_resource_group" "test" {
  2283      name = "acctestRG-%d"
  2284      location = "West US 2"
  2285  }
  2286  
  2287  resource "azurerm_virtual_network" "test" {
  2288      name = "acctvn-%d"
  2289      address_space = ["10.0.0.0/16"]
  2290      location = "West US 2"
  2291      resource_group_name = "${azurerm_resource_group.test.name}"
  2292  }
  2293  
  2294  resource "azurerm_subnet" "test" {
  2295      name = "acctsub-%d"
  2296      resource_group_name = "${azurerm_resource_group.test.name}"
  2297      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2298      address_prefix = "10.0.2.0/24"
  2299  }
  2300  
  2301  resource "azurerm_network_interface" "test" {
  2302      name = "acctni-%d"
  2303      location = "West US 2"
  2304      resource_group_name = "${azurerm_resource_group.test.name}"
  2305  
  2306      ip_configuration {
  2307          name = "testconfiguration1"
  2308          subnet_id = "${azurerm_subnet.test.id}"
  2309          private_ip_address_allocation = "dynamic"
  2310      }
  2311  }
  2312  
  2313  resource "azurerm_storage_account" "test" {
  2314      name = "accsa%d"
  2315      resource_group_name = "${azurerm_resource_group.test.name}"
  2316      location = "West US 2"
  2317      account_type = "Standard_LRS"
  2318  
  2319      tags {
  2320          environment = "staging"
  2321      }
  2322  }
  2323  
  2324  resource "azurerm_storage_container" "test" {
  2325      name = "vhds"
  2326      resource_group_name = "${azurerm_resource_group.test.name}"
  2327      storage_account_name = "${azurerm_storage_account.test.name}"
  2328      container_access_type = "private"
  2329  }
  2330  
  2331  resource "azurerm_virtual_machine" "test" {
  2332      name = "acctvm-%d"
  2333      location = "West US 2"
  2334      resource_group_name = "${azurerm_resource_group.test.name}"
  2335      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2336      vm_size = "Standard_D1_v2"
  2337  
  2338      storage_image_reference {
  2339  	publisher = "MicrosoftWindowsServer"
  2340  	offer = "WindowsServer"
  2341  	sku = "2012-Datacenter"
  2342  	version = "latest"
  2343      }
  2344  
  2345      storage_os_disk {
  2346          name = "myosdisk1"
  2347          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2348          caching = "ReadWrite"
  2349          create_option = "FromImage"
  2350      }
  2351  
  2352      os_profile {
  2353  	computer_name = "winhost01"
  2354  	admin_username = "testadmin"
  2355  	admin_password = "Password1234!"
  2356      }
  2357  
  2358      boot_diagnostics {
  2359          enabled = true
  2360          storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}"
  2361      }
  2362  
  2363      os_profile_windows_config {
  2364          winrm {
  2365  	  protocol = "http"
  2366          }
  2367      }
  2368  }
  2369  
  2370  `
  2371  
  2372  var testAccAzureRMVirtualMachine_winRMConfig = `
  2373  resource "azurerm_resource_group" "test" {
  2374      name = "acctestRG-%d"
  2375      location = "West US 2"
  2376  }
  2377  
  2378  resource "azurerm_virtual_network" "test" {
  2379      name = "acctvn-%d"
  2380      address_space = ["10.0.0.0/16"]
  2381      location = "West US 2"
  2382      resource_group_name = "${azurerm_resource_group.test.name}"
  2383  }
  2384  
  2385  resource "azurerm_subnet" "test" {
  2386      name = "acctsub-%d"
  2387      resource_group_name = "${azurerm_resource_group.test.name}"
  2388      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2389      address_prefix = "10.0.2.0/24"
  2390  }
  2391  
  2392  resource "azurerm_network_interface" "test" {
  2393      name = "acctni-%d"
  2394      location = "West US 2"
  2395      resource_group_name = "${azurerm_resource_group.test.name}"
  2396  
  2397      ip_configuration {
  2398      	name = "testconfiguration1"
  2399      	subnet_id = "${azurerm_subnet.test.id}"
  2400      	private_ip_address_allocation = "dynamic"
  2401      }
  2402  }
  2403  
  2404  resource "azurerm_storage_account" "test" {
  2405      name = "accsa%d"
  2406      resource_group_name = "${azurerm_resource_group.test.name}"
  2407      location = "West US 2"
  2408      account_type = "Standard_LRS"
  2409  
  2410      tags {
  2411          environment = "staging"
  2412      }
  2413  }
  2414  
  2415  resource "azurerm_storage_container" "test" {
  2416      name = "vhds"
  2417      resource_group_name = "${azurerm_resource_group.test.name}"
  2418      storage_account_name = "${azurerm_storage_account.test.name}"
  2419      container_access_type = "private"
  2420  }
  2421  
  2422  resource "azurerm_virtual_machine" "test" {
  2423      name = "acctvm-%d"
  2424      location = "West US 2"
  2425      resource_group_name = "${azurerm_resource_group.test.name}"
  2426      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2427      vm_size = "Standard_D1_v2"
  2428  
  2429      storage_image_reference {
  2430  	publisher = "MicrosoftWindowsServer"
  2431  	offer = "WindowsServer"
  2432  	sku = "2012-Datacenter"
  2433  	version = "latest"
  2434      }
  2435  
  2436      storage_os_disk {
  2437          name = "myosdisk1"
  2438          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2439          caching = "ReadWrite"
  2440          create_option = "FromImage"
  2441      }
  2442  
  2443      os_profile {
  2444  	computer_name = "winhost01"
  2445  	admin_username = "testadmin"
  2446  	admin_password = "Password1234!"
  2447      }
  2448  
  2449      os_profile_windows_config {
  2450          winrm {
  2451  	  protocol = "http"
  2452          }
  2453      }
  2454  }
  2455  `
  2456  
  2457  var testAccAzureRMVirtualMachine_withAvailabilitySet = `
  2458   resource "azurerm_resource_group" "test" {
  2459       name = "acctestRG-%d"
  2460       location = "West US 2"
  2461   }
  2462  
  2463   resource "azurerm_virtual_network" "test" {
  2464       name = "acctvn-%d"
  2465       address_space = ["10.0.0.0/16"]
  2466       location = "West US 2"
  2467       resource_group_name = "${azurerm_resource_group.test.name}"
  2468   }
  2469  
  2470   resource "azurerm_subnet" "test" {
  2471       name = "acctsub-%d"
  2472       resource_group_name = "${azurerm_resource_group.test.name}"
  2473       virtual_network_name = "${azurerm_virtual_network.test.name}"
  2474       address_prefix = "10.0.2.0/24"
  2475   }
  2476  
  2477   resource "azurerm_network_interface" "test" {
  2478       name = "acctni-%d"
  2479       location = "West US 2"
  2480       resource_group_name = "${azurerm_resource_group.test.name}"
  2481  
  2482       ip_configuration {
  2483       	name = "testconfiguration1"
  2484       	subnet_id = "${azurerm_subnet.test.id}"
  2485       	private_ip_address_allocation = "dynamic"
  2486       }
  2487   }
  2488  
  2489   resource "azurerm_storage_account" "test" {
  2490       name = "accsa%d"
  2491       resource_group_name = "${azurerm_resource_group.test.name}"
  2492       location = "West US 2"
  2493       account_type = "Standard_LRS"
  2494  
  2495       tags {
  2496           environment = "staging"
  2497       }
  2498   }
  2499  
  2500   resource "azurerm_availability_set" "test" {
  2501      name = "availabilityset%d"
  2502      location = "West US 2"
  2503      resource_group_name = "${azurerm_resource_group.test.name}"
  2504  }
  2505  
  2506   resource "azurerm_storage_container" "test" {
  2507       name = "vhds"
  2508       resource_group_name = "${azurerm_resource_group.test.name}"
  2509       storage_account_name = "${azurerm_storage_account.test.name}"
  2510       container_access_type = "private"
  2511   }
  2512  
  2513   resource "azurerm_virtual_machine" "test" {
  2514       name = "acctvm-%d"
  2515       location = "West US 2"
  2516       resource_group_name = "${azurerm_resource_group.test.name}"
  2517       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2518       vm_size = "Standard_D1_v2"
  2519       availability_set_id = "${azurerm_availability_set.test.id}"
  2520       delete_os_disk_on_termination = true
  2521  
  2522       storage_image_reference {
  2523   	publisher = "Canonical"
  2524   	offer = "UbuntuServer"
  2525   	sku = "14.04.2-LTS"
  2526   	version = "latest"
  2527       }
  2528  
  2529       storage_os_disk {
  2530           name = "myosdisk1"
  2531           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2532           caching = "ReadWrite"
  2533           create_option = "FromImage"
  2534       }
  2535  
  2536       os_profile {
  2537   	computer_name = "hn%d"
  2538   	admin_username = "testadmin"
  2539   	admin_password = "Password1234!"
  2540       }
  2541  
  2542       os_profile_linux_config {
  2543   	disable_password_authentication = false
  2544       }
  2545   }
  2546  `
  2547  
  2548  var testAccAzureRMVirtualMachine_updateAvailabilitySet = `
  2549   resource "azurerm_resource_group" "test" {
  2550       name = "acctestRG-%d"
  2551       location = "West US 2"
  2552   }
  2553  
  2554   resource "azurerm_virtual_network" "test" {
  2555       name = "acctvn-%d"
  2556       address_space = ["10.0.0.0/16"]
  2557       location = "West US 2"
  2558       resource_group_name = "${azurerm_resource_group.test.name}"
  2559   }
  2560  
  2561   resource "azurerm_subnet" "test" {
  2562       name = "acctsub-%d"
  2563       resource_group_name = "${azurerm_resource_group.test.name}"
  2564       virtual_network_name = "${azurerm_virtual_network.test.name}"
  2565       address_prefix = "10.0.2.0/24"
  2566   }
  2567  
  2568   resource "azurerm_network_interface" "test" {
  2569       name = "acctni-%d"
  2570       location = "West US 2"
  2571       resource_group_name = "${azurerm_resource_group.test.name}"
  2572  
  2573       ip_configuration {
  2574       	name = "testconfiguration1"
  2575       	subnet_id = "${azurerm_subnet.test.id}"
  2576       	private_ip_address_allocation = "dynamic"
  2577       }
  2578   }
  2579  
  2580   resource "azurerm_storage_account" "test" {
  2581       name = "accsa%d"
  2582       resource_group_name = "${azurerm_resource_group.test.name}"
  2583       location = "West US 2"
  2584       account_type = "Standard_LRS"
  2585  
  2586       tags {
  2587           environment = "staging"
  2588       }
  2589   }
  2590  
  2591   resource "azurerm_availability_set" "test" {
  2592      name = "updatedAvailabilitySet%d"
  2593      location = "West US 2"
  2594      resource_group_name = "${azurerm_resource_group.test.name}"
  2595  }
  2596  
  2597   resource "azurerm_storage_container" "test" {
  2598       name = "vhds"
  2599       resource_group_name = "${azurerm_resource_group.test.name}"
  2600       storage_account_name = "${azurerm_storage_account.test.name}"
  2601       container_access_type = "private"
  2602   }
  2603  
  2604   resource "azurerm_virtual_machine" "test" {
  2605       name = "acctvm-%d"
  2606       location = "West US 2"
  2607       resource_group_name = "${azurerm_resource_group.test.name}"
  2608       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2609       vm_size = "Standard_D1_v2"
  2610       availability_set_id = "${azurerm_availability_set.test.id}"
  2611       delete_os_disk_on_termination = true
  2612  
  2613       storage_image_reference {
  2614   	publisher = "Canonical"
  2615   	offer = "UbuntuServer"
  2616   	sku = "14.04.2-LTS"
  2617   	version = "latest"
  2618       }
  2619  
  2620       storage_os_disk {
  2621           name = "myosdisk1"
  2622           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2623           caching = "ReadWrite"
  2624           create_option = "FromImage"
  2625       }
  2626  
  2627       os_profile {
  2628   	computer_name = "hn%d"
  2629   	admin_username = "testadmin"
  2630   	admin_password = "Password1234!"
  2631       }
  2632  
  2633       os_profile_linux_config {
  2634   	disable_password_authentication = false
  2635       }
  2636   }
  2637  `
  2638  
  2639  var testAccAzureRMVirtualMachine_updateMachineName = `
  2640   resource "azurerm_resource_group" "test" {
  2641       name = "acctestRG-%d"
  2642       location = "West US 2"
  2643   }
  2644  
  2645   resource "azurerm_virtual_network" "test" {
  2646       name = "acctvn-%d"
  2647       address_space = ["10.0.0.0/16"]
  2648       location = "West US 2"
  2649       resource_group_name = "${azurerm_resource_group.test.name}"
  2650   }
  2651  
  2652   resource "azurerm_subnet" "test" {
  2653       name = "acctsub-%d"
  2654       resource_group_name = "${azurerm_resource_group.test.name}"
  2655       virtual_network_name = "${azurerm_virtual_network.test.name}"
  2656       address_prefix = "10.0.2.0/24"
  2657   }
  2658  
  2659   resource "azurerm_network_interface" "test" {
  2660       name = "acctni-%d"
  2661       location = "West US 2"
  2662       resource_group_name = "${azurerm_resource_group.test.name}"
  2663  
  2664       ip_configuration {
  2665       	name = "testconfiguration1"
  2666       	subnet_id = "${azurerm_subnet.test.id}"
  2667       	private_ip_address_allocation = "dynamic"
  2668       }
  2669   }
  2670  
  2671   resource "azurerm_storage_account" "test" {
  2672       name = "accsa%d"
  2673       resource_group_name = "${azurerm_resource_group.test.name}"
  2674       location = "West US 2"
  2675       account_type = "Standard_LRS"
  2676  
  2677       tags {
  2678           environment = "staging"
  2679       }
  2680   }
  2681  
  2682   resource "azurerm_storage_container" "test" {
  2683       name = "vhds"
  2684       resource_group_name = "${azurerm_resource_group.test.name}"
  2685       storage_account_name = "${azurerm_storage_account.test.name}"
  2686       container_access_type = "private"
  2687   }
  2688  
  2689   resource "azurerm_virtual_machine" "test" {
  2690       name = "acctvm-%d"
  2691       location = "West US 2"
  2692       resource_group_name = "${azurerm_resource_group.test.name}"
  2693       network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2694       vm_size = "Standard_D1_v2"
  2695        delete_os_disk_on_termination = true
  2696  
  2697       storage_image_reference {
  2698   	publisher = "Canonical"
  2699   	offer = "UbuntuServer"
  2700   	sku = "14.04.2-LTS"
  2701   	version = "latest"
  2702       }
  2703  
  2704       storage_os_disk {
  2705           name = "myosdisk1"
  2706           vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2707           caching = "ReadWrite"
  2708           create_option = "FromImage"
  2709       }
  2710  
  2711       os_profile {
  2712   	computer_name = "newhostname%d"
  2713   	admin_username = "testadmin"
  2714   	admin_password = "Password1234!"
  2715       }
  2716  
  2717       os_profile_linux_config {
  2718   	disable_password_authentication = false
  2719       }
  2720   }
  2721   `
  2722  
  2723  var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore = `
  2724  resource "azurerm_resource_group" "test" {
  2725      name = "acctestRG-%d"
  2726      location = "West US 2"
  2727  }
  2728  
  2729  resource "azurerm_virtual_network" "test" {
  2730      name = "acctvn-%d"
  2731      address_space = ["10.0.0.0/16"]
  2732      location = "West US 2"
  2733      resource_group_name = "${azurerm_resource_group.test.name}"
  2734  }
  2735  
  2736  resource "azurerm_subnet" "test" {
  2737      name = "acctsub-%d"
  2738      resource_group_name = "${azurerm_resource_group.test.name}"
  2739      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2740      address_prefix = "10.0.2.0/24"
  2741  }
  2742  
  2743  resource "azurerm_network_interface" "test" {
  2744      name = "acctni-%d"
  2745      location = "West US 2"
  2746      resource_group_name = "${azurerm_resource_group.test.name}"
  2747  
  2748      ip_configuration {
  2749      	name = "testconfiguration1"
  2750      	subnet_id = "${azurerm_subnet.test.id}"
  2751      	private_ip_address_allocation = "dynamic"
  2752      }
  2753  }
  2754  
  2755  resource "azurerm_storage_account" "test" {
  2756      name = "accsa%d"
  2757      resource_group_name = "${azurerm_resource_group.test.name}"
  2758      location = "West US 2"
  2759      account_type = "Standard_LRS"
  2760  
  2761      tags {
  2762          environment = "staging"
  2763      }
  2764  }
  2765  
  2766  resource "azurerm_storage_container" "test" {
  2767      name = "vhds"
  2768      resource_group_name = "${azurerm_resource_group.test.name}"
  2769      storage_account_name = "${azurerm_storage_account.test.name}"
  2770      container_access_type = "private"
  2771  }
  2772  
  2773  resource "azurerm_virtual_machine" "test" {
  2774      name = "acctvm-%d"
  2775      location = "West US 2"
  2776      resource_group_name = "${azurerm_resource_group.test.name}"
  2777      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2778      vm_size = "Standard_D1_v2"
  2779      delete_os_disk_on_termination = true
  2780  
  2781      storage_image_reference {
  2782  	publisher = "Canonical"
  2783  	offer = "UbuntuServer"
  2784  	sku = "14.04.2-LTS"
  2785  	version = "latest"
  2786      }
  2787  
  2788      storage_os_disk {
  2789          name = "myosdisk1"
  2790          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2791          caching = "ReadWrite"
  2792          create_option = "FromImage"
  2793          disk_size_gb = "45"
  2794      }
  2795  
  2796      os_profile {
  2797  	computer_name = "hn%d"
  2798  	admin_username = "testadmin"
  2799  	admin_password = "Password1234!"
  2800      }
  2801  
  2802      os_profile_linux_config {
  2803  	disable_password_authentication = false
  2804      }
  2805  
  2806      tags {
  2807      	environment = "Production"
  2808      	cost-center = "Ops"
  2809      }
  2810  }
  2811  `
  2812  
  2813  var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter = `
  2814  resource "azurerm_resource_group" "test" {
  2815      name = "acctestRG-%d"
  2816      location = "West US 2"
  2817  }
  2818  
  2819  resource "azurerm_virtual_network" "test" {
  2820      name = "acctvn-%d"
  2821      address_space = ["10.0.0.0/16"]
  2822      location = "West US 2"
  2823      resource_group_name = "${azurerm_resource_group.test.name}"
  2824  }
  2825  
  2826  resource "azurerm_subnet" "test" {
  2827      name = "acctsub-%d"
  2828      resource_group_name = "${azurerm_resource_group.test.name}"
  2829      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2830      address_prefix = "10.0.2.0/24"
  2831  }
  2832  
  2833  resource "azurerm_network_interface" "test" {
  2834      name = "acctni-%d"
  2835      location = "West US 2"
  2836      resource_group_name = "${azurerm_resource_group.test.name}"
  2837  
  2838      ip_configuration {
  2839      	name = "testconfiguration1"
  2840      	subnet_id = "${azurerm_subnet.test.id}"
  2841      	private_ip_address_allocation = "dynamic"
  2842      }
  2843  }
  2844  
  2845  resource "azurerm_storage_account" "test" {
  2846      name = "accsa%d"
  2847      resource_group_name = "${azurerm_resource_group.test.name}"
  2848      location = "West US 2"
  2849      account_type = "Standard_LRS"
  2850  
  2851      tags {
  2852          environment = "staging"
  2853      }
  2854  }
  2855  
  2856  resource "azurerm_storage_container" "test" {
  2857      name = "vhds"
  2858      resource_group_name = "${azurerm_resource_group.test.name}"
  2859      storage_account_name = "${azurerm_storage_account.test.name}"
  2860      container_access_type = "private"
  2861  }
  2862  
  2863  resource "azurerm_virtual_machine" "test" {
  2864      name = "acctvm-%d"
  2865      location = "West US 2"
  2866      resource_group_name = "${azurerm_resource_group.test.name}"
  2867      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2868      vm_size = "Standard_D1_v2"
  2869      delete_os_disk_on_termination = true
  2870  
  2871      storage_image_reference {
  2872  	publisher = "CoreOS"
  2873  	offer = "CoreOS"
  2874  	sku = "Stable"
  2875  	version = "latest"
  2876      }
  2877  
  2878      storage_os_disk {
  2879          name = "myosdisk1"
  2880          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  2881          caching = "ReadWrite"
  2882          create_option = "FromImage"
  2883          disk_size_gb = "45"
  2884      }
  2885  
  2886      os_profile {
  2887  	computer_name = "hn%d"
  2888  	admin_username = "testadmin"
  2889  	admin_password = "Password1234!"
  2890      }
  2891  
  2892      os_profile_linux_config {
  2893  	disable_password_authentication = false
  2894      }
  2895  
  2896      tags {
  2897      	environment = "Production"
  2898      	cost-center = "Ops"
  2899      }
  2900  }
  2901  `
  2902  
  2903  var testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged = `
  2904  resource "azurerm_resource_group" "test" {
  2905      name = "acctestRG-%d"
  2906      location = "West US 2"
  2907  }
  2908  
  2909  resource "azurerm_virtual_network" "test" {
  2910      name = "acctvn-%d"
  2911      address_space = ["10.0.0.0/16"]
  2912      location = "West US 2"
  2913      resource_group_name = "${azurerm_resource_group.test.name}"
  2914  }
  2915  
  2916  resource "azurerm_subnet" "test" {
  2917      name = "acctsub-%d"
  2918      resource_group_name = "${azurerm_resource_group.test.name}"
  2919      virtual_network_name = "${azurerm_virtual_network.test.name}"
  2920      address_prefix = "10.0.2.0/24"
  2921  }
  2922  
  2923  resource "azurerm_network_interface" "test" {
  2924      name = "acctni-%d"
  2925      location = "West US 2"
  2926      resource_group_name = "${azurerm_resource_group.test.name}"
  2927  
  2928      ip_configuration {
  2929      	name = "testconfiguration1"
  2930      	subnet_id = "${azurerm_subnet.test.id}"
  2931      	private_ip_address_allocation = "dynamic"
  2932      }
  2933  }
  2934  
  2935  resource "azurerm_storage_account" "test" {
  2936      name = "accsa%d"
  2937      resource_group_name = "${azurerm_resource_group.test.name}"
  2938      location = "West US 2"
  2939      account_type = "Standard_LRS"
  2940  
  2941      tags {
  2942          environment = "staging"
  2943      }
  2944  }
  2945  
  2946  resource "azurerm_storage_container" "test" {
  2947      name = "vhds"
  2948      resource_group_name = "${azurerm_resource_group.test.name}"
  2949      storage_account_name = "${azurerm_storage_account.test.name}"
  2950      container_access_type = "private"
  2951  }
  2952  
  2953  resource "azurerm_virtual_machine" "test" {
  2954      name = "acctvm-%d"
  2955      location = "West US 2"
  2956      resource_group_name = "${azurerm_resource_group.test.name}"
  2957      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  2958      vm_size = "Standard_D1_v2"
  2959  
  2960      storage_image_reference {
  2961  	publisher = "Canonical"
  2962  	offer = "UbuntuServer"
  2963  	sku = "14.04.2-LTS"
  2964  	version = "latest"
  2965      }
  2966  
  2967      storage_os_disk {
  2968          name = "myosdisk1"
  2969          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdiskchanged2.vhd"
  2970          caching = "ReadWrite"
  2971          create_option = "FromImage"
  2972          disk_size_gb = "45"
  2973      }
  2974  
  2975      os_profile {
  2976  	computer_name = "hn%d"
  2977  	admin_username = "testadmin"
  2978  	admin_password = "Password1234!"
  2979      }
  2980  
  2981      os_profile_linux_config {
  2982  	disable_password_authentication = false
  2983      }
  2984  
  2985      tags {
  2986      	environment = "Production"
  2987      	cost-center = "Ops"
  2988      }
  2989  }
  2990  `
  2991  
  2992  var testAccAzureRMVirtualMachine_windowsLicenseType = `
  2993  resource "azurerm_resource_group" "test" {
  2994      name = "acctestRG-%d"
  2995      location = "West US 2"
  2996  }
  2997  
  2998  resource "azurerm_virtual_network" "test" {
  2999      name = "acctvn-%d"
  3000      address_space = ["10.0.0.0/16"]
  3001      location = "West US 2"
  3002      resource_group_name = "${azurerm_resource_group.test.name}"
  3003  }
  3004  
  3005  resource "azurerm_subnet" "test" {
  3006      name = "acctsub-%d"
  3007      resource_group_name = "${azurerm_resource_group.test.name}"
  3008      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3009      address_prefix = "10.0.2.0/24"
  3010  }
  3011  
  3012  resource "azurerm_network_interface" "test" {
  3013      name = "acctni-%d"
  3014      location = "West US 2"
  3015      resource_group_name = "${azurerm_resource_group.test.name}"
  3016  
  3017      ip_configuration {
  3018      	name = "testconfiguration1"
  3019      	subnet_id = "${azurerm_subnet.test.id}"
  3020      	private_ip_address_allocation = "dynamic"
  3021      }
  3022  }
  3023  
  3024  resource "azurerm_storage_account" "test" {
  3025      name = "accsa%d"
  3026      resource_group_name = "${azurerm_resource_group.test.name}"
  3027      location = "West US 2"
  3028      account_type = "Standard_LRS"
  3029  
  3030      tags {
  3031          environment = "staging"
  3032      }
  3033  }
  3034  
  3035  resource "azurerm_storage_container" "test" {
  3036      name = "vhds"
  3037      resource_group_name = "${azurerm_resource_group.test.name}"
  3038      storage_account_name = "${azurerm_storage_account.test.name}"
  3039      container_access_type = "private"
  3040  }
  3041  
  3042  resource "azurerm_virtual_machine" "test" {
  3043      name = "acctvm-%d"
  3044      location = "West US 2"
  3045      resource_group_name = "${azurerm_resource_group.test.name}"
  3046      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3047      vm_size = "Standard_D1_v2"
  3048      license_type = "Windows_Server"
  3049  
  3050      storage_image_reference {
  3051  	publisher = "MicrosoftWindowsServer"
  3052  	offer = "WindowsServer-HUB"
  3053  	sku = "2008-R2-SP1-HUB"
  3054  	version = "latest"
  3055      }
  3056  
  3057      storage_os_disk {
  3058          name = "myosdisk1"
  3059          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3060          caching = "ReadWrite"
  3061          create_option = "FromImage"
  3062      }
  3063  
  3064      os_profile {
  3065  	computer_name = "winhost01"
  3066  	admin_username = "testadmin"
  3067  	admin_password = "Password1234!"
  3068      }
  3069  
  3070      os_profile_windows_config {
  3071  	enable_automatic_upgrades = false
  3072  	provision_vm_agent = true
  3073      }
  3074  }
  3075  `
  3076  
  3077  var testAccAzureRMVirtualMachine_plan = `
  3078  resource "azurerm_resource_group" "test" {
  3079      name = "acctestRG-%d"
  3080      location = "West US 2"
  3081  }
  3082  
  3083  resource "azurerm_virtual_network" "test" {
  3084      name = "acctvn-%d"
  3085      address_space = ["10.0.0.0/16"]
  3086      location = "West US 2"
  3087      resource_group_name = "${azurerm_resource_group.test.name}"
  3088  }
  3089  
  3090  resource "azurerm_subnet" "test" {
  3091      name = "acctsub-%d"
  3092      resource_group_name = "${azurerm_resource_group.test.name}"
  3093      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3094      address_prefix = "10.0.2.0/24"
  3095  }
  3096  
  3097  resource "azurerm_network_interface" "test" {
  3098      name = "acctni-%d"
  3099      location = "West US 2"
  3100      resource_group_name = "${azurerm_resource_group.test.name}"
  3101  
  3102      ip_configuration {
  3103      	name = "testconfiguration1"
  3104      	subnet_id = "${azurerm_subnet.test.id}"
  3105      	private_ip_address_allocation = "dynamic"
  3106      }
  3107  }
  3108  
  3109  resource "azurerm_storage_account" "test" {
  3110      name = "accsa%d"
  3111      resource_group_name = "${azurerm_resource_group.test.name}"
  3112      location = "West US 2"
  3113      account_type = "Standard_LRS"
  3114  
  3115      tags {
  3116          environment = "staging"
  3117      }
  3118  }
  3119  
  3120  resource "azurerm_storage_container" "test" {
  3121      name = "vhds"
  3122      resource_group_name = "${azurerm_resource_group.test.name}"
  3123      storage_account_name = "${azurerm_storage_account.test.name}"
  3124      container_access_type = "private"
  3125  }
  3126  
  3127  resource "azurerm_virtual_machine" "test" {
  3128      name = "acctvm-%d"
  3129      location = "West US 2"
  3130      resource_group_name = "${azurerm_resource_group.test.name}"
  3131      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3132      vm_size = "Standard_DS1_v2"
  3133  
  3134      storage_image_reference {
  3135  	publisher = "kemptech"
  3136  	offer = "vlm-azure"
  3137  	sku = "freeloadmaster"
  3138  	version = "latest"
  3139      }
  3140  
  3141      storage_os_disk {
  3142          name = "myosdisk1"
  3143          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3144          caching = "ReadWrite"
  3145          create_option = "FromImage"
  3146          disk_size_gb = "45"
  3147      }
  3148  
  3149      os_profile {
  3150  	computer_name = "hn%d"
  3151  	admin_username = "testadmin"
  3152  	admin_password = "Password1234!"
  3153      }
  3154  
  3155      os_profile_linux_config {
  3156  	disable_password_authentication = false
  3157      }
  3158  
  3159      plan {
  3160          name = "freeloadmaster"
  3161          publisher = "kemptech"
  3162          product = "vlm-azure"
  3163      }
  3164  
  3165      tags {
  3166      	environment = "Production"
  3167      	cost-center = "Ops"
  3168      }
  3169  }
  3170  `
  3171  
  3172  var testAccAzureRMVirtualMachine_linuxMachineWithSSH = `
  3173  resource "azurerm_resource_group" "test" {
  3174      name = "acctestrg%s"
  3175      location = "southcentralus"
  3176  }
  3177  
  3178  resource "azurerm_virtual_network" "test" {
  3179      name = "acctvn%s"
  3180      address_space = ["10.0.0.0/16"]
  3181      location = "southcentralus"
  3182      resource_group_name = "${azurerm_resource_group.test.name}"
  3183  }
  3184  
  3185  resource "azurerm_subnet" "test" {
  3186      name = "acctsub%s"
  3187      resource_group_name = "${azurerm_resource_group.test.name}"
  3188      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3189      address_prefix = "10.0.2.0/24"
  3190  }
  3191  
  3192  resource "azurerm_network_interface" "test" {
  3193      name = "acctni%s"
  3194      location = "southcentralus"
  3195      resource_group_name = "${azurerm_resource_group.test.name}"
  3196  
  3197      ip_configuration {
  3198      	name = "testconfiguration1"
  3199      	subnet_id = "${azurerm_subnet.test.id}"
  3200      	private_ip_address_allocation = "dynamic"
  3201      }
  3202  }
  3203  
  3204  resource "azurerm_storage_account" "test" {
  3205      name = "accsa%s"
  3206      resource_group_name = "${azurerm_resource_group.test.name}"
  3207      location = "southcentralus"
  3208      account_type = "Standard_LRS"
  3209  }
  3210  
  3211  resource "azurerm_storage_container" "test" {
  3212      name = "vhds"
  3213      resource_group_name = "${azurerm_resource_group.test.name}"
  3214      storage_account_name = "${azurerm_storage_account.test.name}"
  3215      container_access_type = "private"
  3216  }
  3217  
  3218  resource "azurerm_virtual_machine" "test" {
  3219      name = "acctvm%s"
  3220      location = "southcentralus"
  3221      resource_group_name = "${azurerm_resource_group.test.name}"
  3222      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3223      vm_size = "Standard_D1_v2"
  3224  
  3225      storage_image_reference {
  3226          publisher = "Canonical"
  3227          offer = "UbuntuServer"
  3228          sku = "14.04.2-LTS"
  3229          version = "latest"
  3230      }
  3231  
  3232      storage_os_disk {
  3233          name = "myosdisk1"
  3234          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3235          caching = "ReadWrite"
  3236          create_option = "FromImage"
  3237          disk_size_gb = "45"
  3238      }
  3239  
  3240      os_profile {
  3241          computer_name = "hostname%s"
  3242          admin_username = "testadmin"
  3243          admin_password = "Password1234!"
  3244      }
  3245  
  3246      os_profile_linux_config {
  3247  	    disable_password_authentication = true
  3248          ssh_keys {
  3249              path = "/home/testadmin/.ssh/authorized_keys"
  3250              key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCfGyt5W1eJVpDIxlyvAWO594j/azEGohmlxYe7mgSfmUCWjuzILI6nHuHbxhpBDIZJhQ+JAeduXpii61dmThbI89ghGMhzea0OlT3p12e093zqa4goB9g40jdNKmJArER3pMVqs6hmv8y3GlUNkMDSmuoyI8AYzX4n26cUKZbwXQ== mk@mk3"
  3251          }
  3252      }
  3253  }
  3254  `
  3255  
  3256  var testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved = `
  3257  resource "azurerm_resource_group" "test" {
  3258      name = "acctestrg%s"
  3259      location = "southcentralus"
  3260  }
  3261  
  3262  resource "azurerm_virtual_network" "test" {
  3263      name = "acctvn%s"
  3264      address_space = ["10.0.0.0/16"]
  3265      location = "southcentralus"
  3266      resource_group_name = "${azurerm_resource_group.test.name}"
  3267  }
  3268  
  3269  resource "azurerm_subnet" "test" {
  3270      name = "acctsub%s"
  3271      resource_group_name = "${azurerm_resource_group.test.name}"
  3272      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3273      address_prefix = "10.0.2.0/24"
  3274  }
  3275  
  3276  resource "azurerm_network_interface" "test" {
  3277      name = "acctni%s"
  3278      location = "southcentralus"
  3279      resource_group_name = "${azurerm_resource_group.test.name}"
  3280  
  3281      ip_configuration {
  3282      	name = "testconfiguration1"
  3283      	subnet_id = "${azurerm_subnet.test.id}"
  3284      	private_ip_address_allocation = "dynamic"
  3285      }
  3286  }
  3287  
  3288  resource "azurerm_storage_account" "test" {
  3289      name = "accsa%s"
  3290      resource_group_name = "${azurerm_resource_group.test.name}"
  3291      location = "southcentralus"
  3292      account_type = "Standard_LRS"
  3293  }
  3294  
  3295  resource "azurerm_storage_container" "test" {
  3296      name = "vhds"
  3297      resource_group_name = "${azurerm_resource_group.test.name}"
  3298      storage_account_name = "${azurerm_storage_account.test.name}"
  3299      container_access_type = "private"
  3300  }
  3301  
  3302  resource "azurerm_virtual_machine" "test" {
  3303      name = "acctvm%s"
  3304      location = "southcentralus"
  3305      resource_group_name = "${azurerm_resource_group.test.name}"
  3306      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3307      vm_size = "Standard_D1_v2"
  3308  
  3309      storage_image_reference {
  3310          publisher = "Canonical"
  3311          offer = "UbuntuServer"
  3312          sku = "14.04.2-LTS"
  3313          version = "latest"
  3314      }
  3315  
  3316      storage_os_disk {
  3317          name = "myosdisk1"
  3318          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3319          caching = "ReadWrite"
  3320          create_option = "FromImage"
  3321          disk_size_gb = "45"
  3322      }
  3323  
  3324      os_profile {
  3325          computer_name = "hostname%s"
  3326          admin_username = "testadmin"
  3327          admin_password = "Password1234!"
  3328      }
  3329  
  3330      os_profile_linux_config {
  3331  	    disable_password_authentication = true
  3332      }
  3333  }
  3334  `
  3335  var testAccAzureRMVirtualMachine_osDiskTypeConflict = `
  3336  resource "azurerm_resource_group" "test" {
  3337      name = "acctestRG-%d"
  3338      location = "West US 2"
  3339  }
  3340  
  3341  resource "azurerm_virtual_network" "test" {
  3342      name = "acctvn-%d"
  3343      address_space = ["10.0.0.0/16"]
  3344      location = "West US 2"
  3345      resource_group_name = "${azurerm_resource_group.test.name}"
  3346  }
  3347  
  3348  resource "azurerm_subnet" "test" {
  3349      name = "acctsub-%d"
  3350      resource_group_name = "${azurerm_resource_group.test.name}"
  3351      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3352      address_prefix = "10.0.2.0/24"
  3353  }
  3354  
  3355  resource "azurerm_network_interface" "test" {
  3356      name = "acctni-%d"
  3357      location = "West US 2"
  3358      resource_group_name = "${azurerm_resource_group.test.name}"
  3359  
  3360      ip_configuration {
  3361      	name = "testconfiguration1"
  3362      	subnet_id = "${azurerm_subnet.test.id}"
  3363      	private_ip_address_allocation = "dynamic"
  3364      }
  3365  }
  3366  
  3367  resource "azurerm_virtual_machine" "test" {
  3368      name = "acctvm-%d"
  3369      location = "West US 2"
  3370      resource_group_name = "${azurerm_resource_group.test.name}"
  3371      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3372      vm_size = "Standard_D1_v2"
  3373  
  3374      storage_image_reference {
  3375  	publisher = "Canonical"
  3376  	offer = "UbuntuServer"
  3377  	sku = "14.04.2-LTS"
  3378  	version = "latest"
  3379      }
  3380  
  3381      storage_os_disk {
  3382          name = "osd-%d"
  3383          caching = "ReadWrite"
  3384          create_option = "FromImage"
  3385          disk_size_gb = "10"
  3386          managed_disk_type = "Standard_LRS"
  3387          vhd_uri = "should_cause_conflict"
  3388      }
  3389  
  3390      storage_data_disk {
  3391          name = "mydatadisk1"
  3392          caching = "ReadWrite"
  3393          create_option = "Empty"
  3394          disk_size_gb = "45"
  3395          managed_disk_type = "Standard_LRS"
  3396          lun = "0"
  3397      }
  3398  
  3399      os_profile {
  3400  	computer_name = "hn%d"
  3401  	admin_username = "testadmin"
  3402  	admin_password = "Password1234!"
  3403      }
  3404  
  3405      os_profile_linux_config {
  3406  	disable_password_authentication = false
  3407      }
  3408  
  3409      tags {
  3410      	environment = "Production"
  3411      	cost-center = "Ops"
  3412      }
  3413  }
  3414  `
  3415  
  3416  var testAccAzureRMVirtualMachine_dataDiskTypeConflict = `
  3417  resource "azurerm_resource_group" "test" {
  3418      name = "acctestRG-%d"
  3419      location = "West US 2"
  3420  }
  3421  
  3422  resource "azurerm_virtual_network" "test" {
  3423      name = "acctvn-%d"
  3424      address_space = ["10.0.0.0/16"]
  3425      location = "West US 2"
  3426      resource_group_name = "${azurerm_resource_group.test.name}"
  3427  }
  3428  
  3429  resource "azurerm_subnet" "test" {
  3430      name = "acctsub-%d"
  3431      resource_group_name = "${azurerm_resource_group.test.name}"
  3432      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3433      address_prefix = "10.0.2.0/24"
  3434  }
  3435  
  3436  resource "azurerm_network_interface" "test" {
  3437      name = "acctni-%d"
  3438      location = "West US 2"
  3439      resource_group_name = "${azurerm_resource_group.test.name}"
  3440  
  3441      ip_configuration {
  3442      	name = "testconfiguration1"
  3443      	subnet_id = "${azurerm_subnet.test.id}"
  3444      	private_ip_address_allocation = "dynamic"
  3445      }
  3446  }
  3447  
  3448  resource "azurerm_virtual_machine" "test" {
  3449      name = "acctvm-%d"
  3450      location = "West US 2"
  3451      resource_group_name = "${azurerm_resource_group.test.name}"
  3452      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3453      vm_size = "Standard_D1_v2"
  3454  
  3455      storage_image_reference {
  3456  	publisher = "Canonical"
  3457  	offer = "UbuntuServer"
  3458  	sku = "14.04.2-LTS"
  3459  	version = "latest"
  3460      }
  3461  
  3462      storage_os_disk {
  3463          name = "osd-%d"
  3464          caching = "ReadWrite"
  3465          create_option = "FromImage"
  3466          disk_size_gb = "10"
  3467          managed_disk_type = "Standard_LRS"
  3468      }
  3469  
  3470      storage_data_disk {
  3471          name = "mydatadisk1"
  3472          caching = "ReadWrite"
  3473          create_option = "Empty"
  3474          disk_size_gb = "45"
  3475          managed_disk_type = "Standard_LRS"
  3476          lun = "0"
  3477      }
  3478  
  3479      storage_data_disk {
  3480          name = "mydatadisk1"
  3481          vhd_uri = "should_cause_conflict"
  3482          caching = "ReadWrite"
  3483          create_option = "Empty"
  3484          disk_size_gb = "45"
  3485          managed_disk_type = "Standard_LRS"
  3486          lun = "1"
  3487      }
  3488  
  3489      os_profile {
  3490  	computer_name = "hn%d"
  3491  	admin_username = "testadmin"
  3492  	admin_password = "Password1234!"
  3493      }
  3494  
  3495      os_profile_linux_config {
  3496  	disable_password_authentication = false
  3497      }
  3498  
  3499      tags {
  3500      	environment = "Production"
  3501      	cost-center = "Ops"
  3502      }
  3503  }
  3504  `
  3505  
  3506  var testAccAzureRMVirtualMachine_primaryNetworkInterfaceId = `
  3507  resource "azurerm_resource_group" "test" {
  3508      name = "acctestRG-%d"
  3509      location = "West US"
  3510  }
  3511  
  3512  resource "azurerm_virtual_network" "test" {
  3513      name = "acctvn-%d"
  3514      address_space = ["10.0.0.0/16"]
  3515      location = "West US"
  3516      resource_group_name = "${azurerm_resource_group.test.name}"
  3517  }
  3518  
  3519  resource "azurerm_subnet" "test" {
  3520      name = "acctsub-%d"
  3521      resource_group_name = "${azurerm_resource_group.test.name}"
  3522      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3523      address_prefix = "10.0.2.0/24"
  3524  }
  3525  
  3526  resource "azurerm_network_interface" "test" {
  3527      name = "acctni-%d"
  3528      location = "West US"
  3529      resource_group_name = "${azurerm_resource_group.test.name}"
  3530  
  3531      ip_configuration {
  3532      	name = "testconfiguration1"
  3533      	subnet_id = "${azurerm_subnet.test.id}"
  3534      	private_ip_address_allocation = "dynamic"
  3535      }
  3536  }
  3537  
  3538  resource "azurerm_network_interface" "test2" {
  3539      name = "acctni2-%d"
  3540      location = "West US"
  3541      resource_group_name = "${azurerm_resource_group.test.name}"
  3542  
  3543      ip_configuration {
  3544      	name = "testconfiguration2"
  3545      	subnet_id = "${azurerm_subnet.test.id}"
  3546      	private_ip_address_allocation = "dynamic"
  3547      }
  3548  }
  3549  
  3550  resource "azurerm_storage_account" "test" {
  3551      name = "accsa%d"
  3552      resource_group_name = "${azurerm_resource_group.test.name}"
  3553      location = "westus"
  3554      account_type = "Standard_LRS"
  3555  
  3556      tags {
  3557          environment = "staging"
  3558      }
  3559  }
  3560  
  3561  resource "azurerm_storage_container" "test" {
  3562      name = "vhds"
  3563      resource_group_name = "${azurerm_resource_group.test.name}"
  3564      storage_account_name = "${azurerm_storage_account.test.name}"
  3565      container_access_type = "private"
  3566  }
  3567  
  3568  resource "azurerm_virtual_machine" "test" {
  3569      name = "acctvm-%d"
  3570      location = "West US"
  3571      resource_group_name = "${azurerm_resource_group.test.name}"
  3572      network_interface_ids = ["${azurerm_network_interface.test.id}","${azurerm_network_interface.test2.id}"]
  3573      primary_network_interface_id = "${azurerm_network_interface.test.id}"
  3574      vm_size = "Standard_A3"
  3575  
  3576      storage_image_reference {
  3577  	publisher = "Canonical"
  3578  	offer = "UbuntuServer"
  3579  	sku = "14.04.2-LTS"
  3580  	version = "latest"
  3581      }
  3582  
  3583      storage_os_disk {
  3584          name = "myosdisk1"
  3585          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3586          caching = "ReadWrite"
  3587          create_option = "FromImage"
  3588          disk_size_gb = "45"
  3589      }
  3590  
  3591      os_profile {
  3592  	computer_name = "hostname"
  3593  	admin_username = "testadmin"
  3594  	admin_password = "Password1234!"
  3595      }
  3596  
  3597      os_profile_linux_config {
  3598  	disable_password_authentication = false
  3599      }
  3600  
  3601      tags {
  3602      	environment = "Production"
  3603      	cost-center = "Ops"
  3604      }
  3605  }
  3606  `
  3607  var testAccAzureRMVirtualMachine_basicLinuxMachine_destroy = `
  3608  resource "azurerm_resource_group" "test" {
  3609      name = "acctestRG-%d"
  3610      location = "West US 2"
  3611  }
  3612  
  3613  resource "azurerm_virtual_network" "test" {
  3614      name = "acctvn-%d"
  3615      address_space = ["10.0.0.0/16"]
  3616      location = "West US 2"
  3617      resource_group_name = "${azurerm_resource_group.test.name}"
  3618  }
  3619  
  3620  resource "azurerm_subnet" "test" {
  3621      name = "acctsub-%d"
  3622      resource_group_name = "${azurerm_resource_group.test.name}"
  3623      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3624      address_prefix = "10.0.2.0/24"
  3625  }
  3626  
  3627  resource "azurerm_network_interface" "test" {
  3628      name = "acctni-%d"
  3629      location = "West US 2"
  3630      resource_group_name = "${azurerm_resource_group.test.name}"
  3631  
  3632      ip_configuration {
  3633      	name = "testconfiguration1"
  3634      	subnet_id = "${azurerm_subnet.test.id}"
  3635      	private_ip_address_allocation = "dynamic"
  3636      }
  3637  }
  3638  
  3639  resource "azurerm_storage_account" "test" {
  3640      name = "accsa%d"
  3641      resource_group_name = "${azurerm_resource_group.test.name}"
  3642      location = "West US 2"
  3643      account_type = "Standard_LRS"
  3644  
  3645      tags {
  3646          environment = "staging"
  3647      }
  3648  }
  3649  
  3650  resource "azurerm_storage_container" "test" {
  3651      name = "vhds"
  3652      resource_group_name = "${azurerm_resource_group.test.name}"
  3653      storage_account_name = "${azurerm_storage_account.test.name}"
  3654      container_access_type = "private"
  3655  }
  3656  `
  3657  
  3658  var testAccAzureRMVirtualMachine_basicLinuxMachine_attach_without_osProfile = `
  3659  resource "azurerm_resource_group" "test" {
  3660      name = "acctestRG-%d"
  3661      location = "West US 2"
  3662  }
  3663  
  3664  resource "azurerm_virtual_network" "test" {
  3665      name = "acctvn-%d"
  3666      address_space = ["10.0.0.0/16"]
  3667      location = "West US 2"
  3668      resource_group_name = "${azurerm_resource_group.test.name}"
  3669  }
  3670  
  3671  resource "azurerm_subnet" "test" {
  3672      name = "acctsub-%d"
  3673      resource_group_name = "${azurerm_resource_group.test.name}"
  3674      virtual_network_name = "${azurerm_virtual_network.test.name}"
  3675      address_prefix = "10.0.2.0/24"
  3676  }
  3677  
  3678  resource "azurerm_network_interface" "test" {
  3679      name = "acctni-%d"
  3680      location = "West US 2"
  3681      resource_group_name = "${azurerm_resource_group.test.name}"
  3682  
  3683      ip_configuration {
  3684      	name = "testconfiguration1"
  3685      	subnet_id = "${azurerm_subnet.test.id}"
  3686      	private_ip_address_allocation = "dynamic"
  3687      }
  3688  }
  3689  
  3690  resource "azurerm_storage_account" "test" {
  3691      name = "accsa%d"
  3692      resource_group_name = "${azurerm_resource_group.test.name}"
  3693      location = "West US 2"
  3694      account_type = "Standard_LRS"
  3695  
  3696      tags {
  3697          environment = "staging"
  3698      }
  3699  }
  3700  
  3701  resource "azurerm_storage_container" "test" {
  3702      name = "vhds"
  3703      resource_group_name = "${azurerm_resource_group.test.name}"
  3704      storage_account_name = "${azurerm_storage_account.test.name}"
  3705      container_access_type = "private"
  3706  }
  3707  
  3708  resource "azurerm_virtual_machine" "test" {
  3709      name = "acctvm-%d"
  3710      location = "West US 2"
  3711      resource_group_name = "${azurerm_resource_group.test.name}"
  3712      network_interface_ids = ["${azurerm_network_interface.test.id}"]
  3713      vm_size = "Standard_F2"
  3714  
  3715      storage_os_disk {
  3716          name = "myosdisk1"
  3717          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
  3718          os_type = "linux"
  3719          caching = "ReadWrite"
  3720          create_option = "Attach"
  3721      }
  3722  
  3723      tags {
  3724      	environment = "Production"
  3725      	cost-center = "Ops"
  3726      }
  3727  }
  3728  `