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