github.com/bpineau/terraform@v0.8.0-rc1.0.20161126184705-a8886012d185/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_basicLinuxMachineDestroyDisksBefore, ri, ri, ri, ri, ri, ri, ri, ri) 252 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter, ri, 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 TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) { 336 var afterCreate, afterUpdate compute.VirtualMachine 337 338 ri := acctest.RandInt() 339 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore, ri, ri, ri, ri, ri, ri, ri) 340 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter, ri, ri, ri, ri, ri, ri, ri) 341 resource.Test(t, resource.TestCase{ 342 PreCheck: func() { testAccPreCheck(t) }, 343 Providers: testAccProviders, 344 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 345 Steps: []resource.TestStep{ 346 resource.TestStep{ 347 Config: preConfig, 348 Check: resource.ComposeTestCheckFunc( 349 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 350 ), 351 }, 352 353 resource.TestStep{ 354 Config: postConfig, 355 Check: resource.ComposeTestCheckFunc( 356 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 357 testAccCheckVirtualMachineRecreated( 358 t, &afterCreate, &afterUpdate), 359 ), 360 }, 361 }, 362 }) 363 } 364 365 func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) { 366 var afterCreate, afterUpdate compute.VirtualMachine 367 368 ri := acctest.RandInt() 369 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 370 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged, ri, ri, ri, ri, ri, ri, ri) 371 resource.Test(t, resource.TestCase{ 372 PreCheck: func() { testAccPreCheck(t) }, 373 Providers: testAccProviders, 374 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 375 Steps: []resource.TestStep{ 376 resource.TestStep{ 377 Config: preConfig, 378 Check: resource.ComposeTestCheckFunc( 379 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 380 ), 381 }, 382 383 resource.TestStep{ 384 Config: postConfig, 385 Check: resource.ComposeTestCheckFunc( 386 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 387 testAccCheckVirtualMachineRecreated( 388 t, &afterCreate, &afterUpdate), 389 ), 390 }, 391 }, 392 }) 393 } 394 395 func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) resource.TestCheckFunc { 396 return func(s *terraform.State) error { 397 // Ensure we have enough information in state to look up in API 398 rs, ok := s.RootModule().Resources[name] 399 if !ok { 400 return fmt.Errorf("Not found: %s", name) 401 } 402 403 vmName := rs.Primary.Attributes["name"] 404 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 405 if !hasResourceGroup { 406 return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName) 407 } 408 409 conn := testAccProvider.Meta().(*ArmClient).vmClient 410 411 resp, err := conn.Get(resourceGroup, vmName, "") 412 if err != nil { 413 return fmt.Errorf("Bad: Get on vmClient: %s", err) 414 } 415 416 if resp.StatusCode == http.StatusNotFound { 417 return fmt.Errorf("Bad: VirtualMachine %q (resource group: %q) does not exist", vmName, resourceGroup) 418 } 419 420 *vm = resp 421 422 return nil 423 } 424 } 425 426 func testAccCheckVirtualMachineRecreated(t *testing.T, 427 before, after *compute.VirtualMachine) resource.TestCheckFunc { 428 return func(s *terraform.State) error { 429 if before.ID == after.ID { 430 t.Fatalf("Expected change of Virtual Machine IDs, but both were %v", before.ID) 431 } 432 return nil 433 } 434 } 435 436 func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error { 437 conn := testAccProvider.Meta().(*ArmClient).vmClient 438 439 for _, rs := range s.RootModule().Resources { 440 if rs.Type != "azurerm_virtual_machine" { 441 continue 442 } 443 444 name := rs.Primary.Attributes["name"] 445 resourceGroup := rs.Primary.Attributes["resource_group_name"] 446 447 resp, err := conn.Get(resourceGroup, name, "") 448 449 if err != nil { 450 return nil 451 } 452 453 if resp.StatusCode != http.StatusNotFound { 454 return fmt.Errorf("Virtual Machine still exists:\n%#v", resp.Properties) 455 } 456 } 457 458 return nil 459 } 460 461 func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) resource.TestCheckFunc { 462 return func(s *terraform.State) error { 463 for _, rs := range s.RootModule().Resources { 464 if rs.Type != "azurerm_storage_container" { 465 continue 466 } 467 468 // fetch storage account and container name 469 resourceGroup := rs.Primary.Attributes["resource_group_name"] 470 storageAccountName := rs.Primary.Attributes["storage_account_name"] 471 containerName := rs.Primary.Attributes["name"] 472 storageClient, _, err := testAccProvider.Meta().(*ArmClient).getBlobStorageClientForStorageAccount(resourceGroup, storageAccountName) 473 if err != nil { 474 return fmt.Errorf("Error creating Blob storage client: %s", err) 475 } 476 477 exists, err := storageClient.BlobExists(containerName, name) 478 if err != nil { 479 return fmt.Errorf("Error checking if Disk VHD Blob exists: %s", err) 480 } 481 482 if exists && !shouldExist { 483 return fmt.Errorf("Disk VHD Blob still exists") 484 } else if !exists && shouldExist { 485 return fmt.Errorf("Disk VHD Blob should exist") 486 } 487 } 488 489 return nil 490 } 491 } 492 493 func testCheckAzureRMVirtualMachineDisappears(name string, vm *compute.VirtualMachine) resource.TestCheckFunc { 494 return func(s *terraform.State) error { 495 // Ensure we have enough information in state to look up in API 496 rs, ok := s.RootModule().Resources[name] 497 if !ok { 498 return fmt.Errorf("Not found: %s", name) 499 } 500 501 vmName := rs.Primary.Attributes["name"] 502 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 503 if !hasResourceGroup { 504 return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName) 505 } 506 507 conn := testAccProvider.Meta().(*ArmClient).vmClient 508 509 _, err := conn.Delete(resourceGroup, vmName, make(chan struct{})) 510 if err != nil { 511 return fmt.Errorf("Bad: Delete on vmClient: %s", err) 512 } 513 514 return nil 515 } 516 } 517 518 var testAccAzureRMVirtualMachine_basicLinuxMachine = ` 519 resource "azurerm_resource_group" "test" { 520 name = "acctestRG-%d" 521 location = "West US" 522 } 523 524 resource "azurerm_virtual_network" "test" { 525 name = "acctvn-%d" 526 address_space = ["10.0.0.0/16"] 527 location = "West US" 528 resource_group_name = "${azurerm_resource_group.test.name}" 529 } 530 531 resource "azurerm_subnet" "test" { 532 name = "acctsub-%d" 533 resource_group_name = "${azurerm_resource_group.test.name}" 534 virtual_network_name = "${azurerm_virtual_network.test.name}" 535 address_prefix = "10.0.2.0/24" 536 } 537 538 resource "azurerm_network_interface" "test" { 539 name = "acctni-%d" 540 location = "West US" 541 resource_group_name = "${azurerm_resource_group.test.name}" 542 543 ip_configuration { 544 name = "testconfiguration1" 545 subnet_id = "${azurerm_subnet.test.id}" 546 private_ip_address_allocation = "dynamic" 547 } 548 } 549 550 resource "azurerm_storage_account" "test" { 551 name = "accsa%d" 552 resource_group_name = "${azurerm_resource_group.test.name}" 553 location = "westus" 554 account_type = "Standard_LRS" 555 556 tags { 557 environment = "staging" 558 } 559 } 560 561 resource "azurerm_storage_container" "test" { 562 name = "vhds" 563 resource_group_name = "${azurerm_resource_group.test.name}" 564 storage_account_name = "${azurerm_storage_account.test.name}" 565 container_access_type = "private" 566 } 567 568 resource "azurerm_virtual_machine" "test" { 569 name = "acctvm-%d" 570 location = "West US" 571 resource_group_name = "${azurerm_resource_group.test.name}" 572 network_interface_ids = ["${azurerm_network_interface.test.id}"] 573 vm_size = "Standard_A0" 574 575 storage_image_reference { 576 publisher = "Canonical" 577 offer = "UbuntuServer" 578 sku = "14.04.2-LTS" 579 version = "latest" 580 } 581 582 storage_os_disk { 583 name = "myosdisk1" 584 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 585 caching = "ReadWrite" 586 create_option = "FromImage" 587 disk_size_gb = "45" 588 } 589 590 os_profile { 591 computer_name = "hostname%d" 592 admin_username = "testadmin" 593 admin_password = "Password1234!" 594 } 595 596 os_profile_linux_config { 597 disable_password_authentication = false 598 } 599 600 tags { 601 environment = "Production" 602 cost-center = "Ops" 603 } 604 } 605 ` 606 607 var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = ` 608 resource "azurerm_resource_group" "test" { 609 name = "acctestRG-%d" 610 location = "West US" 611 } 612 613 resource "azurerm_virtual_network" "test" { 614 name = "acctvn-%d" 615 address_space = ["10.0.0.0/16"] 616 location = "West US" 617 resource_group_name = "${azurerm_resource_group.test.name}" 618 } 619 620 resource "azurerm_subnet" "test" { 621 name = "acctsub-%d" 622 resource_group_name = "${azurerm_resource_group.test.name}" 623 virtual_network_name = "${azurerm_virtual_network.test.name}" 624 address_prefix = "10.0.2.0/24" 625 } 626 627 resource "azurerm_network_interface" "test" { 628 name = "acctni-%d" 629 location = "West US" 630 resource_group_name = "${azurerm_resource_group.test.name}" 631 632 ip_configuration { 633 name = "testconfiguration1" 634 subnet_id = "${azurerm_subnet.test.id}" 635 private_ip_address_allocation = "dynamic" 636 } 637 } 638 639 resource "azurerm_storage_account" "test" { 640 name = "accsa%d" 641 resource_group_name = "${azurerm_resource_group.test.name}" 642 location = "westus" 643 account_type = "Standard_LRS" 644 645 tags { 646 environment = "staging" 647 } 648 } 649 650 resource "azurerm_storage_container" "test" { 651 name = "vhds" 652 resource_group_name = "${azurerm_resource_group.test.name}" 653 storage_account_name = "${azurerm_storage_account.test.name}" 654 container_access_type = "private" 655 } 656 657 resource "azurerm_virtual_machine" "test" { 658 name = "acctvm-%d" 659 location = "West US" 660 resource_group_name = "${azurerm_resource_group.test.name}" 661 network_interface_ids = ["${azurerm_network_interface.test.id}"] 662 vm_size = "Standard_A0" 663 delete_os_disk_on_termination = true 664 665 storage_image_reference { 666 publisher = "Canonical" 667 offer = "UbuntuServer" 668 sku = "14.04.2-LTS" 669 version = "latest" 670 } 671 672 storage_os_disk { 673 name = "myosdisk1" 674 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 675 caching = "ReadWrite" 676 create_option = "FromImage" 677 } 678 679 os_profile { 680 computer_name = "hostname%d" 681 admin_username = "testadmin" 682 admin_password = "Password1234!" 683 } 684 685 os_profile_linux_config { 686 disable_password_authentication = false 687 } 688 689 tags { 690 environment = "Production" 691 cost-center = "Ops" 692 } 693 } 694 ` 695 696 var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore = ` 697 resource "azurerm_resource_group" "test" { 698 name = "acctestRG-%d" 699 location = "West US" 700 } 701 702 resource "azurerm_resource_group" "test-sa" { 703 name = "acctestRG-sa-%d" 704 location = "West US" 705 } 706 707 resource "azurerm_virtual_network" "test" { 708 name = "acctvn-%d" 709 address_space = ["10.0.0.0/16"] 710 location = "West US" 711 resource_group_name = "${azurerm_resource_group.test.name}" 712 } 713 714 resource "azurerm_subnet" "test" { 715 name = "acctsub-%d" 716 resource_group_name = "${azurerm_resource_group.test.name}" 717 virtual_network_name = "${azurerm_virtual_network.test.name}" 718 address_prefix = "10.0.2.0/24" 719 } 720 721 resource "azurerm_network_interface" "test" { 722 name = "acctni-%d" 723 location = "West US" 724 resource_group_name = "${azurerm_resource_group.test.name}" 725 726 ip_configuration { 727 name = "testconfiguration1" 728 subnet_id = "${azurerm_subnet.test.id}" 729 private_ip_address_allocation = "dynamic" 730 } 731 } 732 733 resource "azurerm_storage_account" "test" { 734 name = "accsa%d" 735 resource_group_name = "${azurerm_resource_group.test-sa.name}" 736 location = "westus" 737 account_type = "Standard_LRS" 738 739 tags { 740 environment = "staging" 741 } 742 } 743 744 resource "azurerm_storage_container" "test" { 745 name = "vhds" 746 resource_group_name = "${azurerm_resource_group.test-sa.name}" 747 storage_account_name = "${azurerm_storage_account.test.name}" 748 container_access_type = "private" 749 } 750 751 resource "azurerm_virtual_machine" "test" { 752 name = "acctvm-%d" 753 location = "West US" 754 resource_group_name = "${azurerm_resource_group.test.name}" 755 network_interface_ids = ["${azurerm_network_interface.test.id}"] 756 vm_size = "Standard_A0" 757 758 storage_image_reference { 759 publisher = "Canonical" 760 offer = "UbuntuServer" 761 sku = "14.04.2-LTS" 762 version = "latest" 763 } 764 765 storage_os_disk { 766 name = "myosdisk1" 767 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 768 caching = "ReadWrite" 769 create_option = "FromImage" 770 } 771 772 delete_os_disk_on_termination = true 773 774 storage_data_disk { 775 name = "mydatadisk1" 776 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd" 777 disk_size_gb = "1023" 778 create_option = "Empty" 779 lun = 0 780 } 781 782 delete_data_disks_on_termination = true 783 784 os_profile { 785 computer_name = "hostname%d" 786 admin_username = "testadmin" 787 admin_password = "Password1234!" 788 } 789 790 os_profile_linux_config { 791 disable_password_authentication = false 792 } 793 794 tags { 795 environment = "Production" 796 cost-center = "Ops" 797 } 798 } 799 ` 800 801 var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter = ` 802 resource "azurerm_resource_group" "test" { 803 name = "acctestRG-%d" 804 location = "West US" 805 } 806 807 resource "azurerm_resource_group" "test-sa" { 808 name = "acctestRG-sa-%d" 809 location = "West US" 810 } 811 812 resource "azurerm_virtual_network" "test" { 813 name = "acctvn-%d" 814 address_space = ["10.0.0.0/16"] 815 location = "West US" 816 resource_group_name = "${azurerm_resource_group.test.name}" 817 } 818 819 resource "azurerm_subnet" "test" { 820 name = "acctsub-%d" 821 resource_group_name = "${azurerm_resource_group.test.name}" 822 virtual_network_name = "${azurerm_virtual_network.test.name}" 823 address_prefix = "10.0.2.0/24" 824 } 825 826 resource "azurerm_network_interface" "test" { 827 name = "acctni-%d" 828 location = "West US" 829 resource_group_name = "${azurerm_resource_group.test.name}" 830 831 ip_configuration { 832 name = "testconfiguration1" 833 subnet_id = "${azurerm_subnet.test.id}" 834 private_ip_address_allocation = "dynamic" 835 } 836 } 837 838 resource "azurerm_storage_account" "test" { 839 name = "accsa%d" 840 resource_group_name = "${azurerm_resource_group.test-sa.name}" 841 location = "westus" 842 account_type = "Standard_LRS" 843 844 tags { 845 environment = "staging" 846 } 847 } 848 849 resource "azurerm_storage_container" "test" { 850 name = "vhds" 851 resource_group_name = "${azurerm_resource_group.test-sa.name}" 852 storage_account_name = "${azurerm_storage_account.test.name}" 853 container_access_type = "private" 854 } 855 ` 856 857 var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = ` 858 resource "azurerm_resource_group" "test" { 859 name = "acctestRG-%d" 860 location = "West US" 861 } 862 863 resource "azurerm_virtual_network" "test" { 864 name = "acctvn-%d" 865 address_space = ["10.0.0.0/16"] 866 location = "West US" 867 resource_group_name = "${azurerm_resource_group.test.name}" 868 } 869 870 resource "azurerm_subnet" "test" { 871 name = "acctsub-%d" 872 resource_group_name = "${azurerm_resource_group.test.name}" 873 virtual_network_name = "${azurerm_virtual_network.test.name}" 874 address_prefix = "10.0.2.0/24" 875 } 876 877 resource "azurerm_network_interface" "test" { 878 name = "acctni-%d" 879 location = "West US" 880 resource_group_name = "${azurerm_resource_group.test.name}" 881 882 ip_configuration { 883 name = "testconfiguration1" 884 subnet_id = "${azurerm_subnet.test.id}" 885 private_ip_address_allocation = "dynamic" 886 } 887 } 888 889 resource "azurerm_storage_account" "test" { 890 name = "accsa%d" 891 resource_group_name = "${azurerm_resource_group.test.name}" 892 location = "westus" 893 account_type = "Standard_LRS" 894 895 tags { 896 environment = "staging" 897 } 898 } 899 900 resource "azurerm_storage_container" "test" { 901 name = "vhds" 902 resource_group_name = "${azurerm_resource_group.test.name}" 903 storage_account_name = "${azurerm_storage_account.test.name}" 904 container_access_type = "private" 905 } 906 ` 907 908 var testAccAzureRMVirtualMachine_withDataDisk = ` 909 resource "azurerm_resource_group" "test" { 910 name = "acctestRG-%d" 911 location = "West US" 912 } 913 914 resource "azurerm_virtual_network" "test" { 915 name = "acctvn-%d" 916 address_space = ["10.0.0.0/16"] 917 location = "West US" 918 resource_group_name = "${azurerm_resource_group.test.name}" 919 } 920 921 resource "azurerm_subnet" "test" { 922 name = "acctsub-%d" 923 resource_group_name = "${azurerm_resource_group.test.name}" 924 virtual_network_name = "${azurerm_virtual_network.test.name}" 925 address_prefix = "10.0.2.0/24" 926 } 927 928 resource "azurerm_network_interface" "test" { 929 name = "acctni-%d" 930 location = "West US" 931 resource_group_name = "${azurerm_resource_group.test.name}" 932 933 ip_configuration { 934 name = "testconfiguration1" 935 subnet_id = "${azurerm_subnet.test.id}" 936 private_ip_address_allocation = "dynamic" 937 } 938 } 939 940 resource "azurerm_storage_account" "test" { 941 name = "accsa%d" 942 resource_group_name = "${azurerm_resource_group.test.name}" 943 location = "westus" 944 account_type = "Standard_LRS" 945 946 tags { 947 environment = "staging" 948 } 949 } 950 951 resource "azurerm_storage_container" "test" { 952 name = "vhds" 953 resource_group_name = "${azurerm_resource_group.test.name}" 954 storage_account_name = "${azurerm_storage_account.test.name}" 955 container_access_type = "private" 956 } 957 958 resource "azurerm_virtual_machine" "test" { 959 name = "acctvm-%d" 960 location = "West US" 961 resource_group_name = "${azurerm_resource_group.test.name}" 962 network_interface_ids = ["${azurerm_network_interface.test.id}"] 963 vm_size = "Standard_A0" 964 965 storage_image_reference { 966 publisher = "Canonical" 967 offer = "UbuntuServer" 968 sku = "14.04.2-LTS" 969 version = "latest" 970 } 971 972 storage_os_disk { 973 name = "myosdisk1" 974 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 975 caching = "ReadWrite" 976 create_option = "FromImage" 977 } 978 979 storage_data_disk { 980 name = "mydatadisk1" 981 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd" 982 disk_size_gb = "1023" 983 create_option = "Empty" 984 lun = 0 985 } 986 987 os_profile { 988 computer_name = "hostname%d" 989 admin_username = "testadmin" 990 admin_password = "Password1234!" 991 } 992 993 os_profile_linux_config { 994 disable_password_authentication = false 995 } 996 997 tags { 998 environment = "Production" 999 cost-center = "Ops" 1000 } 1001 } 1002 ` 1003 1004 var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = ` 1005 resource "azurerm_resource_group" "test" { 1006 name = "acctestRG-%d" 1007 location = "West US" 1008 } 1009 1010 resource "azurerm_virtual_network" "test" { 1011 name = "acctvn-%d" 1012 address_space = ["10.0.0.0/16"] 1013 location = "West US" 1014 resource_group_name = "${azurerm_resource_group.test.name}" 1015 } 1016 1017 resource "azurerm_subnet" "test" { 1018 name = "acctsub-%d" 1019 resource_group_name = "${azurerm_resource_group.test.name}" 1020 virtual_network_name = "${azurerm_virtual_network.test.name}" 1021 address_prefix = "10.0.2.0/24" 1022 } 1023 1024 resource "azurerm_network_interface" "test" { 1025 name = "acctni-%d" 1026 location = "West US" 1027 resource_group_name = "${azurerm_resource_group.test.name}" 1028 1029 ip_configuration { 1030 name = "testconfiguration1" 1031 subnet_id = "${azurerm_subnet.test.id}" 1032 private_ip_address_allocation = "dynamic" 1033 } 1034 } 1035 1036 resource "azurerm_storage_account" "test" { 1037 name = "accsa%d" 1038 resource_group_name = "${azurerm_resource_group.test.name}" 1039 location = "westus" 1040 account_type = "Standard_LRS" 1041 1042 tags { 1043 environment = "staging" 1044 } 1045 } 1046 1047 resource "azurerm_storage_container" "test" { 1048 name = "vhds" 1049 resource_group_name = "${azurerm_resource_group.test.name}" 1050 storage_account_name = "${azurerm_storage_account.test.name}" 1051 container_access_type = "private" 1052 } 1053 1054 resource "azurerm_virtual_machine" "test" { 1055 name = "acctvm-%d" 1056 location = "West US" 1057 resource_group_name = "${azurerm_resource_group.test.name}" 1058 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1059 vm_size = "Standard_A0" 1060 1061 storage_image_reference { 1062 publisher = "Canonical" 1063 offer = "UbuntuServer" 1064 sku = "14.04.2-LTS" 1065 version = "latest" 1066 } 1067 1068 storage_os_disk { 1069 name = "myosdisk1" 1070 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1071 caching = "ReadWrite" 1072 create_option = "FromImage" 1073 } 1074 1075 os_profile { 1076 computer_name = "hostname%d" 1077 admin_username = "testadmin" 1078 admin_password = "Password1234!" 1079 } 1080 1081 os_profile_linux_config { 1082 disable_password_authentication = false 1083 } 1084 1085 tags { 1086 environment = "Production" 1087 } 1088 } 1089 ` 1090 1091 var testAccAzureRMVirtualMachine_updatedLinuxMachine = ` 1092 resource "azurerm_resource_group" "test" { 1093 name = "acctestRG-%d" 1094 location = "West US" 1095 } 1096 1097 resource "azurerm_virtual_network" "test" { 1098 name = "acctvn-%d" 1099 address_space = ["10.0.0.0/16"] 1100 location = "West US" 1101 resource_group_name = "${azurerm_resource_group.test.name}" 1102 } 1103 1104 resource "azurerm_subnet" "test" { 1105 name = "acctsub-%d" 1106 resource_group_name = "${azurerm_resource_group.test.name}" 1107 virtual_network_name = "${azurerm_virtual_network.test.name}" 1108 address_prefix = "10.0.2.0/24" 1109 } 1110 1111 resource "azurerm_network_interface" "test" { 1112 name = "acctni-%d" 1113 location = "West US" 1114 resource_group_name = "${azurerm_resource_group.test.name}" 1115 1116 ip_configuration { 1117 name = "testconfiguration1" 1118 subnet_id = "${azurerm_subnet.test.id}" 1119 private_ip_address_allocation = "dynamic" 1120 } 1121 } 1122 1123 resource "azurerm_storage_account" "test" { 1124 name = "accsa%d" 1125 resource_group_name = "${azurerm_resource_group.test.name}" 1126 location = "westus" 1127 account_type = "Standard_LRS" 1128 1129 tags { 1130 environment = "staging" 1131 } 1132 } 1133 1134 resource "azurerm_storage_container" "test" { 1135 name = "vhds" 1136 resource_group_name = "${azurerm_resource_group.test.name}" 1137 storage_account_name = "${azurerm_storage_account.test.name}" 1138 container_access_type = "private" 1139 } 1140 1141 resource "azurerm_virtual_machine" "test" { 1142 name = "acctvm-%d" 1143 location = "West US" 1144 resource_group_name = "${azurerm_resource_group.test.name}" 1145 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1146 vm_size = "Standard_A1" 1147 1148 storage_image_reference { 1149 publisher = "Canonical" 1150 offer = "UbuntuServer" 1151 sku = "14.04.2-LTS" 1152 version = "latest" 1153 } 1154 1155 storage_os_disk { 1156 name = "myosdisk1" 1157 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1158 caching = "ReadWrite" 1159 create_option = "FromImage" 1160 } 1161 1162 os_profile { 1163 computer_name = "hostname%d" 1164 admin_username = "testadmin" 1165 admin_password = "Password1234!" 1166 } 1167 1168 os_profile_linux_config { 1169 disable_password_authentication = false 1170 } 1171 } 1172 ` 1173 1174 var testAccAzureRMVirtualMachine_basicWindowsMachine = ` 1175 resource "azurerm_resource_group" "test" { 1176 name = "acctestRG-%d" 1177 location = "West US" 1178 } 1179 1180 resource "azurerm_virtual_network" "test" { 1181 name = "acctvn-%d" 1182 address_space = ["10.0.0.0/16"] 1183 location = "West US" 1184 resource_group_name = "${azurerm_resource_group.test.name}" 1185 } 1186 1187 resource "azurerm_subnet" "test" { 1188 name = "acctsub-%d" 1189 resource_group_name = "${azurerm_resource_group.test.name}" 1190 virtual_network_name = "${azurerm_virtual_network.test.name}" 1191 address_prefix = "10.0.2.0/24" 1192 } 1193 1194 resource "azurerm_network_interface" "test" { 1195 name = "acctni-%d" 1196 location = "West US" 1197 resource_group_name = "${azurerm_resource_group.test.name}" 1198 1199 ip_configuration { 1200 name = "testconfiguration1" 1201 subnet_id = "${azurerm_subnet.test.id}" 1202 private_ip_address_allocation = "dynamic" 1203 } 1204 } 1205 1206 resource "azurerm_storage_account" "test" { 1207 name = "accsa%d" 1208 resource_group_name = "${azurerm_resource_group.test.name}" 1209 location = "westus" 1210 account_type = "Standard_LRS" 1211 1212 tags { 1213 environment = "staging" 1214 } 1215 } 1216 1217 resource "azurerm_storage_container" "test" { 1218 name = "vhds" 1219 resource_group_name = "${azurerm_resource_group.test.name}" 1220 storage_account_name = "${azurerm_storage_account.test.name}" 1221 container_access_type = "private" 1222 } 1223 1224 resource "azurerm_virtual_machine" "test" { 1225 name = "acctvm-%d" 1226 location = "West US" 1227 resource_group_name = "${azurerm_resource_group.test.name}" 1228 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1229 vm_size = "Standard_A0" 1230 1231 storage_image_reference { 1232 publisher = "MicrosoftWindowsServer" 1233 offer = "WindowsServer" 1234 sku = "2012-Datacenter" 1235 version = "latest" 1236 } 1237 1238 storage_os_disk { 1239 name = "myosdisk1" 1240 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1241 caching = "ReadWrite" 1242 create_option = "FromImage" 1243 } 1244 1245 os_profile { 1246 computer_name = "winhost01" 1247 admin_username = "testadmin" 1248 admin_password = "Password1234!" 1249 } 1250 1251 os_profile_windows_config { 1252 enable_automatic_upgrades = false 1253 provision_vm_agent = true 1254 } 1255 } 1256 ` 1257 1258 var testAccAzureRMVirtualMachine_windowsUnattendedConfig = ` 1259 resource "azurerm_resource_group" "test" { 1260 name = "acctestRG-%d" 1261 location = "West US" 1262 } 1263 1264 resource "azurerm_virtual_network" "test" { 1265 name = "acctvn-%d" 1266 address_space = ["10.0.0.0/16"] 1267 location = "West US" 1268 resource_group_name = "${azurerm_resource_group.test.name}" 1269 } 1270 1271 resource "azurerm_subnet" "test" { 1272 name = "acctsub-%d" 1273 resource_group_name = "${azurerm_resource_group.test.name}" 1274 virtual_network_name = "${azurerm_virtual_network.test.name}" 1275 address_prefix = "10.0.2.0/24" 1276 } 1277 1278 resource "azurerm_network_interface" "test" { 1279 name = "acctni-%d" 1280 location = "West US" 1281 resource_group_name = "${azurerm_resource_group.test.name}" 1282 1283 ip_configuration { 1284 name = "testconfiguration1" 1285 subnet_id = "${azurerm_subnet.test.id}" 1286 private_ip_address_allocation = "dynamic" 1287 } 1288 } 1289 1290 resource "azurerm_storage_account" "test" { 1291 name = "accsa%d" 1292 resource_group_name = "${azurerm_resource_group.test.name}" 1293 location = "westus" 1294 account_type = "Standard_LRS" 1295 1296 tags { 1297 environment = "staging" 1298 } 1299 } 1300 1301 resource "azurerm_storage_container" "test" { 1302 name = "vhds" 1303 resource_group_name = "${azurerm_resource_group.test.name}" 1304 storage_account_name = "${azurerm_storage_account.test.name}" 1305 container_access_type = "private" 1306 } 1307 1308 resource "azurerm_virtual_machine" "test" { 1309 name = "acctvm-%d" 1310 location = "West US" 1311 resource_group_name = "${azurerm_resource_group.test.name}" 1312 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1313 vm_size = "Standard_A0" 1314 1315 storage_image_reference { 1316 publisher = "MicrosoftWindowsServer" 1317 offer = "WindowsServer" 1318 sku = "2012-Datacenter" 1319 version = "latest" 1320 } 1321 1322 storage_os_disk { 1323 name = "myosdisk1" 1324 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1325 caching = "ReadWrite" 1326 create_option = "FromImage" 1327 } 1328 1329 os_profile { 1330 computer_name = "winhost01" 1331 admin_username = "testadmin" 1332 admin_password = "Password1234!" 1333 } 1334 1335 os_profile_windows_config { 1336 provision_vm_agent = true 1337 additional_unattend_config { 1338 pass = "oobeSystem" 1339 component = "Microsoft-Windows-Shell-Setup" 1340 setting_name = "FirstLogonCommands" 1341 content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>" 1342 } 1343 } 1344 1345 } 1346 ` 1347 1348 var testAccAzureRMVirtualMachine_diagnosticsProfile = ` 1349 resource "azurerm_resource_group" "test" { 1350 name = "acctestRG-%d" 1351 location = "West US" 1352 } 1353 1354 resource "azurerm_virtual_network" "test" { 1355 name = "acctvn-%d" 1356 address_space = ["10.0.0.0/16"] 1357 location = "West US" 1358 resource_group_name = "${azurerm_resource_group.test.name}" 1359 } 1360 1361 resource "azurerm_subnet" "test" { 1362 name = "acctsub-%d" 1363 resource_group_name = "${azurerm_resource_group.test.name}" 1364 virtual_network_name = "${azurerm_virtual_network.test.name}" 1365 address_prefix = "10.0.2.0/24" 1366 } 1367 1368 resource "azurerm_network_interface" "test" { 1369 name = "acctni-%d" 1370 location = "West US" 1371 resource_group_name = "${azurerm_resource_group.test.name}" 1372 1373 ip_configuration { 1374 name = "testconfiguration1" 1375 subnet_id = "${azurerm_subnet.test.id}" 1376 private_ip_address_allocation = "dynamic" 1377 } 1378 } 1379 1380 resource "azurerm_storage_account" "test" { 1381 name = "accsa%d" 1382 resource_group_name = "${azurerm_resource_group.test.name}" 1383 location = "westus" 1384 account_type = "Standard_LRS" 1385 1386 tags { 1387 environment = "staging" 1388 } 1389 } 1390 1391 resource "azurerm_storage_container" "test" { 1392 name = "vhds" 1393 resource_group_name = "${azurerm_resource_group.test.name}" 1394 storage_account_name = "${azurerm_storage_account.test.name}" 1395 container_access_type = "private" 1396 } 1397 1398 resource "azurerm_virtual_machine" "test" { 1399 name = "acctvm-%d" 1400 location = "West US" 1401 resource_group_name = "${azurerm_resource_group.test.name}" 1402 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1403 vm_size = "Standard_A0" 1404 1405 storage_image_reference { 1406 publisher = "MicrosoftWindowsServer" 1407 offer = "WindowsServer" 1408 sku = "2012-Datacenter" 1409 version = "latest" 1410 } 1411 1412 storage_os_disk { 1413 name = "myosdisk1" 1414 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1415 caching = "ReadWrite" 1416 create_option = "FromImage" 1417 } 1418 1419 os_profile { 1420 computer_name = "winhost01" 1421 admin_username = "testadmin" 1422 admin_password = "Password1234!" 1423 } 1424 1425 boot_diagnostics { 1426 enabled = true 1427 storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" 1428 } 1429 1430 os_profile_windows_config { 1431 winrm { 1432 protocol = "http" 1433 } 1434 } 1435 } 1436 1437 ` 1438 1439 var testAccAzureRMVirtualMachine_winRMConfig = ` 1440 resource "azurerm_resource_group" "test" { 1441 name = "acctestRG-%d" 1442 location = "West US" 1443 } 1444 1445 resource "azurerm_virtual_network" "test" { 1446 name = "acctvn-%d" 1447 address_space = ["10.0.0.0/16"] 1448 location = "West US" 1449 resource_group_name = "${azurerm_resource_group.test.name}" 1450 } 1451 1452 resource "azurerm_subnet" "test" { 1453 name = "acctsub-%d" 1454 resource_group_name = "${azurerm_resource_group.test.name}" 1455 virtual_network_name = "${azurerm_virtual_network.test.name}" 1456 address_prefix = "10.0.2.0/24" 1457 } 1458 1459 resource "azurerm_network_interface" "test" { 1460 name = "acctni-%d" 1461 location = "West US" 1462 resource_group_name = "${azurerm_resource_group.test.name}" 1463 1464 ip_configuration { 1465 name = "testconfiguration1" 1466 subnet_id = "${azurerm_subnet.test.id}" 1467 private_ip_address_allocation = "dynamic" 1468 } 1469 } 1470 1471 resource "azurerm_storage_account" "test" { 1472 name = "accsa%d" 1473 resource_group_name = "${azurerm_resource_group.test.name}" 1474 location = "westus" 1475 account_type = "Standard_LRS" 1476 1477 tags { 1478 environment = "staging" 1479 } 1480 } 1481 1482 resource "azurerm_storage_container" "test" { 1483 name = "vhds" 1484 resource_group_name = "${azurerm_resource_group.test.name}" 1485 storage_account_name = "${azurerm_storage_account.test.name}" 1486 container_access_type = "private" 1487 } 1488 1489 resource "azurerm_virtual_machine" "test" { 1490 name = "acctvm-%d" 1491 location = "West US" 1492 resource_group_name = "${azurerm_resource_group.test.name}" 1493 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1494 vm_size = "Standard_A0" 1495 1496 storage_image_reference { 1497 publisher = "MicrosoftWindowsServer" 1498 offer = "WindowsServer" 1499 sku = "2012-Datacenter" 1500 version = "latest" 1501 } 1502 1503 storage_os_disk { 1504 name = "myosdisk1" 1505 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1506 caching = "ReadWrite" 1507 create_option = "FromImage" 1508 } 1509 1510 os_profile { 1511 computer_name = "winhost01" 1512 admin_username = "testadmin" 1513 admin_password = "Password1234!" 1514 } 1515 1516 os_profile_windows_config { 1517 winrm { 1518 protocol = "http" 1519 } 1520 } 1521 } 1522 ` 1523 1524 var testAccAzureRMVirtualMachine_withAvailabilitySet = ` 1525 resource "azurerm_resource_group" "test" { 1526 name = "acctestRG-%d" 1527 location = "West US" 1528 } 1529 1530 resource "azurerm_virtual_network" "test" { 1531 name = "acctvn-%d" 1532 address_space = ["10.0.0.0/16"] 1533 location = "West US" 1534 resource_group_name = "${azurerm_resource_group.test.name}" 1535 } 1536 1537 resource "azurerm_subnet" "test" { 1538 name = "acctsub-%d" 1539 resource_group_name = "${azurerm_resource_group.test.name}" 1540 virtual_network_name = "${azurerm_virtual_network.test.name}" 1541 address_prefix = "10.0.2.0/24" 1542 } 1543 1544 resource "azurerm_network_interface" "test" { 1545 name = "acctni-%d" 1546 location = "West US" 1547 resource_group_name = "${azurerm_resource_group.test.name}" 1548 1549 ip_configuration { 1550 name = "testconfiguration1" 1551 subnet_id = "${azurerm_subnet.test.id}" 1552 private_ip_address_allocation = "dynamic" 1553 } 1554 } 1555 1556 resource "azurerm_storage_account" "test" { 1557 name = "accsa%d" 1558 resource_group_name = "${azurerm_resource_group.test.name}" 1559 location = "westus" 1560 account_type = "Standard_LRS" 1561 1562 tags { 1563 environment = "staging" 1564 } 1565 } 1566 1567 resource "azurerm_availability_set" "test" { 1568 name = "availabilityset%d" 1569 location = "West US" 1570 resource_group_name = "${azurerm_resource_group.test.name}" 1571 } 1572 1573 resource "azurerm_storage_container" "test" { 1574 name = "vhds" 1575 resource_group_name = "${azurerm_resource_group.test.name}" 1576 storage_account_name = "${azurerm_storage_account.test.name}" 1577 container_access_type = "private" 1578 } 1579 1580 resource "azurerm_virtual_machine" "test" { 1581 name = "acctvm-%d" 1582 location = "West US" 1583 resource_group_name = "${azurerm_resource_group.test.name}" 1584 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1585 vm_size = "Standard_A0" 1586 availability_set_id = "${azurerm_availability_set.test.id}" 1587 delete_os_disk_on_termination = true 1588 1589 storage_image_reference { 1590 publisher = "Canonical" 1591 offer = "UbuntuServer" 1592 sku = "14.04.2-LTS" 1593 version = "latest" 1594 } 1595 1596 storage_os_disk { 1597 name = "myosdisk1" 1598 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1599 caching = "ReadWrite" 1600 create_option = "FromImage" 1601 } 1602 1603 os_profile { 1604 computer_name = "hostname%d" 1605 admin_username = "testadmin" 1606 admin_password = "Password1234!" 1607 } 1608 1609 os_profile_linux_config { 1610 disable_password_authentication = false 1611 } 1612 } 1613 ` 1614 1615 var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` 1616 resource "azurerm_resource_group" "test" { 1617 name = "acctestRG-%d" 1618 location = "West US" 1619 } 1620 1621 resource "azurerm_virtual_network" "test" { 1622 name = "acctvn-%d" 1623 address_space = ["10.0.0.0/16"] 1624 location = "West US" 1625 resource_group_name = "${azurerm_resource_group.test.name}" 1626 } 1627 1628 resource "azurerm_subnet" "test" { 1629 name = "acctsub-%d" 1630 resource_group_name = "${azurerm_resource_group.test.name}" 1631 virtual_network_name = "${azurerm_virtual_network.test.name}" 1632 address_prefix = "10.0.2.0/24" 1633 } 1634 1635 resource "azurerm_network_interface" "test" { 1636 name = "acctni-%d" 1637 location = "West US" 1638 resource_group_name = "${azurerm_resource_group.test.name}" 1639 1640 ip_configuration { 1641 name = "testconfiguration1" 1642 subnet_id = "${azurerm_subnet.test.id}" 1643 private_ip_address_allocation = "dynamic" 1644 } 1645 } 1646 1647 resource "azurerm_storage_account" "test" { 1648 name = "accsa%d" 1649 resource_group_name = "${azurerm_resource_group.test.name}" 1650 location = "westus" 1651 account_type = "Standard_LRS" 1652 1653 tags { 1654 environment = "staging" 1655 } 1656 } 1657 1658 resource "azurerm_availability_set" "test" { 1659 name = "updatedAvailabilitySet%d" 1660 location = "West US" 1661 resource_group_name = "${azurerm_resource_group.test.name}" 1662 } 1663 1664 resource "azurerm_storage_container" "test" { 1665 name = "vhds" 1666 resource_group_name = "${azurerm_resource_group.test.name}" 1667 storage_account_name = "${azurerm_storage_account.test.name}" 1668 container_access_type = "private" 1669 } 1670 1671 resource "azurerm_virtual_machine" "test" { 1672 name = "acctvm-%d" 1673 location = "West US" 1674 resource_group_name = "${azurerm_resource_group.test.name}" 1675 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1676 vm_size = "Standard_A0" 1677 availability_set_id = "${azurerm_availability_set.test.id}" 1678 delete_os_disk_on_termination = true 1679 1680 storage_image_reference { 1681 publisher = "Canonical" 1682 offer = "UbuntuServer" 1683 sku = "14.04.2-LTS" 1684 version = "latest" 1685 } 1686 1687 storage_os_disk { 1688 name = "myosdisk1" 1689 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1690 caching = "ReadWrite" 1691 create_option = "FromImage" 1692 } 1693 1694 os_profile { 1695 computer_name = "hostname%d" 1696 admin_username = "testadmin" 1697 admin_password = "Password1234!" 1698 } 1699 1700 os_profile_linux_config { 1701 disable_password_authentication = false 1702 } 1703 } 1704 ` 1705 1706 var testAccAzureRMVirtualMachine_updateMachineName = ` 1707 resource "azurerm_resource_group" "test" { 1708 name = "acctestRG-%d" 1709 location = "West US" 1710 } 1711 1712 resource "azurerm_virtual_network" "test" { 1713 name = "acctvn-%d" 1714 address_space = ["10.0.0.0/16"] 1715 location = "West US" 1716 resource_group_name = "${azurerm_resource_group.test.name}" 1717 } 1718 1719 resource "azurerm_subnet" "test" { 1720 name = "acctsub-%d" 1721 resource_group_name = "${azurerm_resource_group.test.name}" 1722 virtual_network_name = "${azurerm_virtual_network.test.name}" 1723 address_prefix = "10.0.2.0/24" 1724 } 1725 1726 resource "azurerm_network_interface" "test" { 1727 name = "acctni-%d" 1728 location = "West US" 1729 resource_group_name = "${azurerm_resource_group.test.name}" 1730 1731 ip_configuration { 1732 name = "testconfiguration1" 1733 subnet_id = "${azurerm_subnet.test.id}" 1734 private_ip_address_allocation = "dynamic" 1735 } 1736 } 1737 1738 resource "azurerm_storage_account" "test" { 1739 name = "accsa%d" 1740 resource_group_name = "${azurerm_resource_group.test.name}" 1741 location = "westus" 1742 account_type = "Standard_LRS" 1743 1744 tags { 1745 environment = "staging" 1746 } 1747 } 1748 1749 resource "azurerm_storage_container" "test" { 1750 name = "vhds" 1751 resource_group_name = "${azurerm_resource_group.test.name}" 1752 storage_account_name = "${azurerm_storage_account.test.name}" 1753 container_access_type = "private" 1754 } 1755 1756 resource "azurerm_virtual_machine" "test" { 1757 name = "acctvm-%d" 1758 location = "West US" 1759 resource_group_name = "${azurerm_resource_group.test.name}" 1760 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1761 vm_size = "Standard_A0" 1762 delete_os_disk_on_termination = true 1763 1764 storage_image_reference { 1765 publisher = "Canonical" 1766 offer = "UbuntuServer" 1767 sku = "14.04.2-LTS" 1768 version = "latest" 1769 } 1770 1771 storage_os_disk { 1772 name = "myosdisk1" 1773 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1774 caching = "ReadWrite" 1775 create_option = "FromImage" 1776 } 1777 1778 os_profile { 1779 computer_name = "newhostname%d" 1780 admin_username = "testadmin" 1781 admin_password = "Password1234!" 1782 } 1783 1784 os_profile_linux_config { 1785 disable_password_authentication = false 1786 } 1787 } 1788 ` 1789 1790 var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore = ` 1791 resource "azurerm_resource_group" "test" { 1792 name = "acctestRG-%d" 1793 location = "West US" 1794 } 1795 1796 resource "azurerm_virtual_network" "test" { 1797 name = "acctvn-%d" 1798 address_space = ["10.0.0.0/16"] 1799 location = "West US" 1800 resource_group_name = "${azurerm_resource_group.test.name}" 1801 } 1802 1803 resource "azurerm_subnet" "test" { 1804 name = "acctsub-%d" 1805 resource_group_name = "${azurerm_resource_group.test.name}" 1806 virtual_network_name = "${azurerm_virtual_network.test.name}" 1807 address_prefix = "10.0.2.0/24" 1808 } 1809 1810 resource "azurerm_network_interface" "test" { 1811 name = "acctni-%d" 1812 location = "West US" 1813 resource_group_name = "${azurerm_resource_group.test.name}" 1814 1815 ip_configuration { 1816 name = "testconfiguration1" 1817 subnet_id = "${azurerm_subnet.test.id}" 1818 private_ip_address_allocation = "dynamic" 1819 } 1820 } 1821 1822 resource "azurerm_storage_account" "test" { 1823 name = "accsa%d" 1824 resource_group_name = "${azurerm_resource_group.test.name}" 1825 location = "westus" 1826 account_type = "Standard_LRS" 1827 1828 tags { 1829 environment = "staging" 1830 } 1831 } 1832 1833 resource "azurerm_storage_container" "test" { 1834 name = "vhds" 1835 resource_group_name = "${azurerm_resource_group.test.name}" 1836 storage_account_name = "${azurerm_storage_account.test.name}" 1837 container_access_type = "private" 1838 } 1839 1840 resource "azurerm_virtual_machine" "test" { 1841 name = "acctvm-%d" 1842 location = "West US" 1843 resource_group_name = "${azurerm_resource_group.test.name}" 1844 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1845 vm_size = "Standard_A0" 1846 delete_os_disk_on_termination = true 1847 1848 storage_image_reference { 1849 publisher = "Canonical" 1850 offer = "UbuntuServer" 1851 sku = "14.04.2-LTS" 1852 version = "latest" 1853 } 1854 1855 storage_os_disk { 1856 name = "myosdisk1" 1857 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1858 caching = "ReadWrite" 1859 create_option = "FromImage" 1860 disk_size_gb = "45" 1861 } 1862 1863 os_profile { 1864 computer_name = "hostname%d" 1865 admin_username = "testadmin" 1866 admin_password = "Password1234!" 1867 } 1868 1869 os_profile_linux_config { 1870 disable_password_authentication = false 1871 } 1872 1873 tags { 1874 environment = "Production" 1875 cost-center = "Ops" 1876 } 1877 } 1878 ` 1879 1880 var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter = ` 1881 resource "azurerm_resource_group" "test" { 1882 name = "acctestRG-%d" 1883 location = "West US" 1884 } 1885 1886 resource "azurerm_virtual_network" "test" { 1887 name = "acctvn-%d" 1888 address_space = ["10.0.0.0/16"] 1889 location = "West US" 1890 resource_group_name = "${azurerm_resource_group.test.name}" 1891 } 1892 1893 resource "azurerm_subnet" "test" { 1894 name = "acctsub-%d" 1895 resource_group_name = "${azurerm_resource_group.test.name}" 1896 virtual_network_name = "${azurerm_virtual_network.test.name}" 1897 address_prefix = "10.0.2.0/24" 1898 } 1899 1900 resource "azurerm_network_interface" "test" { 1901 name = "acctni-%d" 1902 location = "West US" 1903 resource_group_name = "${azurerm_resource_group.test.name}" 1904 1905 ip_configuration { 1906 name = "testconfiguration1" 1907 subnet_id = "${azurerm_subnet.test.id}" 1908 private_ip_address_allocation = "dynamic" 1909 } 1910 } 1911 1912 resource "azurerm_storage_account" "test" { 1913 name = "accsa%d" 1914 resource_group_name = "${azurerm_resource_group.test.name}" 1915 location = "westus" 1916 account_type = "Standard_LRS" 1917 1918 tags { 1919 environment = "staging" 1920 } 1921 } 1922 1923 resource "azurerm_storage_container" "test" { 1924 name = "vhds" 1925 resource_group_name = "${azurerm_resource_group.test.name}" 1926 storage_account_name = "${azurerm_storage_account.test.name}" 1927 container_access_type = "private" 1928 } 1929 1930 resource "azurerm_virtual_machine" "test" { 1931 name = "acctvm-%d" 1932 location = "West US" 1933 resource_group_name = "${azurerm_resource_group.test.name}" 1934 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1935 vm_size = "Standard_A0" 1936 delete_os_disk_on_termination = true 1937 1938 storage_image_reference { 1939 publisher = "CoreOS" 1940 offer = "CoreOS" 1941 sku = "Stable" 1942 version = "latest" 1943 } 1944 1945 storage_os_disk { 1946 name = "myosdisk1" 1947 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1948 caching = "ReadWrite" 1949 create_option = "FromImage" 1950 disk_size_gb = "45" 1951 } 1952 1953 os_profile { 1954 computer_name = "hostname%d" 1955 admin_username = "testadmin" 1956 admin_password = "Password1234!" 1957 } 1958 1959 os_profile_linux_config { 1960 disable_password_authentication = false 1961 } 1962 1963 tags { 1964 environment = "Production" 1965 cost-center = "Ops" 1966 } 1967 } 1968 ` 1969 1970 var testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged = ` 1971 resource "azurerm_resource_group" "test" { 1972 name = "acctestRG-%d" 1973 location = "West US" 1974 } 1975 1976 resource "azurerm_virtual_network" "test" { 1977 name = "acctvn-%d" 1978 address_space = ["10.0.0.0/16"] 1979 location = "West US" 1980 resource_group_name = "${azurerm_resource_group.test.name}" 1981 } 1982 1983 resource "azurerm_subnet" "test" { 1984 name = "acctsub-%d" 1985 resource_group_name = "${azurerm_resource_group.test.name}" 1986 virtual_network_name = "${azurerm_virtual_network.test.name}" 1987 address_prefix = "10.0.2.0/24" 1988 } 1989 1990 resource "azurerm_network_interface" "test" { 1991 name = "acctni-%d" 1992 location = "West US" 1993 resource_group_name = "${azurerm_resource_group.test.name}" 1994 1995 ip_configuration { 1996 name = "testconfiguration1" 1997 subnet_id = "${azurerm_subnet.test.id}" 1998 private_ip_address_allocation = "dynamic" 1999 } 2000 } 2001 2002 resource "azurerm_storage_account" "test" { 2003 name = "accsa%d" 2004 resource_group_name = "${azurerm_resource_group.test.name}" 2005 location = "westus" 2006 account_type = "Standard_LRS" 2007 2008 tags { 2009 environment = "staging" 2010 } 2011 } 2012 2013 resource "azurerm_storage_container" "test" { 2014 name = "vhds" 2015 resource_group_name = "${azurerm_resource_group.test.name}" 2016 storage_account_name = "${azurerm_storage_account.test.name}" 2017 container_access_type = "private" 2018 } 2019 2020 resource "azurerm_virtual_machine" "test" { 2021 name = "acctvm-%d" 2022 location = "West US" 2023 resource_group_name = "${azurerm_resource_group.test.name}" 2024 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2025 vm_size = "Standard_A0" 2026 2027 storage_image_reference { 2028 publisher = "Canonical" 2029 offer = "UbuntuServer" 2030 sku = "14.04.2-LTS" 2031 version = "latest" 2032 } 2033 2034 storage_os_disk { 2035 name = "myosdisk1" 2036 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdiskchanged2.vhd" 2037 caching = "ReadWrite" 2038 create_option = "FromImage" 2039 disk_size_gb = "45" 2040 } 2041 2042 os_profile { 2043 computer_name = "hostname%d" 2044 admin_username = "testadmin" 2045 admin_password = "Password1234!" 2046 } 2047 2048 os_profile_linux_config { 2049 disable_password_authentication = false 2050 } 2051 2052 tags { 2053 environment = "Production" 2054 cost-center = "Ops" 2055 } 2056 } 2057 `