github.com/aspring/terraform@v0.8.2-0.20161216122603-6a8619a5db2e/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 lun = 0 1023 } 1024 1025 os_profile { 1026 computer_name = "hostname%d" 1027 admin_username = "testadmin" 1028 admin_password = "Password1234!" 1029 } 1030 1031 os_profile_linux_config { 1032 disable_password_authentication = false 1033 } 1034 1035 tags { 1036 environment = "Production" 1037 cost-center = "Ops" 1038 } 1039 } 1040 ` 1041 1042 var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = ` 1043 resource "azurerm_resource_group" "test" { 1044 name = "acctestRG-%d" 1045 location = "West US" 1046 } 1047 1048 resource "azurerm_virtual_network" "test" { 1049 name = "acctvn-%d" 1050 address_space = ["10.0.0.0/16"] 1051 location = "West US" 1052 resource_group_name = "${azurerm_resource_group.test.name}" 1053 } 1054 1055 resource "azurerm_subnet" "test" { 1056 name = "acctsub-%d" 1057 resource_group_name = "${azurerm_resource_group.test.name}" 1058 virtual_network_name = "${azurerm_virtual_network.test.name}" 1059 address_prefix = "10.0.2.0/24" 1060 } 1061 1062 resource "azurerm_network_interface" "test" { 1063 name = "acctni-%d" 1064 location = "West US" 1065 resource_group_name = "${azurerm_resource_group.test.name}" 1066 1067 ip_configuration { 1068 name = "testconfiguration1" 1069 subnet_id = "${azurerm_subnet.test.id}" 1070 private_ip_address_allocation = "dynamic" 1071 } 1072 } 1073 1074 resource "azurerm_storage_account" "test" { 1075 name = "accsa%d" 1076 resource_group_name = "${azurerm_resource_group.test.name}" 1077 location = "westus" 1078 account_type = "Standard_LRS" 1079 1080 tags { 1081 environment = "staging" 1082 } 1083 } 1084 1085 resource "azurerm_storage_container" "test" { 1086 name = "vhds" 1087 resource_group_name = "${azurerm_resource_group.test.name}" 1088 storage_account_name = "${azurerm_storage_account.test.name}" 1089 container_access_type = "private" 1090 } 1091 1092 resource "azurerm_virtual_machine" "test" { 1093 name = "acctvm-%d" 1094 location = "West US" 1095 resource_group_name = "${azurerm_resource_group.test.name}" 1096 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1097 vm_size = "Standard_A0" 1098 1099 storage_image_reference { 1100 publisher = "Canonical" 1101 offer = "UbuntuServer" 1102 sku = "14.04.2-LTS" 1103 version = "latest" 1104 } 1105 1106 storage_os_disk { 1107 name = "myosdisk1" 1108 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1109 caching = "ReadWrite" 1110 create_option = "FromImage" 1111 } 1112 1113 os_profile { 1114 computer_name = "hostname%d" 1115 admin_username = "testadmin" 1116 admin_password = "Password1234!" 1117 } 1118 1119 os_profile_linux_config { 1120 disable_password_authentication = false 1121 } 1122 1123 tags { 1124 environment = "Production" 1125 } 1126 } 1127 ` 1128 1129 var testAccAzureRMVirtualMachine_updatedLinuxMachine = ` 1130 resource "azurerm_resource_group" "test" { 1131 name = "acctestRG-%d" 1132 location = "West US" 1133 } 1134 1135 resource "azurerm_virtual_network" "test" { 1136 name = "acctvn-%d" 1137 address_space = ["10.0.0.0/16"] 1138 location = "West US" 1139 resource_group_name = "${azurerm_resource_group.test.name}" 1140 } 1141 1142 resource "azurerm_subnet" "test" { 1143 name = "acctsub-%d" 1144 resource_group_name = "${azurerm_resource_group.test.name}" 1145 virtual_network_name = "${azurerm_virtual_network.test.name}" 1146 address_prefix = "10.0.2.0/24" 1147 } 1148 1149 resource "azurerm_network_interface" "test" { 1150 name = "acctni-%d" 1151 location = "West US" 1152 resource_group_name = "${azurerm_resource_group.test.name}" 1153 1154 ip_configuration { 1155 name = "testconfiguration1" 1156 subnet_id = "${azurerm_subnet.test.id}" 1157 private_ip_address_allocation = "dynamic" 1158 } 1159 } 1160 1161 resource "azurerm_storage_account" "test" { 1162 name = "accsa%d" 1163 resource_group_name = "${azurerm_resource_group.test.name}" 1164 location = "westus" 1165 account_type = "Standard_LRS" 1166 1167 tags { 1168 environment = "staging" 1169 } 1170 } 1171 1172 resource "azurerm_storage_container" "test" { 1173 name = "vhds" 1174 resource_group_name = "${azurerm_resource_group.test.name}" 1175 storage_account_name = "${azurerm_storage_account.test.name}" 1176 container_access_type = "private" 1177 } 1178 1179 resource "azurerm_virtual_machine" "test" { 1180 name = "acctvm-%d" 1181 location = "West US" 1182 resource_group_name = "${azurerm_resource_group.test.name}" 1183 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1184 vm_size = "Standard_A1" 1185 1186 storage_image_reference { 1187 publisher = "Canonical" 1188 offer = "UbuntuServer" 1189 sku = "14.04.2-LTS" 1190 version = "latest" 1191 } 1192 1193 storage_os_disk { 1194 name = "myosdisk1" 1195 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1196 caching = "ReadWrite" 1197 create_option = "FromImage" 1198 } 1199 1200 os_profile { 1201 computer_name = "hostname%d" 1202 admin_username = "testadmin" 1203 admin_password = "Password1234!" 1204 } 1205 1206 os_profile_linux_config { 1207 disable_password_authentication = false 1208 } 1209 } 1210 ` 1211 1212 var testAccAzureRMVirtualMachine_basicWindowsMachine = ` 1213 resource "azurerm_resource_group" "test" { 1214 name = "acctestRG-%d" 1215 location = "West US" 1216 } 1217 1218 resource "azurerm_virtual_network" "test" { 1219 name = "acctvn-%d" 1220 address_space = ["10.0.0.0/16"] 1221 location = "West US" 1222 resource_group_name = "${azurerm_resource_group.test.name}" 1223 } 1224 1225 resource "azurerm_subnet" "test" { 1226 name = "acctsub-%d" 1227 resource_group_name = "${azurerm_resource_group.test.name}" 1228 virtual_network_name = "${azurerm_virtual_network.test.name}" 1229 address_prefix = "10.0.2.0/24" 1230 } 1231 1232 resource "azurerm_network_interface" "test" { 1233 name = "acctni-%d" 1234 location = "West US" 1235 resource_group_name = "${azurerm_resource_group.test.name}" 1236 1237 ip_configuration { 1238 name = "testconfiguration1" 1239 subnet_id = "${azurerm_subnet.test.id}" 1240 private_ip_address_allocation = "dynamic" 1241 } 1242 } 1243 1244 resource "azurerm_storage_account" "test" { 1245 name = "accsa%d" 1246 resource_group_name = "${azurerm_resource_group.test.name}" 1247 location = "westus" 1248 account_type = "Standard_LRS" 1249 1250 tags { 1251 environment = "staging" 1252 } 1253 } 1254 1255 resource "azurerm_storage_container" "test" { 1256 name = "vhds" 1257 resource_group_name = "${azurerm_resource_group.test.name}" 1258 storage_account_name = "${azurerm_storage_account.test.name}" 1259 container_access_type = "private" 1260 } 1261 1262 resource "azurerm_virtual_machine" "test" { 1263 name = "acctvm-%d" 1264 location = "West US" 1265 resource_group_name = "${azurerm_resource_group.test.name}" 1266 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1267 vm_size = "Standard_A0" 1268 1269 storage_image_reference { 1270 publisher = "MicrosoftWindowsServer" 1271 offer = "WindowsServer" 1272 sku = "2012-Datacenter" 1273 version = "latest" 1274 } 1275 1276 storage_os_disk { 1277 name = "myosdisk1" 1278 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1279 caching = "ReadWrite" 1280 create_option = "FromImage" 1281 } 1282 1283 os_profile { 1284 computer_name = "winhost01" 1285 admin_username = "testadmin" 1286 admin_password = "Password1234!" 1287 } 1288 1289 os_profile_windows_config { 1290 enable_automatic_upgrades = false 1291 provision_vm_agent = true 1292 } 1293 } 1294 ` 1295 1296 var testAccAzureRMVirtualMachine_windowsUnattendedConfig = ` 1297 resource "azurerm_resource_group" "test" { 1298 name = "acctestRG-%d" 1299 location = "West US" 1300 } 1301 1302 resource "azurerm_virtual_network" "test" { 1303 name = "acctvn-%d" 1304 address_space = ["10.0.0.0/16"] 1305 location = "West US" 1306 resource_group_name = "${azurerm_resource_group.test.name}" 1307 } 1308 1309 resource "azurerm_subnet" "test" { 1310 name = "acctsub-%d" 1311 resource_group_name = "${azurerm_resource_group.test.name}" 1312 virtual_network_name = "${azurerm_virtual_network.test.name}" 1313 address_prefix = "10.0.2.0/24" 1314 } 1315 1316 resource "azurerm_network_interface" "test" { 1317 name = "acctni-%d" 1318 location = "West US" 1319 resource_group_name = "${azurerm_resource_group.test.name}" 1320 1321 ip_configuration { 1322 name = "testconfiguration1" 1323 subnet_id = "${azurerm_subnet.test.id}" 1324 private_ip_address_allocation = "dynamic" 1325 } 1326 } 1327 1328 resource "azurerm_storage_account" "test" { 1329 name = "accsa%d" 1330 resource_group_name = "${azurerm_resource_group.test.name}" 1331 location = "westus" 1332 account_type = "Standard_LRS" 1333 1334 tags { 1335 environment = "staging" 1336 } 1337 } 1338 1339 resource "azurerm_storage_container" "test" { 1340 name = "vhds" 1341 resource_group_name = "${azurerm_resource_group.test.name}" 1342 storage_account_name = "${azurerm_storage_account.test.name}" 1343 container_access_type = "private" 1344 } 1345 1346 resource "azurerm_virtual_machine" "test" { 1347 name = "acctvm-%d" 1348 location = "West US" 1349 resource_group_name = "${azurerm_resource_group.test.name}" 1350 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1351 vm_size = "Standard_A0" 1352 1353 storage_image_reference { 1354 publisher = "MicrosoftWindowsServer" 1355 offer = "WindowsServer" 1356 sku = "2012-Datacenter" 1357 version = "latest" 1358 } 1359 1360 storage_os_disk { 1361 name = "myosdisk1" 1362 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1363 caching = "ReadWrite" 1364 create_option = "FromImage" 1365 } 1366 1367 os_profile { 1368 computer_name = "winhost01" 1369 admin_username = "testadmin" 1370 admin_password = "Password1234!" 1371 } 1372 1373 os_profile_windows_config { 1374 provision_vm_agent = true 1375 additional_unattend_config { 1376 pass = "oobeSystem" 1377 component = "Microsoft-Windows-Shell-Setup" 1378 setting_name = "FirstLogonCommands" 1379 content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>" 1380 } 1381 } 1382 1383 } 1384 ` 1385 1386 var testAccAzureRMVirtualMachine_diagnosticsProfile = ` 1387 resource "azurerm_resource_group" "test" { 1388 name = "acctestRG-%d" 1389 location = "West US" 1390 } 1391 1392 resource "azurerm_virtual_network" "test" { 1393 name = "acctvn-%d" 1394 address_space = ["10.0.0.0/16"] 1395 location = "West US" 1396 resource_group_name = "${azurerm_resource_group.test.name}" 1397 } 1398 1399 resource "azurerm_subnet" "test" { 1400 name = "acctsub-%d" 1401 resource_group_name = "${azurerm_resource_group.test.name}" 1402 virtual_network_name = "${azurerm_virtual_network.test.name}" 1403 address_prefix = "10.0.2.0/24" 1404 } 1405 1406 resource "azurerm_network_interface" "test" { 1407 name = "acctni-%d" 1408 location = "West US" 1409 resource_group_name = "${azurerm_resource_group.test.name}" 1410 1411 ip_configuration { 1412 name = "testconfiguration1" 1413 subnet_id = "${azurerm_subnet.test.id}" 1414 private_ip_address_allocation = "dynamic" 1415 } 1416 } 1417 1418 resource "azurerm_storage_account" "test" { 1419 name = "accsa%d" 1420 resource_group_name = "${azurerm_resource_group.test.name}" 1421 location = "westus" 1422 account_type = "Standard_LRS" 1423 1424 tags { 1425 environment = "staging" 1426 } 1427 } 1428 1429 resource "azurerm_storage_container" "test" { 1430 name = "vhds" 1431 resource_group_name = "${azurerm_resource_group.test.name}" 1432 storage_account_name = "${azurerm_storage_account.test.name}" 1433 container_access_type = "private" 1434 } 1435 1436 resource "azurerm_virtual_machine" "test" { 1437 name = "acctvm-%d" 1438 location = "West US" 1439 resource_group_name = "${azurerm_resource_group.test.name}" 1440 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1441 vm_size = "Standard_A0" 1442 1443 storage_image_reference { 1444 publisher = "MicrosoftWindowsServer" 1445 offer = "WindowsServer" 1446 sku = "2012-Datacenter" 1447 version = "latest" 1448 } 1449 1450 storage_os_disk { 1451 name = "myosdisk1" 1452 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1453 caching = "ReadWrite" 1454 create_option = "FromImage" 1455 } 1456 1457 os_profile { 1458 computer_name = "winhost01" 1459 admin_username = "testadmin" 1460 admin_password = "Password1234!" 1461 } 1462 1463 boot_diagnostics { 1464 enabled = true 1465 storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" 1466 } 1467 1468 os_profile_windows_config { 1469 winrm { 1470 protocol = "http" 1471 } 1472 } 1473 } 1474 1475 ` 1476 1477 var testAccAzureRMVirtualMachine_winRMConfig = ` 1478 resource "azurerm_resource_group" "test" { 1479 name = "acctestRG-%d" 1480 location = "West US" 1481 } 1482 1483 resource "azurerm_virtual_network" "test" { 1484 name = "acctvn-%d" 1485 address_space = ["10.0.0.0/16"] 1486 location = "West US" 1487 resource_group_name = "${azurerm_resource_group.test.name}" 1488 } 1489 1490 resource "azurerm_subnet" "test" { 1491 name = "acctsub-%d" 1492 resource_group_name = "${azurerm_resource_group.test.name}" 1493 virtual_network_name = "${azurerm_virtual_network.test.name}" 1494 address_prefix = "10.0.2.0/24" 1495 } 1496 1497 resource "azurerm_network_interface" "test" { 1498 name = "acctni-%d" 1499 location = "West US" 1500 resource_group_name = "${azurerm_resource_group.test.name}" 1501 1502 ip_configuration { 1503 name = "testconfiguration1" 1504 subnet_id = "${azurerm_subnet.test.id}" 1505 private_ip_address_allocation = "dynamic" 1506 } 1507 } 1508 1509 resource "azurerm_storage_account" "test" { 1510 name = "accsa%d" 1511 resource_group_name = "${azurerm_resource_group.test.name}" 1512 location = "westus" 1513 account_type = "Standard_LRS" 1514 1515 tags { 1516 environment = "staging" 1517 } 1518 } 1519 1520 resource "azurerm_storage_container" "test" { 1521 name = "vhds" 1522 resource_group_name = "${azurerm_resource_group.test.name}" 1523 storage_account_name = "${azurerm_storage_account.test.name}" 1524 container_access_type = "private" 1525 } 1526 1527 resource "azurerm_virtual_machine" "test" { 1528 name = "acctvm-%d" 1529 location = "West US" 1530 resource_group_name = "${azurerm_resource_group.test.name}" 1531 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1532 vm_size = "Standard_A0" 1533 1534 storage_image_reference { 1535 publisher = "MicrosoftWindowsServer" 1536 offer = "WindowsServer" 1537 sku = "2012-Datacenter" 1538 version = "latest" 1539 } 1540 1541 storage_os_disk { 1542 name = "myosdisk1" 1543 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1544 caching = "ReadWrite" 1545 create_option = "FromImage" 1546 } 1547 1548 os_profile { 1549 computer_name = "winhost01" 1550 admin_username = "testadmin" 1551 admin_password = "Password1234!" 1552 } 1553 1554 os_profile_windows_config { 1555 winrm { 1556 protocol = "http" 1557 } 1558 } 1559 } 1560 ` 1561 1562 var testAccAzureRMVirtualMachine_withAvailabilitySet = ` 1563 resource "azurerm_resource_group" "test" { 1564 name = "acctestRG-%d" 1565 location = "West US" 1566 } 1567 1568 resource "azurerm_virtual_network" "test" { 1569 name = "acctvn-%d" 1570 address_space = ["10.0.0.0/16"] 1571 location = "West US" 1572 resource_group_name = "${azurerm_resource_group.test.name}" 1573 } 1574 1575 resource "azurerm_subnet" "test" { 1576 name = "acctsub-%d" 1577 resource_group_name = "${azurerm_resource_group.test.name}" 1578 virtual_network_name = "${azurerm_virtual_network.test.name}" 1579 address_prefix = "10.0.2.0/24" 1580 } 1581 1582 resource "azurerm_network_interface" "test" { 1583 name = "acctni-%d" 1584 location = "West US" 1585 resource_group_name = "${azurerm_resource_group.test.name}" 1586 1587 ip_configuration { 1588 name = "testconfiguration1" 1589 subnet_id = "${azurerm_subnet.test.id}" 1590 private_ip_address_allocation = "dynamic" 1591 } 1592 } 1593 1594 resource "azurerm_storage_account" "test" { 1595 name = "accsa%d" 1596 resource_group_name = "${azurerm_resource_group.test.name}" 1597 location = "westus" 1598 account_type = "Standard_LRS" 1599 1600 tags { 1601 environment = "staging" 1602 } 1603 } 1604 1605 resource "azurerm_availability_set" "test" { 1606 name = "availabilityset%d" 1607 location = "West US" 1608 resource_group_name = "${azurerm_resource_group.test.name}" 1609 } 1610 1611 resource "azurerm_storage_container" "test" { 1612 name = "vhds" 1613 resource_group_name = "${azurerm_resource_group.test.name}" 1614 storage_account_name = "${azurerm_storage_account.test.name}" 1615 container_access_type = "private" 1616 } 1617 1618 resource "azurerm_virtual_machine" "test" { 1619 name = "acctvm-%d" 1620 location = "West US" 1621 resource_group_name = "${azurerm_resource_group.test.name}" 1622 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1623 vm_size = "Standard_A0" 1624 availability_set_id = "${azurerm_availability_set.test.id}" 1625 delete_os_disk_on_termination = true 1626 1627 storage_image_reference { 1628 publisher = "Canonical" 1629 offer = "UbuntuServer" 1630 sku = "14.04.2-LTS" 1631 version = "latest" 1632 } 1633 1634 storage_os_disk { 1635 name = "myosdisk1" 1636 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1637 caching = "ReadWrite" 1638 create_option = "FromImage" 1639 } 1640 1641 os_profile { 1642 computer_name = "hostname%d" 1643 admin_username = "testadmin" 1644 admin_password = "Password1234!" 1645 } 1646 1647 os_profile_linux_config { 1648 disable_password_authentication = false 1649 } 1650 } 1651 ` 1652 1653 var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` 1654 resource "azurerm_resource_group" "test" { 1655 name = "acctestRG-%d" 1656 location = "West US" 1657 } 1658 1659 resource "azurerm_virtual_network" "test" { 1660 name = "acctvn-%d" 1661 address_space = ["10.0.0.0/16"] 1662 location = "West US" 1663 resource_group_name = "${azurerm_resource_group.test.name}" 1664 } 1665 1666 resource "azurerm_subnet" "test" { 1667 name = "acctsub-%d" 1668 resource_group_name = "${azurerm_resource_group.test.name}" 1669 virtual_network_name = "${azurerm_virtual_network.test.name}" 1670 address_prefix = "10.0.2.0/24" 1671 } 1672 1673 resource "azurerm_network_interface" "test" { 1674 name = "acctni-%d" 1675 location = "West US" 1676 resource_group_name = "${azurerm_resource_group.test.name}" 1677 1678 ip_configuration { 1679 name = "testconfiguration1" 1680 subnet_id = "${azurerm_subnet.test.id}" 1681 private_ip_address_allocation = "dynamic" 1682 } 1683 } 1684 1685 resource "azurerm_storage_account" "test" { 1686 name = "accsa%d" 1687 resource_group_name = "${azurerm_resource_group.test.name}" 1688 location = "westus" 1689 account_type = "Standard_LRS" 1690 1691 tags { 1692 environment = "staging" 1693 } 1694 } 1695 1696 resource "azurerm_availability_set" "test" { 1697 name = "updatedAvailabilitySet%d" 1698 location = "West US" 1699 resource_group_name = "${azurerm_resource_group.test.name}" 1700 } 1701 1702 resource "azurerm_storage_container" "test" { 1703 name = "vhds" 1704 resource_group_name = "${azurerm_resource_group.test.name}" 1705 storage_account_name = "${azurerm_storage_account.test.name}" 1706 container_access_type = "private" 1707 } 1708 1709 resource "azurerm_virtual_machine" "test" { 1710 name = "acctvm-%d" 1711 location = "West US" 1712 resource_group_name = "${azurerm_resource_group.test.name}" 1713 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1714 vm_size = "Standard_A0" 1715 availability_set_id = "${azurerm_availability_set.test.id}" 1716 delete_os_disk_on_termination = true 1717 1718 storage_image_reference { 1719 publisher = "Canonical" 1720 offer = "UbuntuServer" 1721 sku = "14.04.2-LTS" 1722 version = "latest" 1723 } 1724 1725 storage_os_disk { 1726 name = "myosdisk1" 1727 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1728 caching = "ReadWrite" 1729 create_option = "FromImage" 1730 } 1731 1732 os_profile { 1733 computer_name = "hostname%d" 1734 admin_username = "testadmin" 1735 admin_password = "Password1234!" 1736 } 1737 1738 os_profile_linux_config { 1739 disable_password_authentication = false 1740 } 1741 } 1742 ` 1743 1744 var testAccAzureRMVirtualMachine_updateMachineName = ` 1745 resource "azurerm_resource_group" "test" { 1746 name = "acctestRG-%d" 1747 location = "West US" 1748 } 1749 1750 resource "azurerm_virtual_network" "test" { 1751 name = "acctvn-%d" 1752 address_space = ["10.0.0.0/16"] 1753 location = "West US" 1754 resource_group_name = "${azurerm_resource_group.test.name}" 1755 } 1756 1757 resource "azurerm_subnet" "test" { 1758 name = "acctsub-%d" 1759 resource_group_name = "${azurerm_resource_group.test.name}" 1760 virtual_network_name = "${azurerm_virtual_network.test.name}" 1761 address_prefix = "10.0.2.0/24" 1762 } 1763 1764 resource "azurerm_network_interface" "test" { 1765 name = "acctni-%d" 1766 location = "West US" 1767 resource_group_name = "${azurerm_resource_group.test.name}" 1768 1769 ip_configuration { 1770 name = "testconfiguration1" 1771 subnet_id = "${azurerm_subnet.test.id}" 1772 private_ip_address_allocation = "dynamic" 1773 } 1774 } 1775 1776 resource "azurerm_storage_account" "test" { 1777 name = "accsa%d" 1778 resource_group_name = "${azurerm_resource_group.test.name}" 1779 location = "westus" 1780 account_type = "Standard_LRS" 1781 1782 tags { 1783 environment = "staging" 1784 } 1785 } 1786 1787 resource "azurerm_storage_container" "test" { 1788 name = "vhds" 1789 resource_group_name = "${azurerm_resource_group.test.name}" 1790 storage_account_name = "${azurerm_storage_account.test.name}" 1791 container_access_type = "private" 1792 } 1793 1794 resource "azurerm_virtual_machine" "test" { 1795 name = "acctvm-%d" 1796 location = "West US" 1797 resource_group_name = "${azurerm_resource_group.test.name}" 1798 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1799 vm_size = "Standard_A0" 1800 delete_os_disk_on_termination = true 1801 1802 storage_image_reference { 1803 publisher = "Canonical" 1804 offer = "UbuntuServer" 1805 sku = "14.04.2-LTS" 1806 version = "latest" 1807 } 1808 1809 storage_os_disk { 1810 name = "myosdisk1" 1811 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1812 caching = "ReadWrite" 1813 create_option = "FromImage" 1814 } 1815 1816 os_profile { 1817 computer_name = "newhostname%d" 1818 admin_username = "testadmin" 1819 admin_password = "Password1234!" 1820 } 1821 1822 os_profile_linux_config { 1823 disable_password_authentication = false 1824 } 1825 } 1826 ` 1827 1828 var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore = ` 1829 resource "azurerm_resource_group" "test" { 1830 name = "acctestRG-%d" 1831 location = "West US" 1832 } 1833 1834 resource "azurerm_virtual_network" "test" { 1835 name = "acctvn-%d" 1836 address_space = ["10.0.0.0/16"] 1837 location = "West US" 1838 resource_group_name = "${azurerm_resource_group.test.name}" 1839 } 1840 1841 resource "azurerm_subnet" "test" { 1842 name = "acctsub-%d" 1843 resource_group_name = "${azurerm_resource_group.test.name}" 1844 virtual_network_name = "${azurerm_virtual_network.test.name}" 1845 address_prefix = "10.0.2.0/24" 1846 } 1847 1848 resource "azurerm_network_interface" "test" { 1849 name = "acctni-%d" 1850 location = "West US" 1851 resource_group_name = "${azurerm_resource_group.test.name}" 1852 1853 ip_configuration { 1854 name = "testconfiguration1" 1855 subnet_id = "${azurerm_subnet.test.id}" 1856 private_ip_address_allocation = "dynamic" 1857 } 1858 } 1859 1860 resource "azurerm_storage_account" "test" { 1861 name = "accsa%d" 1862 resource_group_name = "${azurerm_resource_group.test.name}" 1863 location = "westus" 1864 account_type = "Standard_LRS" 1865 1866 tags { 1867 environment = "staging" 1868 } 1869 } 1870 1871 resource "azurerm_storage_container" "test" { 1872 name = "vhds" 1873 resource_group_name = "${azurerm_resource_group.test.name}" 1874 storage_account_name = "${azurerm_storage_account.test.name}" 1875 container_access_type = "private" 1876 } 1877 1878 resource "azurerm_virtual_machine" "test" { 1879 name = "acctvm-%d" 1880 location = "West US" 1881 resource_group_name = "${azurerm_resource_group.test.name}" 1882 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1883 vm_size = "Standard_A0" 1884 delete_os_disk_on_termination = true 1885 1886 storage_image_reference { 1887 publisher = "Canonical" 1888 offer = "UbuntuServer" 1889 sku = "14.04.2-LTS" 1890 version = "latest" 1891 } 1892 1893 storage_os_disk { 1894 name = "myosdisk1" 1895 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1896 caching = "ReadWrite" 1897 create_option = "FromImage" 1898 disk_size_gb = "45" 1899 } 1900 1901 os_profile { 1902 computer_name = "hostname%d" 1903 admin_username = "testadmin" 1904 admin_password = "Password1234!" 1905 } 1906 1907 os_profile_linux_config { 1908 disable_password_authentication = false 1909 } 1910 1911 tags { 1912 environment = "Production" 1913 cost-center = "Ops" 1914 } 1915 } 1916 ` 1917 1918 var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter = ` 1919 resource "azurerm_resource_group" "test" { 1920 name = "acctestRG-%d" 1921 location = "West US" 1922 } 1923 1924 resource "azurerm_virtual_network" "test" { 1925 name = "acctvn-%d" 1926 address_space = ["10.0.0.0/16"] 1927 location = "West US" 1928 resource_group_name = "${azurerm_resource_group.test.name}" 1929 } 1930 1931 resource "azurerm_subnet" "test" { 1932 name = "acctsub-%d" 1933 resource_group_name = "${azurerm_resource_group.test.name}" 1934 virtual_network_name = "${azurerm_virtual_network.test.name}" 1935 address_prefix = "10.0.2.0/24" 1936 } 1937 1938 resource "azurerm_network_interface" "test" { 1939 name = "acctni-%d" 1940 location = "West US" 1941 resource_group_name = "${azurerm_resource_group.test.name}" 1942 1943 ip_configuration { 1944 name = "testconfiguration1" 1945 subnet_id = "${azurerm_subnet.test.id}" 1946 private_ip_address_allocation = "dynamic" 1947 } 1948 } 1949 1950 resource "azurerm_storage_account" "test" { 1951 name = "accsa%d" 1952 resource_group_name = "${azurerm_resource_group.test.name}" 1953 location = "westus" 1954 account_type = "Standard_LRS" 1955 1956 tags { 1957 environment = "staging" 1958 } 1959 } 1960 1961 resource "azurerm_storage_container" "test" { 1962 name = "vhds" 1963 resource_group_name = "${azurerm_resource_group.test.name}" 1964 storage_account_name = "${azurerm_storage_account.test.name}" 1965 container_access_type = "private" 1966 } 1967 1968 resource "azurerm_virtual_machine" "test" { 1969 name = "acctvm-%d" 1970 location = "West US" 1971 resource_group_name = "${azurerm_resource_group.test.name}" 1972 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1973 vm_size = "Standard_A0" 1974 delete_os_disk_on_termination = true 1975 1976 storage_image_reference { 1977 publisher = "CoreOS" 1978 offer = "CoreOS" 1979 sku = "Stable" 1980 version = "latest" 1981 } 1982 1983 storage_os_disk { 1984 name = "myosdisk1" 1985 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1986 caching = "ReadWrite" 1987 create_option = "FromImage" 1988 disk_size_gb = "45" 1989 } 1990 1991 os_profile { 1992 computer_name = "hostname%d" 1993 admin_username = "testadmin" 1994 admin_password = "Password1234!" 1995 } 1996 1997 os_profile_linux_config { 1998 disable_password_authentication = false 1999 } 2000 2001 tags { 2002 environment = "Production" 2003 cost-center = "Ops" 2004 } 2005 } 2006 ` 2007 2008 var testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged = ` 2009 resource "azurerm_resource_group" "test" { 2010 name = "acctestRG-%d" 2011 location = "West US" 2012 } 2013 2014 resource "azurerm_virtual_network" "test" { 2015 name = "acctvn-%d" 2016 address_space = ["10.0.0.0/16"] 2017 location = "West US" 2018 resource_group_name = "${azurerm_resource_group.test.name}" 2019 } 2020 2021 resource "azurerm_subnet" "test" { 2022 name = "acctsub-%d" 2023 resource_group_name = "${azurerm_resource_group.test.name}" 2024 virtual_network_name = "${azurerm_virtual_network.test.name}" 2025 address_prefix = "10.0.2.0/24" 2026 } 2027 2028 resource "azurerm_network_interface" "test" { 2029 name = "acctni-%d" 2030 location = "West US" 2031 resource_group_name = "${azurerm_resource_group.test.name}" 2032 2033 ip_configuration { 2034 name = "testconfiguration1" 2035 subnet_id = "${azurerm_subnet.test.id}" 2036 private_ip_address_allocation = "dynamic" 2037 } 2038 } 2039 2040 resource "azurerm_storage_account" "test" { 2041 name = "accsa%d" 2042 resource_group_name = "${azurerm_resource_group.test.name}" 2043 location = "westus" 2044 account_type = "Standard_LRS" 2045 2046 tags { 2047 environment = "staging" 2048 } 2049 } 2050 2051 resource "azurerm_storage_container" "test" { 2052 name = "vhds" 2053 resource_group_name = "${azurerm_resource_group.test.name}" 2054 storage_account_name = "${azurerm_storage_account.test.name}" 2055 container_access_type = "private" 2056 } 2057 2058 resource "azurerm_virtual_machine" "test" { 2059 name = "acctvm-%d" 2060 location = "West US" 2061 resource_group_name = "${azurerm_resource_group.test.name}" 2062 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2063 vm_size = "Standard_A0" 2064 2065 storage_image_reference { 2066 publisher = "Canonical" 2067 offer = "UbuntuServer" 2068 sku = "14.04.2-LTS" 2069 version = "latest" 2070 } 2071 2072 storage_os_disk { 2073 name = "myosdisk1" 2074 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdiskchanged2.vhd" 2075 caching = "ReadWrite" 2076 create_option = "FromImage" 2077 disk_size_gb = "45" 2078 } 2079 2080 os_profile { 2081 computer_name = "hostname%d" 2082 admin_username = "testadmin" 2083 admin_password = "Password1234!" 2084 } 2085 2086 os_profile_linux_config { 2087 disable_password_authentication = false 2088 } 2089 2090 tags { 2091 environment = "Production" 2092 cost-center = "Ops" 2093 } 2094 } 2095 ` 2096 2097 var testAccAzureRMVirtualMachine_windowsLicenseType = ` 2098 resource "azurerm_resource_group" "test" { 2099 name = "acctestRG-%d" 2100 location = "West US" 2101 } 2102 2103 resource "azurerm_virtual_network" "test" { 2104 name = "acctvn-%d" 2105 address_space = ["10.0.0.0/16"] 2106 location = "West US" 2107 resource_group_name = "${azurerm_resource_group.test.name}" 2108 } 2109 2110 resource "azurerm_subnet" "test" { 2111 name = "acctsub-%d" 2112 resource_group_name = "${azurerm_resource_group.test.name}" 2113 virtual_network_name = "${azurerm_virtual_network.test.name}" 2114 address_prefix = "10.0.2.0/24" 2115 } 2116 2117 resource "azurerm_network_interface" "test" { 2118 name = "acctni-%d" 2119 location = "West US" 2120 resource_group_name = "${azurerm_resource_group.test.name}" 2121 2122 ip_configuration { 2123 name = "testconfiguration1" 2124 subnet_id = "${azurerm_subnet.test.id}" 2125 private_ip_address_allocation = "dynamic" 2126 } 2127 } 2128 2129 resource "azurerm_storage_account" "test" { 2130 name = "accsa%d" 2131 resource_group_name = "${azurerm_resource_group.test.name}" 2132 location = "westus" 2133 account_type = "Standard_LRS" 2134 2135 tags { 2136 environment = "staging" 2137 } 2138 } 2139 2140 resource "azurerm_storage_container" "test" { 2141 name = "vhds" 2142 resource_group_name = "${azurerm_resource_group.test.name}" 2143 storage_account_name = "${azurerm_storage_account.test.name}" 2144 container_access_type = "private" 2145 } 2146 2147 resource "azurerm_virtual_machine" "test" { 2148 name = "acctvm-%d" 2149 location = "West US" 2150 resource_group_name = "${azurerm_resource_group.test.name}" 2151 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2152 vm_size = "Standard_A0" 2153 license_type = "Windows_Server" 2154 2155 storage_image_reference { 2156 publisher = "MicrosoftWindowsServer" 2157 offer = "WindowsServer-HUB" 2158 sku = "2008-R2-SP1-HUB" 2159 version = "latest" 2160 } 2161 2162 storage_os_disk { 2163 name = "myosdisk1" 2164 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2165 caching = "ReadWrite" 2166 create_option = "FromImage" 2167 } 2168 2169 os_profile { 2170 computer_name = "winhost01" 2171 admin_username = "testadmin" 2172 admin_password = "Password1234!" 2173 } 2174 2175 os_profile_windows_config { 2176 enable_automatic_upgrades = false 2177 provision_vm_agent = true 2178 } 2179 } 2180 ` 2181 2182 var testAccAzureRMVirtualMachine_plan = ` 2183 resource "azurerm_resource_group" "test" { 2184 name = "acctestRG-%d" 2185 location = "West US" 2186 } 2187 2188 resource "azurerm_virtual_network" "test" { 2189 name = "acctvn-%d" 2190 address_space = ["10.0.0.0/16"] 2191 location = "West US" 2192 resource_group_name = "${azurerm_resource_group.test.name}" 2193 } 2194 2195 resource "azurerm_subnet" "test" { 2196 name = "acctsub-%d" 2197 resource_group_name = "${azurerm_resource_group.test.name}" 2198 virtual_network_name = "${azurerm_virtual_network.test.name}" 2199 address_prefix = "10.0.2.0/24" 2200 } 2201 2202 resource "azurerm_network_interface" "test" { 2203 name = "acctni-%d" 2204 location = "West US" 2205 resource_group_name = "${azurerm_resource_group.test.name}" 2206 2207 ip_configuration { 2208 name = "testconfiguration1" 2209 subnet_id = "${azurerm_subnet.test.id}" 2210 private_ip_address_allocation = "dynamic" 2211 } 2212 } 2213 2214 resource "azurerm_storage_account" "test" { 2215 name = "accsa%d" 2216 resource_group_name = "${azurerm_resource_group.test.name}" 2217 location = "westus" 2218 account_type = "Standard_LRS" 2219 2220 tags { 2221 environment = "staging" 2222 } 2223 } 2224 2225 resource "azurerm_storage_container" "test" { 2226 name = "vhds" 2227 resource_group_name = "${azurerm_resource_group.test.name}" 2228 storage_account_name = "${azurerm_storage_account.test.name}" 2229 container_access_type = "private" 2230 } 2231 2232 resource "azurerm_virtual_machine" "test" { 2233 name = "acctvm-%d" 2234 location = "West US" 2235 resource_group_name = "${azurerm_resource_group.test.name}" 2236 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2237 vm_size = "Standard_DS1_v2" 2238 2239 storage_image_reference { 2240 publisher = "kemptech" 2241 offer = "vlm-azure" 2242 sku = "freeloadmaster" 2243 version = "latest" 2244 } 2245 2246 storage_os_disk { 2247 name = "myosdisk1" 2248 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2249 caching = "ReadWrite" 2250 create_option = "FromImage" 2251 disk_size_gb = "45" 2252 } 2253 2254 os_profile { 2255 computer_name = "hostname%d" 2256 admin_username = "testadmin" 2257 admin_password = "Password1234!" 2258 } 2259 2260 os_profile_linux_config { 2261 disable_password_authentication = false 2262 } 2263 2264 plan { 2265 name = "freeloadmaster" 2266 publisher = "kemptech" 2267 product = "vlm-azure" 2268 } 2269 2270 tags { 2271 environment = "Production" 2272 cost-center = "Ops" 2273 } 2274 } 2275 `