github.com/memsql/terraform@v0.7.0-rc2.0.20160706152241-21e2173e0a32/builtin/providers/azurerm/resource_arm_virtual_machine_test.go (about)

     1  package azurerm
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/helper/acctest"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) {
    14  	ri := acctest.RandInt()
    15  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    16  	resource.Test(t, resource.TestCase{
    17  		PreCheck:     func() { testAccPreCheck(t) },
    18  		Providers:    testAccProviders,
    19  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    20  		Steps: []resource.TestStep{
    21  			{
    22  				Config: config,
    23  				Check: resource.ComposeTestCheckFunc(
    24  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
    25  				),
    26  			},
    27  		},
    28  	})
    29  }
    30  
    31  func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) {
    32  	ri := acctest.RandInt()
    33  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri)
    34  	resource.Test(t, resource.TestCase{
    35  		PreCheck:     func() { testAccPreCheck(t) },
    36  		Providers:    testAccProviders,
    37  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    38  		Steps: []resource.TestStep{
    39  			{
    40  				Config: config,
    41  				Check: resource.ComposeTestCheckFunc(
    42  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
    43  				),
    44  			},
    45  		},
    46  	})
    47  }
    48  
    49  func TestAccAzureRMVirtualMachine_tags(t *testing.T) {
    50  	ri := acctest.RandInt()
    51  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    52  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineUpdated, ri, ri, ri, ri, ri, ri, ri)
    53  	resource.Test(t, resource.TestCase{
    54  		PreCheck:     func() { testAccPreCheck(t) },
    55  		Providers:    testAccProviders,
    56  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    57  		Steps: []resource.TestStep{
    58  			{
    59  				Config: preConfig,
    60  				Check: resource.ComposeTestCheckFunc(
    61  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
    62  					resource.TestCheckResourceAttr(
    63  						"azurerm_virtual_machine.test", "tags.%", "2"),
    64  					resource.TestCheckResourceAttr(
    65  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
    66  					resource.TestCheckResourceAttr(
    67  						"azurerm_virtual_machine.test", "tags.cost-center", "Ops"),
    68  				),
    69  			},
    70  
    71  			{
    72  				Config: postConfig,
    73  				Check: resource.ComposeTestCheckFunc(
    74  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
    75  					resource.TestCheckResourceAttr(
    76  						"azurerm_virtual_machine.test", "tags.%", "1"),
    77  					resource.TestCheckResourceAttr(
    78  						"azurerm_virtual_machine.test", "tags.environment", "Production"),
    79  				),
    80  			},
    81  		},
    82  	})
    83  }
    84  
    85  //This is a regression test around https://github.com/hashicorp/terraform/issues/6517
    86  //Because we use CreateOrUpdate, we were sending an empty password on update requests
    87  func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) {
    88  	ri := acctest.RandInt()
    89  	preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    90  	postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
    91  	resource.Test(t, resource.TestCase{
    92  		PreCheck:     func() { testAccPreCheck(t) },
    93  		Providers:    testAccProviders,
    94  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
    95  		Steps: []resource.TestStep{
    96  			{
    97  				Config: preConfig,
    98  				Check: resource.ComposeTestCheckFunc(
    99  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
   100  					resource.TestCheckResourceAttr(
   101  						"azurerm_virtual_machine.test", "vm_size", "Standard_A0"),
   102  				),
   103  			},
   104  			{
   105  				Config: postConfig,
   106  				Check: resource.ComposeTestCheckFunc(
   107  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
   108  					resource.TestCheckResourceAttr(
   109  						"azurerm_virtual_machine.test", "vm_size", "Standard_A1"),
   110  				),
   111  			},
   112  		},
   113  	})
   114  }
   115  
   116  func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) {
   117  	ri := acctest.RandInt()
   118  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicWindowsMachine, ri, ri, ri, ri, ri, ri)
   119  	resource.Test(t, resource.TestCase{
   120  		PreCheck:     func() { testAccPreCheck(t) },
   121  		Providers:    testAccProviders,
   122  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   123  		Steps: []resource.TestStep{
   124  			{
   125  				Config: config,
   126  				Check: resource.ComposeTestCheckFunc(
   127  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
   128  				),
   129  			},
   130  		},
   131  	})
   132  }
   133  
   134  func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) {
   135  	ri := acctest.RandInt()
   136  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsUnattendedConfig, ri, ri, ri, ri, ri, ri)
   137  	resource.Test(t, resource.TestCase{
   138  		PreCheck:     func() { testAccPreCheck(t) },
   139  		Providers:    testAccProviders,
   140  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   141  		Steps: []resource.TestStep{
   142  			{
   143  				Config: config,
   144  				Check: resource.ComposeTestCheckFunc(
   145  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
   146  				),
   147  			},
   148  		},
   149  	})
   150  }
   151  
   152  func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) {
   153  	ri := acctest.RandInt()
   154  	config := fmt.Sprintf(testAccAzureRMVirtualMachine_winRMConfig, ri, ri, ri, ri, ri, ri)
   155  	resource.Test(t, resource.TestCase{
   156  		PreCheck:     func() { testAccPreCheck(t) },
   157  		Providers:    testAccProviders,
   158  		CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
   159  		Steps: []resource.TestStep{
   160  			{
   161  				Config: config,
   162  				Check: resource.ComposeTestCheckFunc(
   163  					testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test"),
   164  				),
   165  			},
   166  		},
   167  	})
   168  }
   169  
   170  func testCheckAzureRMVirtualMachineExists(name string) resource.TestCheckFunc {
   171  	return func(s *terraform.State) error {
   172  		// Ensure we have enough information in state to look up in API
   173  		rs, ok := s.RootModule().Resources[name]
   174  		if !ok {
   175  			return fmt.Errorf("Not found: %s", name)
   176  		}
   177  
   178  		vmName := rs.Primary.Attributes["name"]
   179  		resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
   180  		if !hasResourceGroup {
   181  			return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
   182  		}
   183  
   184  		conn := testAccProvider.Meta().(*ArmClient).vmClient
   185  
   186  		resp, err := conn.Get(resourceGroup, vmName, "")
   187  		if err != nil {
   188  			return fmt.Errorf("Bad: Get on vmClient: %s", err)
   189  		}
   190  
   191  		if resp.StatusCode == http.StatusNotFound {
   192  			return fmt.Errorf("Bad: VirtualMachine %q (resource group: %q) does not exist", vmName, resourceGroup)
   193  		}
   194  
   195  		return nil
   196  	}
   197  }
   198  
   199  func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error {
   200  	conn := testAccProvider.Meta().(*ArmClient).vmClient
   201  
   202  	for _, rs := range s.RootModule().Resources {
   203  		if rs.Type != "azurerm_virtual_machine" {
   204  			continue
   205  		}
   206  
   207  		name := rs.Primary.Attributes["name"]
   208  		resourceGroup := rs.Primary.Attributes["resource_group_name"]
   209  
   210  		resp, err := conn.Get(resourceGroup, name, "")
   211  
   212  		if err != nil {
   213  			return nil
   214  		}
   215  
   216  		if resp.StatusCode != http.StatusNotFound {
   217  			return fmt.Errorf("Virtual Machine still exists:\n%#v", resp.Properties)
   218  		}
   219  	}
   220  
   221  	return nil
   222  }
   223  
   224  var testAccAzureRMVirtualMachine_basicLinuxMachine = `
   225  resource "azurerm_resource_group" "test" {
   226      name = "acctestrg-%d"
   227      location = "West US"
   228  }
   229  
   230  resource "azurerm_virtual_network" "test" {
   231      name = "acctvn-%d"
   232      address_space = ["10.0.0.0/16"]
   233      location = "West US"
   234      resource_group_name = "${azurerm_resource_group.test.name}"
   235  }
   236  
   237  resource "azurerm_subnet" "test" {
   238      name = "acctsub-%d"
   239      resource_group_name = "${azurerm_resource_group.test.name}"
   240      virtual_network_name = "${azurerm_virtual_network.test.name}"
   241      address_prefix = "10.0.2.0/24"
   242  }
   243  
   244  resource "azurerm_network_interface" "test" {
   245      name = "acctni-%d"
   246      location = "West US"
   247      resource_group_name = "${azurerm_resource_group.test.name}"
   248  
   249      ip_configuration {
   250      	name = "testconfiguration1"
   251      	subnet_id = "${azurerm_subnet.test.id}"
   252      	private_ip_address_allocation = "dynamic"
   253      }
   254  }
   255  
   256  resource "azurerm_storage_account" "test" {
   257      name = "accsa%d"
   258      resource_group_name = "${azurerm_resource_group.test.name}"
   259      location = "westus"
   260      account_type = "Standard_LRS"
   261  
   262      tags {
   263          environment = "staging"
   264      }
   265  }
   266  
   267  resource "azurerm_storage_container" "test" {
   268      name = "vhds"
   269      resource_group_name = "${azurerm_resource_group.test.name}"
   270      storage_account_name = "${azurerm_storage_account.test.name}"
   271      container_access_type = "private"
   272  }
   273  
   274  resource "azurerm_virtual_machine" "test" {
   275      name = "acctvm-%d"
   276      location = "West US"
   277      resource_group_name = "${azurerm_resource_group.test.name}"
   278      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   279      vm_size = "Standard_A0"
   280  
   281      storage_image_reference {
   282  	publisher = "Canonical"
   283  	offer = "UbuntuServer"
   284  	sku = "14.04.2-LTS"
   285  	version = "latest"
   286      }
   287  
   288      storage_os_disk {
   289          name = "myosdisk1"
   290          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   291          caching = "ReadWrite"
   292          create_option = "FromImage"
   293      }
   294  
   295      os_profile {
   296  	computer_name = "hostname%d"
   297  	admin_username = "testadmin"
   298  	admin_password = "Password1234!"
   299      }
   300  
   301      os_profile_linux_config {
   302  	disable_password_authentication = false
   303      }
   304  
   305      tags {
   306      	environment = "Production"
   307      	cost-center = "Ops"
   308      }
   309  }
   310  `
   311  
   312  var testAccAzureRMVirtualMachine_withDataDisk = `
   313  resource "azurerm_resource_group" "test" {
   314      name = "acctestrg-%d"
   315      location = "West US"
   316  }
   317  
   318  resource "azurerm_virtual_network" "test" {
   319      name = "acctvn-%d"
   320      address_space = ["10.0.0.0/16"]
   321      location = "West US"
   322      resource_group_name = "${azurerm_resource_group.test.name}"
   323  }
   324  
   325  resource "azurerm_subnet" "test" {
   326      name = "acctsub-%d"
   327      resource_group_name = "${azurerm_resource_group.test.name}"
   328      virtual_network_name = "${azurerm_virtual_network.test.name}"
   329      address_prefix = "10.0.2.0/24"
   330  }
   331  
   332  resource "azurerm_network_interface" "test" {
   333      name = "acctni-%d"
   334      location = "West US"
   335      resource_group_name = "${azurerm_resource_group.test.name}"
   336  
   337      ip_configuration {
   338      	name = "testconfiguration1"
   339      	subnet_id = "${azurerm_subnet.test.id}"
   340      	private_ip_address_allocation = "dynamic"
   341      }
   342  }
   343  
   344  resource "azurerm_storage_account" "test" {
   345      name = "accsa%d"
   346      resource_group_name = "${azurerm_resource_group.test.name}"
   347      location = "westus"
   348      account_type = "Standard_LRS"
   349  
   350      tags {
   351          environment = "staging"
   352      }
   353  }
   354  
   355  resource "azurerm_storage_container" "test" {
   356      name = "vhds"
   357      resource_group_name = "${azurerm_resource_group.test.name}"
   358      storage_account_name = "${azurerm_storage_account.test.name}"
   359      container_access_type = "private"
   360  }
   361  
   362  resource "azurerm_virtual_machine" "test" {
   363      name = "acctvm-%d"
   364      location = "West US"
   365      resource_group_name = "${azurerm_resource_group.test.name}"
   366      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   367      vm_size = "Standard_A0"
   368  
   369      storage_image_reference {
   370  	publisher = "Canonical"
   371  	offer = "UbuntuServer"
   372  	sku = "14.04.2-LTS"
   373  	version = "latest"
   374      }
   375  
   376      storage_os_disk {
   377          name = "myosdisk1"
   378          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   379          caching = "ReadWrite"
   380          create_option = "FromImage"
   381      }
   382  
   383      storage_data_disk {
   384          name          = "mydatadisk1"
   385          vhd_uri       = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd"
   386      	disk_size_gb  = "1023"
   387      	create_option = "Empty"
   388      	lun           = 0
   389      }
   390  
   391      os_profile {
   392  	computer_name = "hostname%d"
   393  	admin_username = "testadmin"
   394  	admin_password = "Password1234!"
   395      }
   396  
   397      os_profile_linux_config {
   398  	disable_password_authentication = false
   399      }
   400  
   401      tags {
   402      	environment = "Production"
   403      	cost-center = "Ops"
   404      }
   405  }
   406  `
   407  
   408  var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = `
   409  resource "azurerm_resource_group" "test" {
   410      name = "acctestrg-%d"
   411      location = "West US"
   412  }
   413  
   414  resource "azurerm_virtual_network" "test" {
   415      name = "acctvn-%d"
   416      address_space = ["10.0.0.0/16"]
   417      location = "West US"
   418      resource_group_name = "${azurerm_resource_group.test.name}"
   419  }
   420  
   421  resource "azurerm_subnet" "test" {
   422      name = "acctsub-%d"
   423      resource_group_name = "${azurerm_resource_group.test.name}"
   424      virtual_network_name = "${azurerm_virtual_network.test.name}"
   425      address_prefix = "10.0.2.0/24"
   426  }
   427  
   428  resource "azurerm_network_interface" "test" {
   429      name = "acctni-%d"
   430      location = "West US"
   431      resource_group_name = "${azurerm_resource_group.test.name}"
   432  
   433      ip_configuration {
   434      	name = "testconfiguration1"
   435      	subnet_id = "${azurerm_subnet.test.id}"
   436      	private_ip_address_allocation = "dynamic"
   437      }
   438  }
   439  
   440  resource "azurerm_storage_account" "test" {
   441      name = "accsa%d"
   442      resource_group_name = "${azurerm_resource_group.test.name}"
   443      location = "westus"
   444      account_type = "Standard_LRS"
   445  
   446      tags {
   447          environment = "staging"
   448      }
   449  }
   450  
   451  resource "azurerm_storage_container" "test" {
   452      name = "vhds"
   453      resource_group_name = "${azurerm_resource_group.test.name}"
   454      storage_account_name = "${azurerm_storage_account.test.name}"
   455      container_access_type = "private"
   456  }
   457  
   458  resource "azurerm_virtual_machine" "test" {
   459      name = "acctvm-%d"
   460      location = "West US"
   461      resource_group_name = "${azurerm_resource_group.test.name}"
   462      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   463      vm_size = "Standard_A0"
   464  
   465      storage_image_reference {
   466  	publisher = "Canonical"
   467  	offer = "UbuntuServer"
   468  	sku = "14.04.2-LTS"
   469  	version = "latest"
   470      }
   471  
   472      storage_os_disk {
   473          name = "myosdisk1"
   474          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   475          caching = "ReadWrite"
   476          create_option = "FromImage"
   477      }
   478  
   479      os_profile {
   480  	computer_name = "hostname%d"
   481  	admin_username = "testadmin"
   482  	admin_password = "Password1234!"
   483      }
   484  
   485      os_profile_linux_config {
   486  	disable_password_authentication = false
   487      }
   488  
   489      tags {
   490      	environment = "Production"
   491      }
   492  }
   493  `
   494  
   495  var testAccAzureRMVirtualMachine_updatedLinuxMachine = `
   496  resource "azurerm_resource_group" "test" {
   497      name = "acctestrg-%d"
   498      location = "West US"
   499  }
   500  
   501  resource "azurerm_virtual_network" "test" {
   502      name = "acctvn-%d"
   503      address_space = ["10.0.0.0/16"]
   504      location = "West US"
   505      resource_group_name = "${azurerm_resource_group.test.name}"
   506  }
   507  
   508  resource "azurerm_subnet" "test" {
   509      name = "acctsub-%d"
   510      resource_group_name = "${azurerm_resource_group.test.name}"
   511      virtual_network_name = "${azurerm_virtual_network.test.name}"
   512      address_prefix = "10.0.2.0/24"
   513  }
   514  
   515  resource "azurerm_network_interface" "test" {
   516      name = "acctni-%d"
   517      location = "West US"
   518      resource_group_name = "${azurerm_resource_group.test.name}"
   519  
   520      ip_configuration {
   521      	name = "testconfiguration1"
   522      	subnet_id = "${azurerm_subnet.test.id}"
   523      	private_ip_address_allocation = "dynamic"
   524      }
   525  }
   526  
   527  resource "azurerm_storage_account" "test" {
   528      name = "accsa%d"
   529      resource_group_name = "${azurerm_resource_group.test.name}"
   530      location = "westus"
   531      account_type = "Standard_LRS"
   532  
   533      tags {
   534          environment = "staging"
   535      }
   536  }
   537  
   538  resource "azurerm_storage_container" "test" {
   539      name = "vhds"
   540      resource_group_name = "${azurerm_resource_group.test.name}"
   541      storage_account_name = "${azurerm_storage_account.test.name}"
   542      container_access_type = "private"
   543  }
   544  
   545  resource "azurerm_virtual_machine" "test" {
   546      name = "acctvm-%d"
   547      location = "West US"
   548      resource_group_name = "${azurerm_resource_group.test.name}"
   549      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   550      vm_size = "Standard_A1"
   551  
   552      storage_image_reference {
   553  	publisher = "Canonical"
   554  	offer = "UbuntuServer"
   555  	sku = "14.04.2-LTS"
   556  	version = "latest"
   557      }
   558  
   559      storage_os_disk {
   560          name = "myosdisk1"
   561          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   562          caching = "ReadWrite"
   563          create_option = "FromImage"
   564      }
   565  
   566      os_profile {
   567  	computer_name = "hostname%d"
   568  	admin_username = "testadmin"
   569  	admin_password = "Password1234!"
   570      }
   571  
   572      os_profile_linux_config {
   573  	disable_password_authentication = false
   574      }
   575  }
   576  `
   577  
   578  var testAccAzureRMVirtualMachine_basicWindowsMachine = `
   579  resource "azurerm_resource_group" "test" {
   580      name = "acctestrg-%d"
   581      location = "West US"
   582  }
   583  
   584  resource "azurerm_virtual_network" "test" {
   585      name = "acctvn-%d"
   586      address_space = ["10.0.0.0/16"]
   587      location = "West US"
   588      resource_group_name = "${azurerm_resource_group.test.name}"
   589  }
   590  
   591  resource "azurerm_subnet" "test" {
   592      name = "acctsub-%d"
   593      resource_group_name = "${azurerm_resource_group.test.name}"
   594      virtual_network_name = "${azurerm_virtual_network.test.name}"
   595      address_prefix = "10.0.2.0/24"
   596  }
   597  
   598  resource "azurerm_network_interface" "test" {
   599      name = "acctni-%d"
   600      location = "West US"
   601      resource_group_name = "${azurerm_resource_group.test.name}"
   602  
   603      ip_configuration {
   604      	name = "testconfiguration1"
   605      	subnet_id = "${azurerm_subnet.test.id}"
   606      	private_ip_address_allocation = "dynamic"
   607      }
   608  }
   609  
   610  resource "azurerm_storage_account" "test" {
   611      name = "accsa%d"
   612      resource_group_name = "${azurerm_resource_group.test.name}"
   613      location = "westus"
   614      account_type = "Standard_LRS"
   615  
   616      tags {
   617          environment = "staging"
   618      }
   619  }
   620  
   621  resource "azurerm_storage_container" "test" {
   622      name = "vhds"
   623      resource_group_name = "${azurerm_resource_group.test.name}"
   624      storage_account_name = "${azurerm_storage_account.test.name}"
   625      container_access_type = "private"
   626  }
   627  
   628  resource "azurerm_virtual_machine" "test" {
   629      name = "acctvm-%d"
   630      location = "West US"
   631      resource_group_name = "${azurerm_resource_group.test.name}"
   632      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   633      vm_size = "Standard_A0"
   634  
   635      storage_image_reference {
   636  	publisher = "MicrosoftWindowsServer"
   637  	offer = "WindowsServer"
   638  	sku = "2012-Datacenter"
   639  	version = "latest"
   640      }
   641  
   642      storage_os_disk {
   643          name = "myosdisk1"
   644          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   645          caching = "ReadWrite"
   646          create_option = "FromImage"
   647      }
   648  
   649      os_profile {
   650  	computer_name = "winhost01"
   651  	admin_username = "testadmin"
   652  	admin_password = "Password1234!"
   653      }
   654  
   655      os_profile_windows_config {
   656  	enable_automatic_upgrades = false
   657  	provision_vm_agent = true
   658      }
   659  }
   660  `
   661  
   662  var testAccAzureRMVirtualMachine_windowsUnattendedConfig = `
   663  resource "azurerm_resource_group" "test" {
   664      name = "acctestrg-%d"
   665      location = "West US"
   666  }
   667  
   668  resource "azurerm_virtual_network" "test" {
   669      name = "acctvn-%d"
   670      address_space = ["10.0.0.0/16"]
   671      location = "West US"
   672      resource_group_name = "${azurerm_resource_group.test.name}"
   673  }
   674  
   675  resource "azurerm_subnet" "test" {
   676      name = "acctsub-%d"
   677      resource_group_name = "${azurerm_resource_group.test.name}"
   678      virtual_network_name = "${azurerm_virtual_network.test.name}"
   679      address_prefix = "10.0.2.0/24"
   680  }
   681  
   682  resource "azurerm_network_interface" "test" {
   683      name = "acctni-%d"
   684      location = "West US"
   685      resource_group_name = "${azurerm_resource_group.test.name}"
   686  
   687      ip_configuration {
   688      	name = "testconfiguration1"
   689      	subnet_id = "${azurerm_subnet.test.id}"
   690      	private_ip_address_allocation = "dynamic"
   691      }
   692  }
   693  
   694  resource "azurerm_storage_account" "test" {
   695      name = "accsa%d"
   696      resource_group_name = "${azurerm_resource_group.test.name}"
   697      location = "westus"
   698      account_type = "Standard_LRS"
   699  
   700      tags {
   701          environment = "staging"
   702      }
   703  }
   704  
   705  resource "azurerm_storage_container" "test" {
   706      name = "vhds"
   707      resource_group_name = "${azurerm_resource_group.test.name}"
   708      storage_account_name = "${azurerm_storage_account.test.name}"
   709      container_access_type = "private"
   710  }
   711  
   712  resource "azurerm_virtual_machine" "test" {
   713      name = "acctvm-%d"
   714      location = "West US"
   715      resource_group_name = "${azurerm_resource_group.test.name}"
   716      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   717      vm_size = "Standard_A0"
   718  
   719      storage_image_reference {
   720  	publisher = "MicrosoftWindowsServer"
   721  	offer = "WindowsServer"
   722  	sku = "2012-Datacenter"
   723  	version = "latest"
   724      }
   725  
   726      storage_os_disk {
   727          name = "myosdisk1"
   728          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   729          caching = "ReadWrite"
   730          create_option = "FromImage"
   731      }
   732  
   733      os_profile {
   734  	computer_name = "winhost01"
   735  	admin_username = "testadmin"
   736  	admin_password = "Password1234!"
   737      }
   738  
   739      os_profile_windows_config {
   740          provision_vm_agent = true
   741          additional_unattend_config {
   742              pass = "oobeSystem"
   743              component = "Microsoft-Windows-Shell-Setup"
   744              setting_name = "FirstLogonCommands"
   745              content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
   746          }
   747      }
   748  }
   749  `
   750  
   751  var testAccAzureRMVirtualMachine_winRMConfig = `
   752  resource "azurerm_resource_group" "test" {
   753      name = "acctestrg-%d"
   754      location = "West US"
   755  }
   756  
   757  resource "azurerm_virtual_network" "test" {
   758      name = "acctvn-%d"
   759      address_space = ["10.0.0.0/16"]
   760      location = "West US"
   761      resource_group_name = "${azurerm_resource_group.test.name}"
   762  }
   763  
   764  resource "azurerm_subnet" "test" {
   765      name = "acctsub-%d"
   766      resource_group_name = "${azurerm_resource_group.test.name}"
   767      virtual_network_name = "${azurerm_virtual_network.test.name}"
   768      address_prefix = "10.0.2.0/24"
   769  }
   770  
   771  resource "azurerm_network_interface" "test" {
   772      name = "acctni-%d"
   773      location = "West US"
   774      resource_group_name = "${azurerm_resource_group.test.name}"
   775  
   776      ip_configuration {
   777      	name = "testconfiguration1"
   778      	subnet_id = "${azurerm_subnet.test.id}"
   779      	private_ip_address_allocation = "dynamic"
   780      }
   781  }
   782  
   783  resource "azurerm_storage_account" "test" {
   784      name = "accsa%d"
   785      resource_group_name = "${azurerm_resource_group.test.name}"
   786      location = "westus"
   787      account_type = "Standard_LRS"
   788  
   789      tags {
   790          environment = "staging"
   791      }
   792  }
   793  
   794  resource "azurerm_storage_container" "test" {
   795      name = "vhds"
   796      resource_group_name = "${azurerm_resource_group.test.name}"
   797      storage_account_name = "${azurerm_storage_account.test.name}"
   798      container_access_type = "private"
   799  }
   800  
   801  resource "azurerm_virtual_machine" "test" {
   802      name = "acctvm-%d"
   803      location = "West US"
   804      resource_group_name = "${azurerm_resource_group.test.name}"
   805      network_interface_ids = ["${azurerm_network_interface.test.id}"]
   806      vm_size = "Standard_A0"
   807  
   808      storage_image_reference {
   809  	publisher = "MicrosoftWindowsServer"
   810  	offer = "WindowsServer"
   811  	sku = "2012-Datacenter"
   812  	version = "latest"
   813      }
   814  
   815      storage_os_disk {
   816          name = "myosdisk1"
   817          vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
   818          caching = "ReadWrite"
   819          create_option = "FromImage"
   820      }
   821  
   822      os_profile {
   823  	computer_name = "winhost01"
   824  	admin_username = "testadmin"
   825  	admin_password = "Password1234!"
   826      }
   827  
   828      os_profile_windows_config {
   829          winrm {
   830  	  protocol = "http"
   831          }
   832      }
   833  }
   834  `