github.com/inge4pres/terraform@v0.7.5-0.20160930053151-bd083f84f376/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/Azure/azure-sdk-for-go/arm/compute" 9 "github.com/hashicorp/terraform/helper/acctest" 10 "github.com/hashicorp/terraform/helper/resource" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { 15 var vm compute.VirtualMachine 16 ri := acctest.RandInt() 17 config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 18 resource.Test(t, resource.TestCase{ 19 PreCheck: func() { testAccPreCheck(t) }, 20 Providers: testAccProviders, 21 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 22 Steps: []resource.TestStep{ 23 { 24 Config: config, 25 Check: resource.ComposeTestCheckFunc( 26 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 27 ), 28 }, 29 }, 30 }) 31 } 32 33 func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) { 34 var vm compute.VirtualMachine 35 36 ri := acctest.RandInt() 37 config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri) 38 resource.Test(t, resource.TestCase{ 39 PreCheck: func() { testAccPreCheck(t) }, 40 Providers: testAccProviders, 41 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 42 Steps: []resource.TestStep{ 43 { 44 Config: config, 45 Check: resource.ComposeTestCheckFunc( 46 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 47 ), 48 }, 49 }, 50 }) 51 } 52 53 func TestAccAzureRMVirtualMachine_tags(t *testing.T) { 54 var vm compute.VirtualMachine 55 56 ri := acctest.RandInt() 57 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 58 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineUpdated, ri, ri, ri, ri, ri, ri, ri) 59 resource.Test(t, resource.TestCase{ 60 PreCheck: func() { testAccPreCheck(t) }, 61 Providers: testAccProviders, 62 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 63 Steps: []resource.TestStep{ 64 { 65 Config: preConfig, 66 Check: resource.ComposeTestCheckFunc( 67 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 68 resource.TestCheckResourceAttr( 69 "azurerm_virtual_machine.test", "tags.%", "2"), 70 resource.TestCheckResourceAttr( 71 "azurerm_virtual_machine.test", "tags.environment", "Production"), 72 resource.TestCheckResourceAttr( 73 "azurerm_virtual_machine.test", "tags.cost-center", "Ops"), 74 ), 75 }, 76 77 { 78 Config: postConfig, 79 Check: resource.ComposeTestCheckFunc( 80 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 81 resource.TestCheckResourceAttr( 82 "azurerm_virtual_machine.test", "tags.%", "1"), 83 resource.TestCheckResourceAttr( 84 "azurerm_virtual_machine.test", "tags.environment", "Production"), 85 ), 86 }, 87 }, 88 }) 89 } 90 91 //This is a regression test around https://github.com/hashicorp/terraform/issues/6517 92 //Because we use CreateOrUpdate, we were sending an empty password on update requests 93 func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { 94 var vm compute.VirtualMachine 95 96 ri := acctest.RandInt() 97 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 98 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 99 resource.Test(t, resource.TestCase{ 100 PreCheck: func() { testAccPreCheck(t) }, 101 Providers: testAccProviders, 102 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 103 Steps: []resource.TestStep{ 104 { 105 Config: preConfig, 106 Check: resource.ComposeTestCheckFunc( 107 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 108 resource.TestCheckResourceAttr( 109 "azurerm_virtual_machine.test", "vm_size", "Standard_A0"), 110 ), 111 }, 112 { 113 Config: postConfig, 114 Check: resource.ComposeTestCheckFunc( 115 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 116 resource.TestCheckResourceAttr( 117 "azurerm_virtual_machine.test", "vm_size", "Standard_A1"), 118 ), 119 }, 120 }, 121 }) 122 } 123 124 func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { 125 var vm compute.VirtualMachine 126 ri := acctest.RandInt() 127 config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicWindowsMachine, ri, ri, ri, ri, ri, ri) 128 resource.Test(t, resource.TestCase{ 129 PreCheck: func() { testAccPreCheck(t) }, 130 Providers: testAccProviders, 131 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 132 Steps: []resource.TestStep{ 133 { 134 Config: config, 135 Check: resource.ComposeTestCheckFunc( 136 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 137 ), 138 }, 139 }, 140 }) 141 } 142 143 func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) { 144 var vm compute.VirtualMachine 145 ri := acctest.RandInt() 146 config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsUnattendedConfig, ri, ri, ri, ri, ri, ri) 147 resource.Test(t, resource.TestCase{ 148 PreCheck: func() { testAccPreCheck(t) }, 149 Providers: testAccProviders, 150 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 151 Steps: []resource.TestStep{ 152 { 153 Config: config, 154 Check: resource.ComposeTestCheckFunc( 155 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 156 ), 157 }, 158 }, 159 }) 160 } 161 162 func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) { 163 var vm compute.VirtualMachine 164 ri := acctest.RandInt() 165 config := fmt.Sprintf(testAccAzureRMVirtualMachine_diagnosticsProfile, ri, ri, ri, ri, ri, ri) 166 resource.Test(t, resource.TestCase{ 167 PreCheck: func() { testAccPreCheck(t) }, 168 Providers: testAccProviders, 169 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 170 Steps: []resource.TestStep{ 171 { 172 Config: config, 173 Check: resource.ComposeTestCheckFunc( 174 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 175 ), 176 }, 177 }, 178 }) 179 } 180 181 func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) { 182 var vm compute.VirtualMachine 183 ri := acctest.RandInt() 184 config := fmt.Sprintf(testAccAzureRMVirtualMachine_winRMConfig, ri, ri, ri, ri, ri, ri) 185 resource.Test(t, resource.TestCase{ 186 PreCheck: func() { testAccPreCheck(t) }, 187 Providers: testAccProviders, 188 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 189 Steps: []resource.TestStep{ 190 { 191 Config: config, 192 Check: resource.ComposeTestCheckFunc( 193 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 194 ), 195 }, 196 }, 197 }) 198 } 199 200 func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) { 201 var vm compute.VirtualMachine 202 ri := acctest.RandInt() 203 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri) 204 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM, ri, ri, ri, ri, ri) 205 resource.Test(t, resource.TestCase{ 206 PreCheck: func() { testAccPreCheck(t) }, 207 Providers: testAccProviders, 208 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 209 Steps: []resource.TestStep{ 210 { 211 Config: preConfig, 212 Check: resource.ComposeTestCheckFunc( 213 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 214 ), 215 }, 216 { 217 Config: postConfig, 218 Check: resource.ComposeTestCheckFunc( 219 testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", true), 220 testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", true), 221 ), 222 }, 223 }, 224 }) 225 } 226 227 func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) { 228 var vm compute.VirtualMachine 229 ri := acctest.RandInt() 230 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisks, ri, ri, ri, ri, ri, ri, ri) 231 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM, ri, ri, ri, ri, ri) 232 resource.Test(t, resource.TestCase{ 233 PreCheck: func() { testAccPreCheck(t) }, 234 Providers: testAccProviders, 235 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 236 Steps: []resource.TestStep{ 237 { 238 Config: preConfig, 239 Check: resource.ComposeTestCheckFunc( 240 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 241 ), 242 }, 243 { 244 Config: postConfig, 245 Check: resource.ComposeTestCheckFunc( 246 testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", false), 247 testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", false), 248 ), 249 }, 250 }, 251 }) 252 } 253 254 func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) { 255 var afterCreate, afterUpdate compute.VirtualMachine 256 257 ri := acctest.RandInt() 258 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_machineNameBeforeUpdate, ri, ri, ri, ri, ri, ri, ri) 259 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateMachineName, ri, ri, ri, ri, ri, ri, ri) 260 resource.Test(t, resource.TestCase{ 261 PreCheck: func() { testAccPreCheck(t) }, 262 Providers: testAccProviders, 263 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 264 Steps: []resource.TestStep{ 265 resource.TestStep{ 266 Config: preConfig, 267 Check: resource.ComposeTestCheckFunc( 268 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 269 ), 270 }, 271 272 resource.TestStep{ 273 Config: postConfig, 274 Check: resource.ComposeTestCheckFunc( 275 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 276 testAccCheckVirtualMachineRecreated( 277 t, &afterCreate, &afterUpdate), 278 ), 279 }, 280 }, 281 }) 282 } 283 284 func TestAccAzureRMVirtualMachine_ChangeAvailbilitySet(t *testing.T) { 285 var afterCreate, afterUpdate compute.VirtualMachine 286 287 ri := acctest.RandInt() 288 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri) 289 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri) 290 resource.Test(t, resource.TestCase{ 291 PreCheck: func() { testAccPreCheck(t) }, 292 Providers: testAccProviders, 293 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 294 Steps: []resource.TestStep{ 295 resource.TestStep{ 296 Config: preConfig, 297 Check: resource.ComposeTestCheckFunc( 298 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 299 ), 300 }, 301 302 resource.TestStep{ 303 Config: postConfig, 304 Check: resource.ComposeTestCheckFunc( 305 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 306 testAccCheckVirtualMachineRecreated( 307 t, &afterCreate, &afterUpdate), 308 ), 309 }, 310 }, 311 }) 312 } 313 314 func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) resource.TestCheckFunc { 315 return func(s *terraform.State) error { 316 // Ensure we have enough information in state to look up in API 317 rs, ok := s.RootModule().Resources[name] 318 if !ok { 319 return fmt.Errorf("Not found: %s", name) 320 } 321 322 vmName := rs.Primary.Attributes["name"] 323 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 324 if !hasResourceGroup { 325 return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName) 326 } 327 328 conn := testAccProvider.Meta().(*ArmClient).vmClient 329 330 resp, err := conn.Get(resourceGroup, vmName, "") 331 if err != nil { 332 return fmt.Errorf("Bad: Get on vmClient: %s", err) 333 } 334 335 if resp.StatusCode == http.StatusNotFound { 336 return fmt.Errorf("Bad: VirtualMachine %q (resource group: %q) does not exist", vmName, resourceGroup) 337 } 338 339 *vm = resp 340 341 return nil 342 } 343 } 344 345 func testAccCheckVirtualMachineRecreated(t *testing.T, 346 before, after *compute.VirtualMachine) resource.TestCheckFunc { 347 return func(s *terraform.State) error { 348 if before.ID == after.ID { 349 t.Fatalf("Expected change of Virtual Machine IDs, but both were %v", before.ID) 350 } 351 return nil 352 } 353 } 354 355 func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error { 356 conn := testAccProvider.Meta().(*ArmClient).vmClient 357 358 for _, rs := range s.RootModule().Resources { 359 if rs.Type != "azurerm_virtual_machine" { 360 continue 361 } 362 363 name := rs.Primary.Attributes["name"] 364 resourceGroup := rs.Primary.Attributes["resource_group_name"] 365 366 resp, err := conn.Get(resourceGroup, name, "") 367 368 if err != nil { 369 return nil 370 } 371 372 if resp.StatusCode != http.StatusNotFound { 373 return fmt.Errorf("Virtual Machine still exists:\n%#v", resp.Properties) 374 } 375 } 376 377 return nil 378 } 379 380 func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) resource.TestCheckFunc { 381 return func(s *terraform.State) error { 382 for _, rs := range s.RootModule().Resources { 383 if rs.Type != "azurerm_storage_container" { 384 continue 385 } 386 387 // fetch storage account and container name 388 resourceGroup := rs.Primary.Attributes["resource_group_name"] 389 storageAccountName := rs.Primary.Attributes["storage_account_name"] 390 containerName := rs.Primary.Attributes["name"] 391 storageClient, _, err := testAccProvider.Meta().(*ArmClient).getBlobStorageClientForStorageAccount(resourceGroup, storageAccountName) 392 if err != nil { 393 return fmt.Errorf("Error creating Blob storage client: %s", err) 394 } 395 396 exists, err := storageClient.BlobExists(containerName, name) 397 if err != nil { 398 return fmt.Errorf("Error checking if Disk VHD Blob exists: %s", err) 399 } 400 401 if exists && !shouldExist { 402 return fmt.Errorf("Disk VHD Blob still exists") 403 } else if !exists && shouldExist { 404 return fmt.Errorf("Disk VHD Blob should exist") 405 } 406 } 407 408 return nil 409 } 410 } 411 412 var testAccAzureRMVirtualMachine_basicLinuxMachine = ` 413 resource "azurerm_resource_group" "test" { 414 name = "acctestrg-%d" 415 location = "West US" 416 } 417 418 resource "azurerm_virtual_network" "test" { 419 name = "acctvn-%d" 420 address_space = ["10.0.0.0/16"] 421 location = "West US" 422 resource_group_name = "${azurerm_resource_group.test.name}" 423 } 424 425 resource "azurerm_subnet" "test" { 426 name = "acctsub-%d" 427 resource_group_name = "${azurerm_resource_group.test.name}" 428 virtual_network_name = "${azurerm_virtual_network.test.name}" 429 address_prefix = "10.0.2.0/24" 430 } 431 432 resource "azurerm_network_interface" "test" { 433 name = "acctni-%d" 434 location = "West US" 435 resource_group_name = "${azurerm_resource_group.test.name}" 436 437 ip_configuration { 438 name = "testconfiguration1" 439 subnet_id = "${azurerm_subnet.test.id}" 440 private_ip_address_allocation = "dynamic" 441 } 442 } 443 444 resource "azurerm_storage_account" "test" { 445 name = "accsa%d" 446 resource_group_name = "${azurerm_resource_group.test.name}" 447 location = "westus" 448 account_type = "Standard_LRS" 449 450 tags { 451 environment = "staging" 452 } 453 } 454 455 resource "azurerm_storage_container" "test" { 456 name = "vhds" 457 resource_group_name = "${azurerm_resource_group.test.name}" 458 storage_account_name = "${azurerm_storage_account.test.name}" 459 container_access_type = "private" 460 } 461 462 resource "azurerm_virtual_machine" "test" { 463 name = "acctvm-%d" 464 location = "West US" 465 resource_group_name = "${azurerm_resource_group.test.name}" 466 network_interface_ids = ["${azurerm_network_interface.test.id}"] 467 vm_size = "Standard_A0" 468 469 storage_image_reference { 470 publisher = "Canonical" 471 offer = "UbuntuServer" 472 sku = "14.04.2-LTS" 473 version = "latest" 474 } 475 476 storage_os_disk { 477 name = "myosdisk1" 478 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 479 caching = "ReadWrite" 480 create_option = "FromImage" 481 } 482 483 os_profile { 484 computer_name = "hostname%d" 485 admin_username = "testadmin" 486 admin_password = "Password1234!" 487 } 488 489 os_profile_linux_config { 490 disable_password_authentication = false 491 } 492 493 tags { 494 environment = "Production" 495 cost-center = "Ops" 496 } 497 } 498 ` 499 500 var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = ` 501 resource "azurerm_resource_group" "test" { 502 name = "acctestrg-%d" 503 location = "West US" 504 } 505 506 resource "azurerm_virtual_network" "test" { 507 name = "acctvn-%d" 508 address_space = ["10.0.0.0/16"] 509 location = "West US" 510 resource_group_name = "${azurerm_resource_group.test.name}" 511 } 512 513 resource "azurerm_subnet" "test" { 514 name = "acctsub-%d" 515 resource_group_name = "${azurerm_resource_group.test.name}" 516 virtual_network_name = "${azurerm_virtual_network.test.name}" 517 address_prefix = "10.0.2.0/24" 518 } 519 520 resource "azurerm_network_interface" "test" { 521 name = "acctni-%d" 522 location = "West US" 523 resource_group_name = "${azurerm_resource_group.test.name}" 524 525 ip_configuration { 526 name = "testconfiguration1" 527 subnet_id = "${azurerm_subnet.test.id}" 528 private_ip_address_allocation = "dynamic" 529 } 530 } 531 532 resource "azurerm_storage_account" "test" { 533 name = "accsa%d" 534 resource_group_name = "${azurerm_resource_group.test.name}" 535 location = "westus" 536 account_type = "Standard_LRS" 537 538 tags { 539 environment = "staging" 540 } 541 } 542 543 resource "azurerm_storage_container" "test" { 544 name = "vhds" 545 resource_group_name = "${azurerm_resource_group.test.name}" 546 storage_account_name = "${azurerm_storage_account.test.name}" 547 container_access_type = "private" 548 } 549 550 resource "azurerm_virtual_machine" "test" { 551 name = "acctvm-%d" 552 location = "West US" 553 resource_group_name = "${azurerm_resource_group.test.name}" 554 network_interface_ids = ["${azurerm_network_interface.test.id}"] 555 vm_size = "Standard_A0" 556 delete_os_disk_on_termination = true 557 558 storage_image_reference { 559 publisher = "Canonical" 560 offer = "UbuntuServer" 561 sku = "14.04.2-LTS" 562 version = "latest" 563 } 564 565 storage_os_disk { 566 name = "myosdisk1" 567 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 568 caching = "ReadWrite" 569 create_option = "FromImage" 570 } 571 572 os_profile { 573 computer_name = "hostname%d" 574 admin_username = "testadmin" 575 admin_password = "Password1234!" 576 } 577 578 os_profile_linux_config { 579 disable_password_authentication = false 580 } 581 582 tags { 583 environment = "Production" 584 cost-center = "Ops" 585 } 586 } 587 ` 588 589 var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisks = ` 590 resource "azurerm_resource_group" "test" { 591 name = "acctestrg-%d" 592 location = "West US" 593 } 594 595 resource "azurerm_virtual_network" "test" { 596 name = "acctvn-%d" 597 address_space = ["10.0.0.0/16"] 598 location = "West US" 599 resource_group_name = "${azurerm_resource_group.test.name}" 600 } 601 602 resource "azurerm_subnet" "test" { 603 name = "acctsub-%d" 604 resource_group_name = "${azurerm_resource_group.test.name}" 605 virtual_network_name = "${azurerm_virtual_network.test.name}" 606 address_prefix = "10.0.2.0/24" 607 } 608 609 resource "azurerm_network_interface" "test" { 610 name = "acctni-%d" 611 location = "West US" 612 resource_group_name = "${azurerm_resource_group.test.name}" 613 614 ip_configuration { 615 name = "testconfiguration1" 616 subnet_id = "${azurerm_subnet.test.id}" 617 private_ip_address_allocation = "dynamic" 618 } 619 } 620 621 resource "azurerm_storage_account" "test" { 622 name = "accsa%d" 623 resource_group_name = "${azurerm_resource_group.test.name}" 624 location = "westus" 625 account_type = "Standard_LRS" 626 627 tags { 628 environment = "staging" 629 } 630 } 631 632 resource "azurerm_storage_container" "test" { 633 name = "vhds" 634 resource_group_name = "${azurerm_resource_group.test.name}" 635 storage_account_name = "${azurerm_storage_account.test.name}" 636 container_access_type = "private" 637 } 638 639 resource "azurerm_virtual_machine" "test" { 640 name = "acctvm-%d" 641 location = "West US" 642 resource_group_name = "${azurerm_resource_group.test.name}" 643 network_interface_ids = ["${azurerm_network_interface.test.id}"] 644 vm_size = "Standard_A0" 645 646 storage_image_reference { 647 publisher = "Canonical" 648 offer = "UbuntuServer" 649 sku = "14.04.2-LTS" 650 version = "latest" 651 } 652 653 storage_os_disk { 654 name = "myosdisk1" 655 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 656 caching = "ReadWrite" 657 create_option = "FromImage" 658 } 659 660 delete_os_disk_on_termination = true 661 662 storage_data_disk { 663 name = "mydatadisk1" 664 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd" 665 disk_size_gb = "1023" 666 create_option = "Empty" 667 lun = 0 668 } 669 670 delete_data_disks_on_termination = true 671 672 os_profile { 673 computer_name = "hostname%d" 674 admin_username = "testadmin" 675 admin_password = "Password1234!" 676 } 677 678 os_profile_linux_config { 679 disable_password_authentication = false 680 } 681 682 tags { 683 environment = "Production" 684 cost-center = "Ops" 685 } 686 } 687 ` 688 689 var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = ` 690 resource "azurerm_resource_group" "test" { 691 name = "acctestrg-%d" 692 location = "West US" 693 } 694 695 resource "azurerm_virtual_network" "test" { 696 name = "acctvn-%d" 697 address_space = ["10.0.0.0/16"] 698 location = "West US" 699 resource_group_name = "${azurerm_resource_group.test.name}" 700 } 701 702 resource "azurerm_subnet" "test" { 703 name = "acctsub-%d" 704 resource_group_name = "${azurerm_resource_group.test.name}" 705 virtual_network_name = "${azurerm_virtual_network.test.name}" 706 address_prefix = "10.0.2.0/24" 707 } 708 709 resource "azurerm_network_interface" "test" { 710 name = "acctni-%d" 711 location = "West US" 712 resource_group_name = "${azurerm_resource_group.test.name}" 713 714 ip_configuration { 715 name = "testconfiguration1" 716 subnet_id = "${azurerm_subnet.test.id}" 717 private_ip_address_allocation = "dynamic" 718 } 719 } 720 721 resource "azurerm_storage_account" "test" { 722 name = "accsa%d" 723 resource_group_name = "${azurerm_resource_group.test.name}" 724 location = "westus" 725 account_type = "Standard_LRS" 726 727 tags { 728 environment = "staging" 729 } 730 } 731 732 resource "azurerm_storage_container" "test" { 733 name = "vhds" 734 resource_group_name = "${azurerm_resource_group.test.name}" 735 storage_account_name = "${azurerm_storage_account.test.name}" 736 container_access_type = "private" 737 } 738 ` 739 740 var testAccAzureRMVirtualMachine_withDataDisk = ` 741 resource "azurerm_resource_group" "test" { 742 name = "acctestrg-%d" 743 location = "West US" 744 } 745 746 resource "azurerm_virtual_network" "test" { 747 name = "acctvn-%d" 748 address_space = ["10.0.0.0/16"] 749 location = "West US" 750 resource_group_name = "${azurerm_resource_group.test.name}" 751 } 752 753 resource "azurerm_subnet" "test" { 754 name = "acctsub-%d" 755 resource_group_name = "${azurerm_resource_group.test.name}" 756 virtual_network_name = "${azurerm_virtual_network.test.name}" 757 address_prefix = "10.0.2.0/24" 758 } 759 760 resource "azurerm_network_interface" "test" { 761 name = "acctni-%d" 762 location = "West US" 763 resource_group_name = "${azurerm_resource_group.test.name}" 764 765 ip_configuration { 766 name = "testconfiguration1" 767 subnet_id = "${azurerm_subnet.test.id}" 768 private_ip_address_allocation = "dynamic" 769 } 770 } 771 772 resource "azurerm_storage_account" "test" { 773 name = "accsa%d" 774 resource_group_name = "${azurerm_resource_group.test.name}" 775 location = "westus" 776 account_type = "Standard_LRS" 777 778 tags { 779 environment = "staging" 780 } 781 } 782 783 resource "azurerm_storage_container" "test" { 784 name = "vhds" 785 resource_group_name = "${azurerm_resource_group.test.name}" 786 storage_account_name = "${azurerm_storage_account.test.name}" 787 container_access_type = "private" 788 } 789 790 resource "azurerm_virtual_machine" "test" { 791 name = "acctvm-%d" 792 location = "West US" 793 resource_group_name = "${azurerm_resource_group.test.name}" 794 network_interface_ids = ["${azurerm_network_interface.test.id}"] 795 vm_size = "Standard_A0" 796 797 storage_image_reference { 798 publisher = "Canonical" 799 offer = "UbuntuServer" 800 sku = "14.04.2-LTS" 801 version = "latest" 802 } 803 804 storage_os_disk { 805 name = "myosdisk1" 806 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 807 caching = "ReadWrite" 808 create_option = "FromImage" 809 } 810 811 storage_data_disk { 812 name = "mydatadisk1" 813 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd" 814 disk_size_gb = "1023" 815 create_option = "Empty" 816 lun = 0 817 } 818 819 os_profile { 820 computer_name = "hostname%d" 821 admin_username = "testadmin" 822 admin_password = "Password1234!" 823 } 824 825 os_profile_linux_config { 826 disable_password_authentication = false 827 } 828 829 tags { 830 environment = "Production" 831 cost-center = "Ops" 832 } 833 } 834 ` 835 836 var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = ` 837 resource "azurerm_resource_group" "test" { 838 name = "acctestrg-%d" 839 location = "West US" 840 } 841 842 resource "azurerm_virtual_network" "test" { 843 name = "acctvn-%d" 844 address_space = ["10.0.0.0/16"] 845 location = "West US" 846 resource_group_name = "${azurerm_resource_group.test.name}" 847 } 848 849 resource "azurerm_subnet" "test" { 850 name = "acctsub-%d" 851 resource_group_name = "${azurerm_resource_group.test.name}" 852 virtual_network_name = "${azurerm_virtual_network.test.name}" 853 address_prefix = "10.0.2.0/24" 854 } 855 856 resource "azurerm_network_interface" "test" { 857 name = "acctni-%d" 858 location = "West US" 859 resource_group_name = "${azurerm_resource_group.test.name}" 860 861 ip_configuration { 862 name = "testconfiguration1" 863 subnet_id = "${azurerm_subnet.test.id}" 864 private_ip_address_allocation = "dynamic" 865 } 866 } 867 868 resource "azurerm_storage_account" "test" { 869 name = "accsa%d" 870 resource_group_name = "${azurerm_resource_group.test.name}" 871 location = "westus" 872 account_type = "Standard_LRS" 873 874 tags { 875 environment = "staging" 876 } 877 } 878 879 resource "azurerm_storage_container" "test" { 880 name = "vhds" 881 resource_group_name = "${azurerm_resource_group.test.name}" 882 storage_account_name = "${azurerm_storage_account.test.name}" 883 container_access_type = "private" 884 } 885 886 resource "azurerm_virtual_machine" "test" { 887 name = "acctvm-%d" 888 location = "West US" 889 resource_group_name = "${azurerm_resource_group.test.name}" 890 network_interface_ids = ["${azurerm_network_interface.test.id}"] 891 vm_size = "Standard_A0" 892 893 storage_image_reference { 894 publisher = "Canonical" 895 offer = "UbuntuServer" 896 sku = "14.04.2-LTS" 897 version = "latest" 898 } 899 900 storage_os_disk { 901 name = "myosdisk1" 902 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 903 caching = "ReadWrite" 904 create_option = "FromImage" 905 } 906 907 os_profile { 908 computer_name = "hostname%d" 909 admin_username = "testadmin" 910 admin_password = "Password1234!" 911 } 912 913 os_profile_linux_config { 914 disable_password_authentication = false 915 } 916 917 tags { 918 environment = "Production" 919 } 920 } 921 ` 922 923 var testAccAzureRMVirtualMachine_updatedLinuxMachine = ` 924 resource "azurerm_resource_group" "test" { 925 name = "acctestrg-%d" 926 location = "West US" 927 } 928 929 resource "azurerm_virtual_network" "test" { 930 name = "acctvn-%d" 931 address_space = ["10.0.0.0/16"] 932 location = "West US" 933 resource_group_name = "${azurerm_resource_group.test.name}" 934 } 935 936 resource "azurerm_subnet" "test" { 937 name = "acctsub-%d" 938 resource_group_name = "${azurerm_resource_group.test.name}" 939 virtual_network_name = "${azurerm_virtual_network.test.name}" 940 address_prefix = "10.0.2.0/24" 941 } 942 943 resource "azurerm_network_interface" "test" { 944 name = "acctni-%d" 945 location = "West US" 946 resource_group_name = "${azurerm_resource_group.test.name}" 947 948 ip_configuration { 949 name = "testconfiguration1" 950 subnet_id = "${azurerm_subnet.test.id}" 951 private_ip_address_allocation = "dynamic" 952 } 953 } 954 955 resource "azurerm_storage_account" "test" { 956 name = "accsa%d" 957 resource_group_name = "${azurerm_resource_group.test.name}" 958 location = "westus" 959 account_type = "Standard_LRS" 960 961 tags { 962 environment = "staging" 963 } 964 } 965 966 resource "azurerm_storage_container" "test" { 967 name = "vhds" 968 resource_group_name = "${azurerm_resource_group.test.name}" 969 storage_account_name = "${azurerm_storage_account.test.name}" 970 container_access_type = "private" 971 } 972 973 resource "azurerm_virtual_machine" "test" { 974 name = "acctvm-%d" 975 location = "West US" 976 resource_group_name = "${azurerm_resource_group.test.name}" 977 network_interface_ids = ["${azurerm_network_interface.test.id}"] 978 vm_size = "Standard_A1" 979 980 storage_image_reference { 981 publisher = "Canonical" 982 offer = "UbuntuServer" 983 sku = "14.04.2-LTS" 984 version = "latest" 985 } 986 987 storage_os_disk { 988 name = "myosdisk1" 989 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 990 caching = "ReadWrite" 991 create_option = "FromImage" 992 } 993 994 os_profile { 995 computer_name = "hostname%d" 996 admin_username = "testadmin" 997 admin_password = "Password1234!" 998 } 999 1000 os_profile_linux_config { 1001 disable_password_authentication = false 1002 } 1003 } 1004 ` 1005 1006 var testAccAzureRMVirtualMachine_basicWindowsMachine = ` 1007 resource "azurerm_resource_group" "test" { 1008 name = "acctestrg-%d" 1009 location = "West US" 1010 } 1011 1012 resource "azurerm_virtual_network" "test" { 1013 name = "acctvn-%d" 1014 address_space = ["10.0.0.0/16"] 1015 location = "West US" 1016 resource_group_name = "${azurerm_resource_group.test.name}" 1017 } 1018 1019 resource "azurerm_subnet" "test" { 1020 name = "acctsub-%d" 1021 resource_group_name = "${azurerm_resource_group.test.name}" 1022 virtual_network_name = "${azurerm_virtual_network.test.name}" 1023 address_prefix = "10.0.2.0/24" 1024 } 1025 1026 resource "azurerm_network_interface" "test" { 1027 name = "acctni-%d" 1028 location = "West US" 1029 resource_group_name = "${azurerm_resource_group.test.name}" 1030 1031 ip_configuration { 1032 name = "testconfiguration1" 1033 subnet_id = "${azurerm_subnet.test.id}" 1034 private_ip_address_allocation = "dynamic" 1035 } 1036 } 1037 1038 resource "azurerm_storage_account" "test" { 1039 name = "accsa%d" 1040 resource_group_name = "${azurerm_resource_group.test.name}" 1041 location = "westus" 1042 account_type = "Standard_LRS" 1043 1044 tags { 1045 environment = "staging" 1046 } 1047 } 1048 1049 resource "azurerm_storage_container" "test" { 1050 name = "vhds" 1051 resource_group_name = "${azurerm_resource_group.test.name}" 1052 storage_account_name = "${azurerm_storage_account.test.name}" 1053 container_access_type = "private" 1054 } 1055 1056 resource "azurerm_virtual_machine" "test" { 1057 name = "acctvm-%d" 1058 location = "West US" 1059 resource_group_name = "${azurerm_resource_group.test.name}" 1060 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1061 vm_size = "Standard_A0" 1062 1063 storage_image_reference { 1064 publisher = "MicrosoftWindowsServer" 1065 offer = "WindowsServer" 1066 sku = "2012-Datacenter" 1067 version = "latest" 1068 } 1069 1070 storage_os_disk { 1071 name = "myosdisk1" 1072 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1073 caching = "ReadWrite" 1074 create_option = "FromImage" 1075 } 1076 1077 os_profile { 1078 computer_name = "winhost01" 1079 admin_username = "testadmin" 1080 admin_password = "Password1234!" 1081 } 1082 1083 os_profile_windows_config { 1084 enable_automatic_upgrades = false 1085 provision_vm_agent = true 1086 } 1087 } 1088 ` 1089 1090 var testAccAzureRMVirtualMachine_windowsUnattendedConfig = ` 1091 resource "azurerm_resource_group" "test" { 1092 name = "acctestrg-%d" 1093 location = "West US" 1094 } 1095 1096 resource "azurerm_virtual_network" "test" { 1097 name = "acctvn-%d" 1098 address_space = ["10.0.0.0/16"] 1099 location = "West US" 1100 resource_group_name = "${azurerm_resource_group.test.name}" 1101 } 1102 1103 resource "azurerm_subnet" "test" { 1104 name = "acctsub-%d" 1105 resource_group_name = "${azurerm_resource_group.test.name}" 1106 virtual_network_name = "${azurerm_virtual_network.test.name}" 1107 address_prefix = "10.0.2.0/24" 1108 } 1109 1110 resource "azurerm_network_interface" "test" { 1111 name = "acctni-%d" 1112 location = "West US" 1113 resource_group_name = "${azurerm_resource_group.test.name}" 1114 1115 ip_configuration { 1116 name = "testconfiguration1" 1117 subnet_id = "${azurerm_subnet.test.id}" 1118 private_ip_address_allocation = "dynamic" 1119 } 1120 } 1121 1122 resource "azurerm_storage_account" "test" { 1123 name = "accsa%d" 1124 resource_group_name = "${azurerm_resource_group.test.name}" 1125 location = "westus" 1126 account_type = "Standard_LRS" 1127 1128 tags { 1129 environment = "staging" 1130 } 1131 } 1132 1133 resource "azurerm_storage_container" "test" { 1134 name = "vhds" 1135 resource_group_name = "${azurerm_resource_group.test.name}" 1136 storage_account_name = "${azurerm_storage_account.test.name}" 1137 container_access_type = "private" 1138 } 1139 1140 resource "azurerm_virtual_machine" "test" { 1141 name = "acctvm-%d" 1142 location = "West US" 1143 resource_group_name = "${azurerm_resource_group.test.name}" 1144 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1145 vm_size = "Standard_A0" 1146 1147 storage_image_reference { 1148 publisher = "MicrosoftWindowsServer" 1149 offer = "WindowsServer" 1150 sku = "2012-Datacenter" 1151 version = "latest" 1152 } 1153 1154 storage_os_disk { 1155 name = "myosdisk1" 1156 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1157 caching = "ReadWrite" 1158 create_option = "FromImage" 1159 } 1160 1161 os_profile { 1162 computer_name = "winhost01" 1163 admin_username = "testadmin" 1164 admin_password = "Password1234!" 1165 } 1166 1167 os_profile_windows_config { 1168 provision_vm_agent = true 1169 additional_unattend_config { 1170 pass = "oobeSystem" 1171 component = "Microsoft-Windows-Shell-Setup" 1172 setting_name = "FirstLogonCommands" 1173 content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>" 1174 } 1175 } 1176 1177 } 1178 ` 1179 1180 var testAccAzureRMVirtualMachine_diagnosticsProfile = ` 1181 resource "azurerm_resource_group" "test" { 1182 name = "acctestrg-%d" 1183 location = "West US" 1184 } 1185 1186 resource "azurerm_virtual_network" "test" { 1187 name = "acctvn-%d" 1188 address_space = ["10.0.0.0/16"] 1189 location = "West US" 1190 resource_group_name = "${azurerm_resource_group.test.name}" 1191 } 1192 1193 resource "azurerm_subnet" "test" { 1194 name = "acctsub-%d" 1195 resource_group_name = "${azurerm_resource_group.test.name}" 1196 virtual_network_name = "${azurerm_virtual_network.test.name}" 1197 address_prefix = "10.0.2.0/24" 1198 } 1199 1200 resource "azurerm_network_interface" "test" { 1201 name = "acctni-%d" 1202 location = "West US" 1203 resource_group_name = "${azurerm_resource_group.test.name}" 1204 1205 ip_configuration { 1206 name = "testconfiguration1" 1207 subnet_id = "${azurerm_subnet.test.id}" 1208 private_ip_address_allocation = "dynamic" 1209 } 1210 } 1211 1212 resource "azurerm_storage_account" "test" { 1213 name = "accsa%d" 1214 resource_group_name = "${azurerm_resource_group.test.name}" 1215 location = "westus" 1216 account_type = "Standard_LRS" 1217 1218 tags { 1219 environment = "staging" 1220 } 1221 } 1222 1223 resource "azurerm_storage_container" "test" { 1224 name = "vhds" 1225 resource_group_name = "${azurerm_resource_group.test.name}" 1226 storage_account_name = "${azurerm_storage_account.test.name}" 1227 container_access_type = "private" 1228 } 1229 1230 resource "azurerm_virtual_machine" "test" { 1231 name = "acctvm-%d" 1232 location = "West US" 1233 resource_group_name = "${azurerm_resource_group.test.name}" 1234 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1235 vm_size = "Standard_A0" 1236 1237 storage_image_reference { 1238 publisher = "MicrosoftWindowsServer" 1239 offer = "WindowsServer" 1240 sku = "2012-Datacenter" 1241 version = "latest" 1242 } 1243 1244 storage_os_disk { 1245 name = "myosdisk1" 1246 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1247 caching = "ReadWrite" 1248 create_option = "FromImage" 1249 } 1250 1251 os_profile { 1252 computer_name = "winhost01" 1253 admin_username = "testadmin" 1254 admin_password = "Password1234!" 1255 } 1256 1257 os_profile_windows_config { 1258 winrm { 1259 protocol = "http" 1260 } 1261 } 1262 } 1263 1264 ` 1265 1266 var testAccAzureRMVirtualMachine_winRMConfig = ` 1267 resource "azurerm_resource_group" "test" { 1268 name = "acctestrg-%d" 1269 location = "West US" 1270 } 1271 1272 resource "azurerm_virtual_network" "test" { 1273 name = "acctvn-%d" 1274 address_space = ["10.0.0.0/16"] 1275 location = "West US" 1276 resource_group_name = "${azurerm_resource_group.test.name}" 1277 } 1278 1279 resource "azurerm_subnet" "test" { 1280 name = "acctsub-%d" 1281 resource_group_name = "${azurerm_resource_group.test.name}" 1282 virtual_network_name = "${azurerm_virtual_network.test.name}" 1283 address_prefix = "10.0.2.0/24" 1284 } 1285 1286 resource "azurerm_network_interface" "test" { 1287 name = "acctni-%d" 1288 location = "West US" 1289 resource_group_name = "${azurerm_resource_group.test.name}" 1290 1291 ip_configuration { 1292 name = "testconfiguration1" 1293 subnet_id = "${azurerm_subnet.test.id}" 1294 private_ip_address_allocation = "dynamic" 1295 } 1296 } 1297 1298 resource "azurerm_storage_account" "test" { 1299 name = "accsa%d" 1300 resource_group_name = "${azurerm_resource_group.test.name}" 1301 location = "westus" 1302 account_type = "Standard_LRS" 1303 1304 tags { 1305 environment = "staging" 1306 } 1307 } 1308 1309 resource "azurerm_storage_container" "test" { 1310 name = "vhds" 1311 resource_group_name = "${azurerm_resource_group.test.name}" 1312 storage_account_name = "${azurerm_storage_account.test.name}" 1313 container_access_type = "private" 1314 } 1315 1316 resource "azurerm_virtual_machine" "test" { 1317 name = "acctvm-%d" 1318 location = "West US" 1319 resource_group_name = "${azurerm_resource_group.test.name}" 1320 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1321 vm_size = "Standard_A0" 1322 1323 storage_image_reference { 1324 publisher = "MicrosoftWindowsServer" 1325 offer = "WindowsServer" 1326 sku = "2012-Datacenter" 1327 version = "latest" 1328 } 1329 1330 storage_os_disk { 1331 name = "myosdisk1" 1332 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1333 caching = "ReadWrite" 1334 create_option = "FromImage" 1335 } 1336 1337 os_profile { 1338 computer_name = "winhost01" 1339 admin_username = "testadmin" 1340 admin_password = "Password1234!" 1341 } 1342 1343 os_profile_windows_config { 1344 winrm { 1345 protocol = "http" 1346 } 1347 } 1348 } 1349 ` 1350 1351 var testAccAzureRMVirtualMachine_withAvailabilitySet = ` 1352 resource "azurerm_resource_group" "test" { 1353 name = "acctestrg-%d" 1354 location = "West US" 1355 } 1356 1357 resource "azurerm_virtual_network" "test" { 1358 name = "acctvn-%d" 1359 address_space = ["10.0.0.0/16"] 1360 location = "West US" 1361 resource_group_name = "${azurerm_resource_group.test.name}" 1362 } 1363 1364 resource "azurerm_subnet" "test" { 1365 name = "acctsub-%d" 1366 resource_group_name = "${azurerm_resource_group.test.name}" 1367 virtual_network_name = "${azurerm_virtual_network.test.name}" 1368 address_prefix = "10.0.2.0/24" 1369 } 1370 1371 resource "azurerm_network_interface" "test" { 1372 name = "acctni-%d" 1373 location = "West US" 1374 resource_group_name = "${azurerm_resource_group.test.name}" 1375 1376 ip_configuration { 1377 name = "testconfiguration1" 1378 subnet_id = "${azurerm_subnet.test.id}" 1379 private_ip_address_allocation = "dynamic" 1380 } 1381 } 1382 1383 resource "azurerm_storage_account" "test" { 1384 name = "accsa%d" 1385 resource_group_name = "${azurerm_resource_group.test.name}" 1386 location = "westus" 1387 account_type = "Standard_LRS" 1388 1389 tags { 1390 environment = "staging" 1391 } 1392 } 1393 1394 resource "azurerm_availability_set" "test" { 1395 name = "availabilityset%d" 1396 location = "West US" 1397 resource_group_name = "${azurerm_resource_group.test.name}" 1398 } 1399 1400 resource "azurerm_storage_container" "test" { 1401 name = "vhds" 1402 resource_group_name = "${azurerm_resource_group.test.name}" 1403 storage_account_name = "${azurerm_storage_account.test.name}" 1404 container_access_type = "private" 1405 } 1406 1407 resource "azurerm_virtual_machine" "test" { 1408 name = "acctvm-%d" 1409 location = "West US" 1410 resource_group_name = "${azurerm_resource_group.test.name}" 1411 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1412 vm_size = "Standard_A0" 1413 availability_set_id = "${azurerm_availability_set.test.id}" 1414 delete_os_disk_on_termination = true 1415 1416 storage_image_reference { 1417 publisher = "Canonical" 1418 offer = "UbuntuServer" 1419 sku = "14.04.2-LTS" 1420 version = "latest" 1421 } 1422 1423 storage_os_disk { 1424 name = "myosdisk1" 1425 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1426 caching = "ReadWrite" 1427 create_option = "FromImage" 1428 } 1429 1430 os_profile { 1431 computer_name = "hostname%d" 1432 admin_username = "testadmin" 1433 admin_password = "Password1234!" 1434 } 1435 1436 os_profile_linux_config { 1437 disable_password_authentication = false 1438 } 1439 } 1440 ` 1441 1442 var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` 1443 resource "azurerm_resource_group" "test" { 1444 name = "acctestrg-%d" 1445 location = "West US" 1446 } 1447 1448 resource "azurerm_virtual_network" "test" { 1449 name = "acctvn-%d" 1450 address_space = ["10.0.0.0/16"] 1451 location = "West US" 1452 resource_group_name = "${azurerm_resource_group.test.name}" 1453 } 1454 1455 resource "azurerm_subnet" "test" { 1456 name = "acctsub-%d" 1457 resource_group_name = "${azurerm_resource_group.test.name}" 1458 virtual_network_name = "${azurerm_virtual_network.test.name}" 1459 address_prefix = "10.0.2.0/24" 1460 } 1461 1462 resource "azurerm_network_interface" "test" { 1463 name = "acctni-%d" 1464 location = "West US" 1465 resource_group_name = "${azurerm_resource_group.test.name}" 1466 1467 ip_configuration { 1468 name = "testconfiguration1" 1469 subnet_id = "${azurerm_subnet.test.id}" 1470 private_ip_address_allocation = "dynamic" 1471 } 1472 } 1473 1474 resource "azurerm_storage_account" "test" { 1475 name = "accsa%d" 1476 resource_group_name = "${azurerm_resource_group.test.name}" 1477 location = "westus" 1478 account_type = "Standard_LRS" 1479 1480 tags { 1481 environment = "staging" 1482 } 1483 } 1484 1485 resource "azurerm_availability_set" "test" { 1486 name = "updatedAvailabilitySet%d" 1487 location = "West US" 1488 resource_group_name = "${azurerm_resource_group.test.name}" 1489 } 1490 1491 resource "azurerm_storage_container" "test" { 1492 name = "vhds" 1493 resource_group_name = "${azurerm_resource_group.test.name}" 1494 storage_account_name = "${azurerm_storage_account.test.name}" 1495 container_access_type = "private" 1496 } 1497 1498 resource "azurerm_virtual_machine" "test" { 1499 name = "acctvm-%d" 1500 location = "West US" 1501 resource_group_name = "${azurerm_resource_group.test.name}" 1502 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1503 vm_size = "Standard_A0" 1504 availability_set_id = "${azurerm_availability_set.test.id}" 1505 delete_os_disk_on_termination = true 1506 1507 storage_image_reference { 1508 publisher = "Canonical" 1509 offer = "UbuntuServer" 1510 sku = "14.04.2-LTS" 1511 version = "latest" 1512 } 1513 1514 storage_os_disk { 1515 name = "myosdisk1" 1516 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1517 caching = "ReadWrite" 1518 create_option = "FromImage" 1519 } 1520 1521 os_profile { 1522 computer_name = "hostname%d" 1523 admin_username = "testadmin" 1524 admin_password = "Password1234!" 1525 } 1526 1527 os_profile_linux_config { 1528 disable_password_authentication = false 1529 } 1530 } 1531 ` 1532 1533 var testAccAzureRMVirtualMachine_updateMachineName = ` 1534 resource "azurerm_resource_group" "test" { 1535 name = "acctestrg-%d" 1536 location = "West US" 1537 } 1538 1539 resource "azurerm_virtual_network" "test" { 1540 name = "acctvn-%d" 1541 address_space = ["10.0.0.0/16"] 1542 location = "West US" 1543 resource_group_name = "${azurerm_resource_group.test.name}" 1544 } 1545 1546 resource "azurerm_subnet" "test" { 1547 name = "acctsub-%d" 1548 resource_group_name = "${azurerm_resource_group.test.name}" 1549 virtual_network_name = "${azurerm_virtual_network.test.name}" 1550 address_prefix = "10.0.2.0/24" 1551 } 1552 1553 resource "azurerm_network_interface" "test" { 1554 name = "acctni-%d" 1555 location = "West US" 1556 resource_group_name = "${azurerm_resource_group.test.name}" 1557 1558 ip_configuration { 1559 name = "testconfiguration1" 1560 subnet_id = "${azurerm_subnet.test.id}" 1561 private_ip_address_allocation = "dynamic" 1562 } 1563 } 1564 1565 resource "azurerm_storage_account" "test" { 1566 name = "accsa%d" 1567 resource_group_name = "${azurerm_resource_group.test.name}" 1568 location = "westus" 1569 account_type = "Standard_LRS" 1570 1571 tags { 1572 environment = "staging" 1573 } 1574 } 1575 1576 resource "azurerm_storage_container" "test" { 1577 name = "vhds" 1578 resource_group_name = "${azurerm_resource_group.test.name}" 1579 storage_account_name = "${azurerm_storage_account.test.name}" 1580 container_access_type = "private" 1581 } 1582 1583 resource "azurerm_virtual_machine" "test" { 1584 name = "acctvm-%d" 1585 location = "West US" 1586 resource_group_name = "${azurerm_resource_group.test.name}" 1587 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1588 vm_size = "Standard_A0" 1589 delete_os_disk_on_termination = true 1590 1591 storage_image_reference { 1592 publisher = "Canonical" 1593 offer = "UbuntuServer" 1594 sku = "14.04.2-LTS" 1595 version = "latest" 1596 } 1597 1598 storage_os_disk { 1599 name = "myosdisk1" 1600 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1601 caching = "ReadWrite" 1602 create_option = "FromImage" 1603 } 1604 1605 os_profile { 1606 computer_name = "newhostname%d" 1607 admin_username = "testadmin" 1608 admin_password = "Password1234!" 1609 } 1610 1611 os_profile_linux_config { 1612 disable_password_authentication = false 1613 } 1614 } 1615 `