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