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