github.com/dougneal/terraform@v0.6.15-0.20170330092735-b6a3840768a4/builtin/providers/azurerm/resource_arm_virtual_machine_test.go (about) 1 package azurerm 2 3 import ( 4 "fmt" 5 "net/http" 6 "strings" 7 "testing" 8 9 "github.com/Azure/azure-sdk-for-go/arm/compute" 10 "github.com/hashicorp/terraform/helper/acctest" 11 "github.com/hashicorp/terraform/helper/resource" 12 "github.com/hashicorp/terraform/terraform" 13 ) 14 15 func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { 16 var vm compute.VirtualMachine 17 ri := acctest.RandInt() 18 config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 19 resource.Test(t, resource.TestCase{ 20 PreCheck: func() { testAccPreCheck(t) }, 21 Providers: testAccProviders, 22 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 23 Steps: []resource.TestStep{ 24 { 25 Config: config, 26 Check: resource.ComposeTestCheckFunc( 27 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 28 ), 29 }, 30 }, 31 }) 32 } 33 34 func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) { 35 var vm compute.VirtualMachine 36 ri := acctest.RandInt() 37 config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 38 resource.Test(t, resource.TestCase{ 39 PreCheck: func() { testAccPreCheck(t) }, 40 Providers: testAccProviders, 41 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 42 Steps: []resource.TestStep{ 43 { 44 Config: config, 45 Check: resource.ComposeTestCheckFunc( 46 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 47 testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test", &vm), 48 ), 49 ExpectNonEmptyPlan: true, 50 }, 51 }, 52 }) 53 } 54 55 func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) { 56 var vm compute.VirtualMachine 57 58 ri := acctest.RandInt() 59 config := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri) 60 resource.Test(t, resource.TestCase{ 61 PreCheck: func() { testAccPreCheck(t) }, 62 Providers: testAccProviders, 63 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 64 Steps: []resource.TestStep{ 65 { 66 Config: config, 67 Check: resource.ComposeTestCheckFunc( 68 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 69 ), 70 }, 71 }, 72 }) 73 } 74 75 func TestAccAzureRMVirtualMachine_tags(t *testing.T) { 76 var vm compute.VirtualMachine 77 78 ri := acctest.RandInt() 79 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 80 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineUpdated, ri, ri, ri, ri, ri, ri, ri) 81 resource.Test(t, resource.TestCase{ 82 PreCheck: func() { testAccPreCheck(t) }, 83 Providers: testAccProviders, 84 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 85 Steps: []resource.TestStep{ 86 { 87 Config: preConfig, 88 Check: resource.ComposeTestCheckFunc( 89 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 90 resource.TestCheckResourceAttr( 91 "azurerm_virtual_machine.test", "tags.%", "2"), 92 resource.TestCheckResourceAttr( 93 "azurerm_virtual_machine.test", "tags.environment", "Production"), 94 resource.TestCheckResourceAttr( 95 "azurerm_virtual_machine.test", "tags.cost-center", "Ops"), 96 ), 97 }, 98 99 { 100 Config: postConfig, 101 Check: resource.ComposeTestCheckFunc( 102 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 103 resource.TestCheckResourceAttr( 104 "azurerm_virtual_machine.test", "tags.%", "1"), 105 resource.TestCheckResourceAttr( 106 "azurerm_virtual_machine.test", "tags.environment", "Production"), 107 ), 108 }, 109 }, 110 }) 111 } 112 113 //This is a regression test around https://github.com/hashicorp/terraform/issues/6517 114 //Because we use CreateOrUpdate, we were sending an empty password on update requests 115 func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { 116 var vm compute.VirtualMachine 117 118 ri := acctest.RandInt() 119 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 120 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updatedLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 121 resource.Test(t, resource.TestCase{ 122 PreCheck: func() { testAccPreCheck(t) }, 123 Providers: testAccProviders, 124 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 125 Steps: []resource.TestStep{ 126 { 127 Config: preConfig, 128 Check: resource.ComposeTestCheckFunc( 129 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 130 resource.TestCheckResourceAttr( 131 "azurerm_virtual_machine.test", "vm_size", "Standard_A0"), 132 ), 133 }, 134 { 135 Config: postConfig, 136 Check: resource.ComposeTestCheckFunc( 137 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 138 resource.TestCheckResourceAttr( 139 "azurerm_virtual_machine.test", "vm_size", "Standard_A1"), 140 ), 141 }, 142 }, 143 }) 144 } 145 146 func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { 147 var vm compute.VirtualMachine 148 ri := acctest.RandInt() 149 config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicWindowsMachine, ri, ri, ri, ri, ri, ri) 150 resource.Test(t, resource.TestCase{ 151 PreCheck: func() { testAccPreCheck(t) }, 152 Providers: testAccProviders, 153 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 154 Steps: []resource.TestStep{ 155 { 156 Config: config, 157 Check: resource.ComposeTestCheckFunc( 158 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 159 ), 160 }, 161 }, 162 }) 163 } 164 165 func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) { 166 var vm compute.VirtualMachine 167 ri := acctest.RandInt() 168 config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsUnattendedConfig, ri, ri, ri, ri, ri, ri) 169 resource.Test(t, resource.TestCase{ 170 PreCheck: func() { testAccPreCheck(t) }, 171 Providers: testAccProviders, 172 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 173 Steps: []resource.TestStep{ 174 { 175 Config: config, 176 Check: resource.ComposeTestCheckFunc( 177 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 178 ), 179 }, 180 }, 181 }) 182 } 183 184 func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) { 185 var vm compute.VirtualMachine 186 ri := acctest.RandInt() 187 config := fmt.Sprintf(testAccAzureRMVirtualMachine_diagnosticsProfile, ri, ri, ri, ri, ri, ri) 188 resource.Test(t, resource.TestCase{ 189 PreCheck: func() { testAccPreCheck(t) }, 190 Providers: testAccProviders, 191 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 192 Steps: []resource.TestStep{ 193 { 194 Config: config, 195 Check: resource.ComposeTestCheckFunc( 196 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 197 ), 198 }, 199 }, 200 }) 201 } 202 203 func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) { 204 var vm compute.VirtualMachine 205 ri := acctest.RandInt() 206 config := fmt.Sprintf(testAccAzureRMVirtualMachine_winRMConfig, ri, ri, ri, ri, ri, ri) 207 resource.Test(t, resource.TestCase{ 208 PreCheck: func() { testAccPreCheck(t) }, 209 Providers: testAccProviders, 210 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 211 Steps: []resource.TestStep{ 212 { 213 Config: config, 214 Check: resource.ComposeTestCheckFunc( 215 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 216 ), 217 }, 218 }, 219 }) 220 } 221 222 func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) { 223 var vm compute.VirtualMachine 224 ri := acctest.RandInt() 225 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withDataDisk, ri, ri, ri, ri, ri, ri, ri) 226 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM, ri, ri, ri, ri, ri) 227 resource.Test(t, resource.TestCase{ 228 PreCheck: func() { testAccPreCheck(t) }, 229 Providers: testAccProviders, 230 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 231 Steps: []resource.TestStep{ 232 { 233 Config: preConfig, 234 Check: resource.ComposeTestCheckFunc( 235 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 236 ), 237 }, 238 { 239 Config: postConfig, 240 Check: resource.ComposeTestCheckFunc( 241 testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", true), 242 testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", true), 243 ), 244 }, 245 }, 246 }) 247 } 248 249 func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) { 250 var vm compute.VirtualMachine 251 ri := acctest.RandInt() 252 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore, ri, ri, ri, ri, ri, ri, ri, ri) 253 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter, ri, ri, ri, ri, ri, ri) 254 resource.Test(t, resource.TestCase{ 255 PreCheck: func() { testAccPreCheck(t) }, 256 Providers: testAccProviders, 257 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 258 Steps: []resource.TestStep{ 259 { 260 Config: preConfig, 261 Check: resource.ComposeTestCheckFunc( 262 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 263 ), 264 }, 265 { 266 Config: postConfig, 267 Check: resource.ComposeTestCheckFunc( 268 testCheckAzureRMVirtualMachineVHDExistance("myosdisk1.vhd", false), 269 testCheckAzureRMVirtualMachineVHDExistance("mydatadisk1.vhd", false), 270 ), 271 }, 272 }, 273 }) 274 } 275 276 func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) { 277 var afterCreate, afterUpdate compute.VirtualMachine 278 279 ri := acctest.RandInt() 280 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_machineNameBeforeUpdate, ri, ri, ri, ri, ri, ri, ri) 281 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateMachineName, ri, ri, ri, ri, ri, ri, ri) 282 resource.Test(t, resource.TestCase{ 283 PreCheck: func() { testAccPreCheck(t) }, 284 Providers: testAccProviders, 285 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 286 Steps: []resource.TestStep{ 287 resource.TestStep{ 288 Config: preConfig, 289 Check: resource.ComposeTestCheckFunc( 290 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 291 ), 292 }, 293 294 resource.TestStep{ 295 Config: postConfig, 296 Check: resource.ComposeTestCheckFunc( 297 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 298 testAccCheckVirtualMachineRecreated( 299 t, &afterCreate, &afterUpdate), 300 ), 301 }, 302 }, 303 }) 304 } 305 306 func TestAccAzureRMVirtualMachine_ChangeAvailbilitySet(t *testing.T) { 307 var afterCreate, afterUpdate compute.VirtualMachine 308 309 ri := acctest.RandInt() 310 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_withAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri) 311 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_updateAvailabilitySet, ri, ri, ri, ri, ri, ri, ri, ri) 312 resource.Test(t, resource.TestCase{ 313 PreCheck: func() { testAccPreCheck(t) }, 314 Providers: testAccProviders, 315 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 316 Steps: []resource.TestStep{ 317 resource.TestStep{ 318 Config: preConfig, 319 Check: resource.ComposeTestCheckFunc( 320 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 321 ), 322 }, 323 324 resource.TestStep{ 325 Config: postConfig, 326 Check: resource.ComposeTestCheckFunc( 327 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 328 testAccCheckVirtualMachineRecreated( 329 t, &afterCreate, &afterUpdate), 330 ), 331 }, 332 }, 333 }) 334 } 335 336 func TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) { 337 var afterCreate, afterUpdate compute.VirtualMachine 338 339 ri := acctest.RandInt() 340 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore, ri, ri, ri, ri, ri, ri, ri) 341 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter, ri, ri, ri, ri, ri, ri, ri) 342 resource.Test(t, resource.TestCase{ 343 PreCheck: func() { testAccPreCheck(t) }, 344 Providers: testAccProviders, 345 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 346 Steps: []resource.TestStep{ 347 resource.TestStep{ 348 Config: preConfig, 349 Check: resource.ComposeTestCheckFunc( 350 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 351 ), 352 }, 353 354 resource.TestStep{ 355 Config: postConfig, 356 Check: resource.ComposeTestCheckFunc( 357 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 358 testAccCheckVirtualMachineRecreated( 359 t, &afterCreate, &afterUpdate), 360 ), 361 }, 362 }, 363 }) 364 } 365 366 func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) { 367 var afterCreate, afterUpdate compute.VirtualMachine 368 369 ri := acctest.RandInt() 370 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri) 371 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged, ri, ri, ri, ri, ri, ri, ri) 372 resource.Test(t, resource.TestCase{ 373 PreCheck: func() { testAccPreCheck(t) }, 374 Providers: testAccProviders, 375 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 376 Steps: []resource.TestStep{ 377 resource.TestStep{ 378 Config: preConfig, 379 Check: resource.ComposeTestCheckFunc( 380 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), 381 ), 382 }, 383 384 resource.TestStep{ 385 Config: postConfig, 386 Check: resource.ComposeTestCheckFunc( 387 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), 388 testAccCheckVirtualMachineRecreated( 389 t, &afterCreate, &afterUpdate), 390 ), 391 }, 392 }, 393 }) 394 } 395 396 func TestAccAzureRMVirtualMachine_plan(t *testing.T) { 397 var vm compute.VirtualMachine 398 ri := acctest.RandInt() 399 config := fmt.Sprintf(testAccAzureRMVirtualMachine_plan, ri, ri, ri, ri, ri, ri, ri) 400 resource.Test(t, resource.TestCase{ 401 PreCheck: func() { testAccPreCheck(t) }, 402 Providers: testAccProviders, 403 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 404 Steps: []resource.TestStep{ 405 { 406 Config: config, 407 Check: resource.ComposeTestCheckFunc( 408 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 409 ), 410 }, 411 }, 412 }) 413 } 414 415 func TestAccAzureRMVirtualMachine_changeSSHKey(t *testing.T) { 416 var vm compute.VirtualMachine 417 ri := strings.ToLower(acctest.RandString(10)) 418 preConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_linuxMachineWithSSH, ri, ri, ri, ri, ri, ri, ri) 419 postConfig := fmt.Sprintf(testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved, ri, ri, ri, ri, ri, ri, ri) 420 resource.Test(t, resource.TestCase{ 421 PreCheck: func() { testAccPreCheck(t) }, 422 Providers: testAccProviders, 423 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 424 Steps: []resource.TestStep{ 425 { 426 Config: preConfig, 427 Check: resource.ComposeTestCheckFunc( 428 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 429 ), 430 }, 431 { 432 Config: postConfig, 433 Check: resource.ComposeTestCheckFunc( 434 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 435 ), 436 }, 437 }, 438 }) 439 } 440 441 func testCheckAzureRMVirtualMachineExists(name string, vm *compute.VirtualMachine) resource.TestCheckFunc { 442 return func(s *terraform.State) error { 443 // Ensure we have enough information in state to look up in API 444 rs, ok := s.RootModule().Resources[name] 445 if !ok { 446 return fmt.Errorf("Not found: %s", name) 447 } 448 449 vmName := rs.Primary.Attributes["name"] 450 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 451 if !hasResourceGroup { 452 return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName) 453 } 454 455 conn := testAccProvider.Meta().(*ArmClient).vmClient 456 457 resp, err := conn.Get(resourceGroup, vmName, "") 458 if err != nil { 459 return fmt.Errorf("Bad: Get on vmClient: %s", err) 460 } 461 462 if resp.StatusCode == http.StatusNotFound { 463 return fmt.Errorf("Bad: VirtualMachine %q (resource group: %q) does not exist", vmName, resourceGroup) 464 } 465 466 *vm = resp 467 468 return nil 469 } 470 } 471 472 func testAccCheckVirtualMachineRecreated(t *testing.T, 473 before, after *compute.VirtualMachine) resource.TestCheckFunc { 474 return func(s *terraform.State) error { 475 if before.ID == after.ID { 476 t.Fatalf("Expected change of Virtual Machine IDs, but both were %v", before.ID) 477 } 478 return nil 479 } 480 } 481 482 func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error { 483 conn := testAccProvider.Meta().(*ArmClient).vmClient 484 485 for _, rs := range s.RootModule().Resources { 486 if rs.Type != "azurerm_virtual_machine" { 487 continue 488 } 489 490 name := rs.Primary.Attributes["name"] 491 resourceGroup := rs.Primary.Attributes["resource_group_name"] 492 493 resp, err := conn.Get(resourceGroup, name, "") 494 495 if err != nil { 496 return nil 497 } 498 499 if resp.StatusCode != http.StatusNotFound { 500 return fmt.Errorf("Virtual Machine still exists:\n%#v", resp.VirtualMachineProperties) 501 } 502 } 503 504 return nil 505 } 506 507 func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) resource.TestCheckFunc { 508 return func(s *terraform.State) error { 509 for _, rs := range s.RootModule().Resources { 510 if rs.Type != "azurerm_storage_container" { 511 continue 512 } 513 514 // fetch storage account and container name 515 resourceGroup := rs.Primary.Attributes["resource_group_name"] 516 storageAccountName := rs.Primary.Attributes["storage_account_name"] 517 containerName := rs.Primary.Attributes["name"] 518 storageClient, _, err := testAccProvider.Meta().(*ArmClient).getBlobStorageClientForStorageAccount(resourceGroup, storageAccountName) 519 if err != nil { 520 return fmt.Errorf("Error creating Blob storage client: %s", err) 521 } 522 523 exists, err := storageClient.BlobExists(containerName, name) 524 if err != nil { 525 return fmt.Errorf("Error checking if Disk VHD Blob exists: %s", err) 526 } 527 528 if exists && !shouldExist { 529 return fmt.Errorf("Disk VHD Blob still exists") 530 } else if !exists && shouldExist { 531 return fmt.Errorf("Disk VHD Blob should exist") 532 } 533 } 534 535 return nil 536 } 537 } 538 539 func testCheckAzureRMVirtualMachineDisappears(name string, vm *compute.VirtualMachine) resource.TestCheckFunc { 540 return func(s *terraform.State) error { 541 // Ensure we have enough information in state to look up in API 542 rs, ok := s.RootModule().Resources[name] 543 if !ok { 544 return fmt.Errorf("Not found: %s", name) 545 } 546 547 vmName := rs.Primary.Attributes["name"] 548 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 549 if !hasResourceGroup { 550 return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName) 551 } 552 553 conn := testAccProvider.Meta().(*ArmClient).vmClient 554 555 _, err := conn.Delete(resourceGroup, vmName, make(chan struct{})) 556 if err != nil { 557 return fmt.Errorf("Bad: Delete on vmClient: %s", err) 558 } 559 560 return nil 561 } 562 } 563 564 func TestAccAzureRMVirtualMachine_windowsLicenseType(t *testing.T) { 565 var vm compute.VirtualMachine 566 ri := acctest.RandInt() 567 config := fmt.Sprintf(testAccAzureRMVirtualMachine_windowsLicenseType, ri, ri, ri, ri, ri, ri) 568 resource.Test(t, resource.TestCase{ 569 PreCheck: func() { testAccPreCheck(t) }, 570 Providers: testAccProviders, 571 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 572 Steps: []resource.TestStep{ 573 { 574 Config: config, 575 Check: resource.ComposeTestCheckFunc( 576 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 577 ), 578 }, 579 }, 580 }) 581 } 582 583 func TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId(t *testing.T) { 584 var vm compute.VirtualMachine 585 ri := acctest.RandInt() 586 config := fmt.Sprintf(testAccAzureRMVirtualMachine_primaryNetworkInterfaceId, ri, ri, ri, ri, ri, ri, ri) 587 resource.Test(t, resource.TestCase{ 588 PreCheck: func() { testAccPreCheck(t) }, 589 Providers: testAccProviders, 590 CheckDestroy: testCheckAzureRMVirtualMachineDestroy, 591 Steps: []resource.TestStep{ 592 { 593 Config: config, 594 Check: resource.ComposeTestCheckFunc( 595 testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), 596 ), 597 }, 598 }, 599 }) 600 } 601 602 var testAccAzureRMVirtualMachine_basicLinuxMachine = ` 603 resource "azurerm_resource_group" "test" { 604 name = "acctestRG-%d" 605 location = "West US" 606 } 607 608 resource "azurerm_virtual_network" "test" { 609 name = "acctvn-%d" 610 address_space = ["10.0.0.0/16"] 611 location = "West US" 612 resource_group_name = "${azurerm_resource_group.test.name}" 613 } 614 615 resource "azurerm_subnet" "test" { 616 name = "acctsub-%d" 617 resource_group_name = "${azurerm_resource_group.test.name}" 618 virtual_network_name = "${azurerm_virtual_network.test.name}" 619 address_prefix = "10.0.2.0/24" 620 } 621 622 resource "azurerm_network_interface" "test" { 623 name = "acctni-%d" 624 location = "West US" 625 resource_group_name = "${azurerm_resource_group.test.name}" 626 627 ip_configuration { 628 name = "testconfiguration1" 629 subnet_id = "${azurerm_subnet.test.id}" 630 private_ip_address_allocation = "dynamic" 631 } 632 } 633 634 resource "azurerm_storage_account" "test" { 635 name = "accsa%d" 636 resource_group_name = "${azurerm_resource_group.test.name}" 637 location = "westus" 638 account_type = "Standard_LRS" 639 640 tags { 641 environment = "staging" 642 } 643 } 644 645 resource "azurerm_storage_container" "test" { 646 name = "vhds" 647 resource_group_name = "${azurerm_resource_group.test.name}" 648 storage_account_name = "${azurerm_storage_account.test.name}" 649 container_access_type = "private" 650 } 651 652 resource "azurerm_virtual_machine" "test" { 653 name = "acctvm-%d" 654 location = "West US" 655 resource_group_name = "${azurerm_resource_group.test.name}" 656 network_interface_ids = ["${azurerm_network_interface.test.id}"] 657 vm_size = "Standard_A0" 658 659 storage_image_reference { 660 publisher = "Canonical" 661 offer = "UbuntuServer" 662 sku = "14.04.2-LTS" 663 version = "latest" 664 } 665 666 storage_os_disk { 667 name = "myosdisk1" 668 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 669 caching = "ReadWrite" 670 create_option = "FromImage" 671 disk_size_gb = "45" 672 } 673 674 os_profile { 675 computer_name = "hostname%d" 676 admin_username = "testadmin" 677 admin_password = "Password1234!" 678 } 679 680 os_profile_linux_config { 681 disable_password_authentication = false 682 } 683 684 tags { 685 environment = "Production" 686 cost-center = "Ops" 687 } 688 } 689 ` 690 691 var testAccAzureRMVirtualMachine_machineNameBeforeUpdate = ` 692 resource "azurerm_resource_group" "test" { 693 name = "acctestRG-%d" 694 location = "West US" 695 } 696 697 resource "azurerm_virtual_network" "test" { 698 name = "acctvn-%d" 699 address_space = ["10.0.0.0/16"] 700 location = "West US" 701 resource_group_name = "${azurerm_resource_group.test.name}" 702 } 703 704 resource "azurerm_subnet" "test" { 705 name = "acctsub-%d" 706 resource_group_name = "${azurerm_resource_group.test.name}" 707 virtual_network_name = "${azurerm_virtual_network.test.name}" 708 address_prefix = "10.0.2.0/24" 709 } 710 711 resource "azurerm_network_interface" "test" { 712 name = "acctni-%d" 713 location = "West US" 714 resource_group_name = "${azurerm_resource_group.test.name}" 715 716 ip_configuration { 717 name = "testconfiguration1" 718 subnet_id = "${azurerm_subnet.test.id}" 719 private_ip_address_allocation = "dynamic" 720 } 721 } 722 723 resource "azurerm_storage_account" "test" { 724 name = "accsa%d" 725 resource_group_name = "${azurerm_resource_group.test.name}" 726 location = "westus" 727 account_type = "Standard_LRS" 728 729 tags { 730 environment = "staging" 731 } 732 } 733 734 resource "azurerm_storage_container" "test" { 735 name = "vhds" 736 resource_group_name = "${azurerm_resource_group.test.name}" 737 storage_account_name = "${azurerm_storage_account.test.name}" 738 container_access_type = "private" 739 } 740 741 resource "azurerm_virtual_machine" "test" { 742 name = "acctvm-%d" 743 location = "West US" 744 resource_group_name = "${azurerm_resource_group.test.name}" 745 network_interface_ids = ["${azurerm_network_interface.test.id}"] 746 vm_size = "Standard_A0" 747 delete_os_disk_on_termination = true 748 749 storage_image_reference { 750 publisher = "Canonical" 751 offer = "UbuntuServer" 752 sku = "14.04.2-LTS" 753 version = "latest" 754 } 755 756 storage_os_disk { 757 name = "myosdisk1" 758 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 759 caching = "ReadWrite" 760 create_option = "FromImage" 761 } 762 763 os_profile { 764 computer_name = "hostname%d" 765 admin_username = "testadmin" 766 admin_password = "Password1234!" 767 } 768 769 os_profile_linux_config { 770 disable_password_authentication = false 771 } 772 773 tags { 774 environment = "Production" 775 cost-center = "Ops" 776 } 777 } 778 ` 779 780 var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore = ` 781 resource "azurerm_resource_group" "test" { 782 name = "acctestRG-%d" 783 location = "West US" 784 } 785 786 resource "azurerm_resource_group" "test-sa" { 787 name = "acctestRG-sa-%d" 788 location = "West US" 789 } 790 791 resource "azurerm_virtual_network" "test" { 792 name = "acctvn-%d" 793 address_space = ["10.0.0.0/16"] 794 location = "West US" 795 resource_group_name = "${azurerm_resource_group.test.name}" 796 } 797 798 resource "azurerm_subnet" "test" { 799 name = "acctsub-%d" 800 resource_group_name = "${azurerm_resource_group.test.name}" 801 virtual_network_name = "${azurerm_virtual_network.test.name}" 802 address_prefix = "10.0.2.0/24" 803 } 804 805 resource "azurerm_network_interface" "test" { 806 name = "acctni-%d" 807 location = "West US" 808 resource_group_name = "${azurerm_resource_group.test.name}" 809 810 ip_configuration { 811 name = "testconfiguration1" 812 subnet_id = "${azurerm_subnet.test.id}" 813 private_ip_address_allocation = "dynamic" 814 } 815 } 816 817 resource "azurerm_storage_account" "test" { 818 name = "accsa%d" 819 resource_group_name = "${azurerm_resource_group.test-sa.name}" 820 location = "westus" 821 account_type = "Standard_LRS" 822 823 tags { 824 environment = "staging" 825 } 826 } 827 828 resource "azurerm_storage_container" "test" { 829 name = "vhds" 830 resource_group_name = "${azurerm_resource_group.test-sa.name}" 831 storage_account_name = "${azurerm_storage_account.test.name}" 832 container_access_type = "private" 833 } 834 835 resource "azurerm_virtual_machine" "test" { 836 name = "acctvm-%d" 837 location = "West US" 838 resource_group_name = "${azurerm_resource_group.test.name}" 839 network_interface_ids = ["${azurerm_network_interface.test.id}"] 840 vm_size = "Standard_A0" 841 842 storage_image_reference { 843 publisher = "Canonical" 844 offer = "UbuntuServer" 845 sku = "14.04.2-LTS" 846 version = "latest" 847 } 848 849 storage_os_disk { 850 name = "myosdisk1" 851 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 852 caching = "ReadWrite" 853 create_option = "FromImage" 854 } 855 856 delete_os_disk_on_termination = true 857 858 storage_data_disk { 859 name = "mydatadisk1" 860 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd" 861 disk_size_gb = "1023" 862 create_option = "Empty" 863 lun = 0 864 } 865 866 delete_data_disks_on_termination = true 867 868 os_profile { 869 computer_name = "hostname%d" 870 admin_username = "testadmin" 871 admin_password = "Password1234!" 872 } 873 874 os_profile_linux_config { 875 disable_password_authentication = false 876 } 877 878 tags { 879 environment = "Production" 880 cost-center = "Ops" 881 } 882 } 883 ` 884 885 var testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter = ` 886 resource "azurerm_resource_group" "test" { 887 name = "acctestRG-%d" 888 location = "West US" 889 } 890 891 resource "azurerm_resource_group" "test-sa" { 892 name = "acctestRG-sa-%d" 893 location = "West US" 894 } 895 896 resource "azurerm_virtual_network" "test" { 897 name = "acctvn-%d" 898 address_space = ["10.0.0.0/16"] 899 location = "West US" 900 resource_group_name = "${azurerm_resource_group.test.name}" 901 } 902 903 resource "azurerm_subnet" "test" { 904 name = "acctsub-%d" 905 resource_group_name = "${azurerm_resource_group.test.name}" 906 virtual_network_name = "${azurerm_virtual_network.test.name}" 907 address_prefix = "10.0.2.0/24" 908 } 909 910 resource "azurerm_network_interface" "test" { 911 name = "acctni-%d" 912 location = "West US" 913 resource_group_name = "${azurerm_resource_group.test.name}" 914 915 ip_configuration { 916 name = "testconfiguration1" 917 subnet_id = "${azurerm_subnet.test.id}" 918 private_ip_address_allocation = "dynamic" 919 } 920 } 921 922 resource "azurerm_storage_account" "test" { 923 name = "accsa%d" 924 resource_group_name = "${azurerm_resource_group.test-sa.name}" 925 location = "westus" 926 account_type = "Standard_LRS" 927 928 tags { 929 environment = "staging" 930 } 931 } 932 933 resource "azurerm_storage_container" "test" { 934 name = "vhds" 935 resource_group_name = "${azurerm_resource_group.test-sa.name}" 936 storage_account_name = "${azurerm_storage_account.test.name}" 937 container_access_type = "private" 938 } 939 ` 940 941 var testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM = ` 942 resource "azurerm_resource_group" "test" { 943 name = "acctestRG-%d" 944 location = "West US" 945 } 946 947 resource "azurerm_virtual_network" "test" { 948 name = "acctvn-%d" 949 address_space = ["10.0.0.0/16"] 950 location = "West US" 951 resource_group_name = "${azurerm_resource_group.test.name}" 952 } 953 954 resource "azurerm_subnet" "test" { 955 name = "acctsub-%d" 956 resource_group_name = "${azurerm_resource_group.test.name}" 957 virtual_network_name = "${azurerm_virtual_network.test.name}" 958 address_prefix = "10.0.2.0/24" 959 } 960 961 resource "azurerm_network_interface" "test" { 962 name = "acctni-%d" 963 location = "West US" 964 resource_group_name = "${azurerm_resource_group.test.name}" 965 966 ip_configuration { 967 name = "testconfiguration1" 968 subnet_id = "${azurerm_subnet.test.id}" 969 private_ip_address_allocation = "dynamic" 970 } 971 } 972 973 resource "azurerm_storage_account" "test" { 974 name = "accsa%d" 975 resource_group_name = "${azurerm_resource_group.test.name}" 976 location = "westus" 977 account_type = "Standard_LRS" 978 979 tags { 980 environment = "staging" 981 } 982 } 983 984 resource "azurerm_storage_container" "test" { 985 name = "vhds" 986 resource_group_name = "${azurerm_resource_group.test.name}" 987 storage_account_name = "${azurerm_storage_account.test.name}" 988 container_access_type = "private" 989 } 990 ` 991 992 var testAccAzureRMVirtualMachine_withDataDisk = ` 993 resource "azurerm_resource_group" "test" { 994 name = "acctestRG-%d" 995 location = "West US" 996 } 997 998 resource "azurerm_virtual_network" "test" { 999 name = "acctvn-%d" 1000 address_space = ["10.0.0.0/16"] 1001 location = "West US" 1002 resource_group_name = "${azurerm_resource_group.test.name}" 1003 } 1004 1005 resource "azurerm_subnet" "test" { 1006 name = "acctsub-%d" 1007 resource_group_name = "${azurerm_resource_group.test.name}" 1008 virtual_network_name = "${azurerm_virtual_network.test.name}" 1009 address_prefix = "10.0.2.0/24" 1010 } 1011 1012 resource "azurerm_network_interface" "test" { 1013 name = "acctni-%d" 1014 location = "West US" 1015 resource_group_name = "${azurerm_resource_group.test.name}" 1016 1017 ip_configuration { 1018 name = "testconfiguration1" 1019 subnet_id = "${azurerm_subnet.test.id}" 1020 private_ip_address_allocation = "dynamic" 1021 } 1022 } 1023 1024 resource "azurerm_storage_account" "test" { 1025 name = "accsa%d" 1026 resource_group_name = "${azurerm_resource_group.test.name}" 1027 location = "westus" 1028 account_type = "Standard_LRS" 1029 1030 tags { 1031 environment = "staging" 1032 } 1033 } 1034 1035 resource "azurerm_storage_container" "test" { 1036 name = "vhds" 1037 resource_group_name = "${azurerm_resource_group.test.name}" 1038 storage_account_name = "${azurerm_storage_account.test.name}" 1039 container_access_type = "private" 1040 } 1041 1042 resource "azurerm_virtual_machine" "test" { 1043 name = "acctvm-%d" 1044 location = "West US" 1045 resource_group_name = "${azurerm_resource_group.test.name}" 1046 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1047 vm_size = "Standard_A0" 1048 1049 storage_image_reference { 1050 publisher = "Canonical" 1051 offer = "UbuntuServer" 1052 sku = "14.04.2-LTS" 1053 version = "latest" 1054 } 1055 1056 storage_os_disk { 1057 name = "myosdisk1" 1058 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1059 caching = "ReadWrite" 1060 create_option = "FromImage" 1061 } 1062 1063 storage_data_disk { 1064 name = "mydatadisk1" 1065 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mydatadisk1.vhd" 1066 disk_size_gb = "1023" 1067 create_option = "Empty" 1068 caching = "ReadWrite" 1069 lun = 0 1070 } 1071 1072 os_profile { 1073 computer_name = "hostname%d" 1074 admin_username = "testadmin" 1075 admin_password = "Password1234!" 1076 } 1077 1078 os_profile_linux_config { 1079 disable_password_authentication = false 1080 } 1081 1082 tags { 1083 environment = "Production" 1084 cost-center = "Ops" 1085 } 1086 } 1087 ` 1088 1089 var testAccAzureRMVirtualMachine_basicLinuxMachineUpdated = ` 1090 resource "azurerm_resource_group" "test" { 1091 name = "acctestRG-%d" 1092 location = "West US" 1093 } 1094 1095 resource "azurerm_virtual_network" "test" { 1096 name = "acctvn-%d" 1097 address_space = ["10.0.0.0/16"] 1098 location = "West US" 1099 resource_group_name = "${azurerm_resource_group.test.name}" 1100 } 1101 1102 resource "azurerm_subnet" "test" { 1103 name = "acctsub-%d" 1104 resource_group_name = "${azurerm_resource_group.test.name}" 1105 virtual_network_name = "${azurerm_virtual_network.test.name}" 1106 address_prefix = "10.0.2.0/24" 1107 } 1108 1109 resource "azurerm_network_interface" "test" { 1110 name = "acctni-%d" 1111 location = "West US" 1112 resource_group_name = "${azurerm_resource_group.test.name}" 1113 1114 ip_configuration { 1115 name = "testconfiguration1" 1116 subnet_id = "${azurerm_subnet.test.id}" 1117 private_ip_address_allocation = "dynamic" 1118 } 1119 } 1120 1121 resource "azurerm_storage_account" "test" { 1122 name = "accsa%d" 1123 resource_group_name = "${azurerm_resource_group.test.name}" 1124 location = "westus" 1125 account_type = "Standard_LRS" 1126 1127 tags { 1128 environment = "staging" 1129 } 1130 } 1131 1132 resource "azurerm_storage_container" "test" { 1133 name = "vhds" 1134 resource_group_name = "${azurerm_resource_group.test.name}" 1135 storage_account_name = "${azurerm_storage_account.test.name}" 1136 container_access_type = "private" 1137 } 1138 1139 resource "azurerm_virtual_machine" "test" { 1140 name = "acctvm-%d" 1141 location = "West US" 1142 resource_group_name = "${azurerm_resource_group.test.name}" 1143 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1144 vm_size = "Standard_A0" 1145 1146 storage_image_reference { 1147 publisher = "Canonical" 1148 offer = "UbuntuServer" 1149 sku = "14.04.2-LTS" 1150 version = "latest" 1151 } 1152 1153 storage_os_disk { 1154 name = "myosdisk1" 1155 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1156 caching = "ReadWrite" 1157 create_option = "FromImage" 1158 } 1159 1160 os_profile { 1161 computer_name = "hostname%d" 1162 admin_username = "testadmin" 1163 admin_password = "Password1234!" 1164 } 1165 1166 os_profile_linux_config { 1167 disable_password_authentication = false 1168 } 1169 1170 tags { 1171 environment = "Production" 1172 } 1173 } 1174 ` 1175 1176 var testAccAzureRMVirtualMachine_updatedLinuxMachine = ` 1177 resource "azurerm_resource_group" "test" { 1178 name = "acctestRG-%d" 1179 location = "West US" 1180 } 1181 1182 resource "azurerm_virtual_network" "test" { 1183 name = "acctvn-%d" 1184 address_space = ["10.0.0.0/16"] 1185 location = "West US" 1186 resource_group_name = "${azurerm_resource_group.test.name}" 1187 } 1188 1189 resource "azurerm_subnet" "test" { 1190 name = "acctsub-%d" 1191 resource_group_name = "${azurerm_resource_group.test.name}" 1192 virtual_network_name = "${azurerm_virtual_network.test.name}" 1193 address_prefix = "10.0.2.0/24" 1194 } 1195 1196 resource "azurerm_network_interface" "test" { 1197 name = "acctni-%d" 1198 location = "West US" 1199 resource_group_name = "${azurerm_resource_group.test.name}" 1200 1201 ip_configuration { 1202 name = "testconfiguration1" 1203 subnet_id = "${azurerm_subnet.test.id}" 1204 private_ip_address_allocation = "dynamic" 1205 } 1206 } 1207 1208 resource "azurerm_storage_account" "test" { 1209 name = "accsa%d" 1210 resource_group_name = "${azurerm_resource_group.test.name}" 1211 location = "westus" 1212 account_type = "Standard_LRS" 1213 1214 tags { 1215 environment = "staging" 1216 } 1217 } 1218 1219 resource "azurerm_storage_container" "test" { 1220 name = "vhds" 1221 resource_group_name = "${azurerm_resource_group.test.name}" 1222 storage_account_name = "${azurerm_storage_account.test.name}" 1223 container_access_type = "private" 1224 } 1225 1226 resource "azurerm_virtual_machine" "test" { 1227 name = "acctvm-%d" 1228 location = "West US" 1229 resource_group_name = "${azurerm_resource_group.test.name}" 1230 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1231 vm_size = "Standard_A1" 1232 1233 storage_image_reference { 1234 publisher = "Canonical" 1235 offer = "UbuntuServer" 1236 sku = "14.04.2-LTS" 1237 version = "latest" 1238 } 1239 1240 storage_os_disk { 1241 name = "myosdisk1" 1242 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1243 caching = "ReadWrite" 1244 create_option = "FromImage" 1245 } 1246 1247 os_profile { 1248 computer_name = "hostname%d" 1249 admin_username = "testadmin" 1250 admin_password = "Password1234!" 1251 } 1252 1253 os_profile_linux_config { 1254 disable_password_authentication = false 1255 } 1256 } 1257 ` 1258 1259 var testAccAzureRMVirtualMachine_basicWindowsMachine = ` 1260 resource "azurerm_resource_group" "test" { 1261 name = "acctestRG-%d" 1262 location = "West US" 1263 } 1264 1265 resource "azurerm_virtual_network" "test" { 1266 name = "acctvn-%d" 1267 address_space = ["10.0.0.0/16"] 1268 location = "West US" 1269 resource_group_name = "${azurerm_resource_group.test.name}" 1270 } 1271 1272 resource "azurerm_subnet" "test" { 1273 name = "acctsub-%d" 1274 resource_group_name = "${azurerm_resource_group.test.name}" 1275 virtual_network_name = "${azurerm_virtual_network.test.name}" 1276 address_prefix = "10.0.2.0/24" 1277 } 1278 1279 resource "azurerm_network_interface" "test" { 1280 name = "acctni-%d" 1281 location = "West US" 1282 resource_group_name = "${azurerm_resource_group.test.name}" 1283 1284 ip_configuration { 1285 name = "testconfiguration1" 1286 subnet_id = "${azurerm_subnet.test.id}" 1287 private_ip_address_allocation = "dynamic" 1288 } 1289 } 1290 1291 resource "azurerm_storage_account" "test" { 1292 name = "accsa%d" 1293 resource_group_name = "${azurerm_resource_group.test.name}" 1294 location = "westus" 1295 account_type = "Standard_LRS" 1296 1297 tags { 1298 environment = "staging" 1299 } 1300 } 1301 1302 resource "azurerm_storage_container" "test" { 1303 name = "vhds" 1304 resource_group_name = "${azurerm_resource_group.test.name}" 1305 storage_account_name = "${azurerm_storage_account.test.name}" 1306 container_access_type = "private" 1307 } 1308 1309 resource "azurerm_virtual_machine" "test" { 1310 name = "acctvm-%d" 1311 location = "West US" 1312 resource_group_name = "${azurerm_resource_group.test.name}" 1313 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1314 vm_size = "Standard_A0" 1315 1316 storage_image_reference { 1317 publisher = "MicrosoftWindowsServer" 1318 offer = "WindowsServer" 1319 sku = "2012-Datacenter" 1320 version = "latest" 1321 } 1322 1323 storage_os_disk { 1324 name = "myosdisk1" 1325 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1326 caching = "ReadWrite" 1327 create_option = "FromImage" 1328 } 1329 1330 os_profile { 1331 computer_name = "winhost01" 1332 admin_username = "testadmin" 1333 admin_password = "Password1234!" 1334 } 1335 1336 os_profile_windows_config { 1337 enable_automatic_upgrades = false 1338 provision_vm_agent = true 1339 } 1340 } 1341 ` 1342 1343 var testAccAzureRMVirtualMachine_windowsUnattendedConfig = ` 1344 resource "azurerm_resource_group" "test" { 1345 name = "acctestRG-%d" 1346 location = "West US" 1347 } 1348 1349 resource "azurerm_virtual_network" "test" { 1350 name = "acctvn-%d" 1351 address_space = ["10.0.0.0/16"] 1352 location = "West US" 1353 resource_group_name = "${azurerm_resource_group.test.name}" 1354 } 1355 1356 resource "azurerm_subnet" "test" { 1357 name = "acctsub-%d" 1358 resource_group_name = "${azurerm_resource_group.test.name}" 1359 virtual_network_name = "${azurerm_virtual_network.test.name}" 1360 address_prefix = "10.0.2.0/24" 1361 } 1362 1363 resource "azurerm_network_interface" "test" { 1364 name = "acctni-%d" 1365 location = "West US" 1366 resource_group_name = "${azurerm_resource_group.test.name}" 1367 1368 ip_configuration { 1369 name = "testconfiguration1" 1370 subnet_id = "${azurerm_subnet.test.id}" 1371 private_ip_address_allocation = "dynamic" 1372 } 1373 } 1374 1375 resource "azurerm_storage_account" "test" { 1376 name = "accsa%d" 1377 resource_group_name = "${azurerm_resource_group.test.name}" 1378 location = "westus" 1379 account_type = "Standard_LRS" 1380 1381 tags { 1382 environment = "staging" 1383 } 1384 } 1385 1386 resource "azurerm_storage_container" "test" { 1387 name = "vhds" 1388 resource_group_name = "${azurerm_resource_group.test.name}" 1389 storage_account_name = "${azurerm_storage_account.test.name}" 1390 container_access_type = "private" 1391 } 1392 1393 resource "azurerm_virtual_machine" "test" { 1394 name = "acctvm-%d" 1395 location = "West US" 1396 resource_group_name = "${azurerm_resource_group.test.name}" 1397 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1398 vm_size = "Standard_A0" 1399 1400 storage_image_reference { 1401 publisher = "MicrosoftWindowsServer" 1402 offer = "WindowsServer" 1403 sku = "2012-Datacenter" 1404 version = "latest" 1405 } 1406 1407 storage_os_disk { 1408 name = "myosdisk1" 1409 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1410 caching = "ReadWrite" 1411 create_option = "FromImage" 1412 } 1413 1414 os_profile { 1415 computer_name = "winhost01" 1416 admin_username = "testadmin" 1417 admin_password = "Password1234!" 1418 } 1419 1420 os_profile_windows_config { 1421 provision_vm_agent = true 1422 additional_unattend_config { 1423 pass = "oobeSystem" 1424 component = "Microsoft-Windows-Shell-Setup" 1425 setting_name = "FirstLogonCommands" 1426 content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>" 1427 } 1428 } 1429 1430 } 1431 ` 1432 1433 var testAccAzureRMVirtualMachine_diagnosticsProfile = ` 1434 resource "azurerm_resource_group" "test" { 1435 name = "acctestRG-%d" 1436 location = "West US" 1437 } 1438 1439 resource "azurerm_virtual_network" "test" { 1440 name = "acctvn-%d" 1441 address_space = ["10.0.0.0/16"] 1442 location = "West US" 1443 resource_group_name = "${azurerm_resource_group.test.name}" 1444 } 1445 1446 resource "azurerm_subnet" "test" { 1447 name = "acctsub-%d" 1448 resource_group_name = "${azurerm_resource_group.test.name}" 1449 virtual_network_name = "${azurerm_virtual_network.test.name}" 1450 address_prefix = "10.0.2.0/24" 1451 } 1452 1453 resource "azurerm_network_interface" "test" { 1454 name = "acctni-%d" 1455 location = "West US" 1456 resource_group_name = "${azurerm_resource_group.test.name}" 1457 1458 ip_configuration { 1459 name = "testconfiguration1" 1460 subnet_id = "${azurerm_subnet.test.id}" 1461 private_ip_address_allocation = "dynamic" 1462 } 1463 } 1464 1465 resource "azurerm_storage_account" "test" { 1466 name = "accsa%d" 1467 resource_group_name = "${azurerm_resource_group.test.name}" 1468 location = "westus" 1469 account_type = "Standard_LRS" 1470 1471 tags { 1472 environment = "staging" 1473 } 1474 } 1475 1476 resource "azurerm_storage_container" "test" { 1477 name = "vhds" 1478 resource_group_name = "${azurerm_resource_group.test.name}" 1479 storage_account_name = "${azurerm_storage_account.test.name}" 1480 container_access_type = "private" 1481 } 1482 1483 resource "azurerm_virtual_machine" "test" { 1484 name = "acctvm-%d" 1485 location = "West US" 1486 resource_group_name = "${azurerm_resource_group.test.name}" 1487 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1488 vm_size = "Standard_A0" 1489 1490 storage_image_reference { 1491 publisher = "MicrosoftWindowsServer" 1492 offer = "WindowsServer" 1493 sku = "2012-Datacenter" 1494 version = "latest" 1495 } 1496 1497 storage_os_disk { 1498 name = "myosdisk1" 1499 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1500 caching = "ReadWrite" 1501 create_option = "FromImage" 1502 } 1503 1504 os_profile { 1505 computer_name = "winhost01" 1506 admin_username = "testadmin" 1507 admin_password = "Password1234!" 1508 } 1509 1510 boot_diagnostics { 1511 enabled = true 1512 storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" 1513 } 1514 1515 os_profile_windows_config { 1516 winrm { 1517 protocol = "http" 1518 } 1519 } 1520 } 1521 1522 ` 1523 1524 var testAccAzureRMVirtualMachine_winRMConfig = ` 1525 resource "azurerm_resource_group" "test" { 1526 name = "acctestRG-%d" 1527 location = "West US" 1528 } 1529 1530 resource "azurerm_virtual_network" "test" { 1531 name = "acctvn-%d" 1532 address_space = ["10.0.0.0/16"] 1533 location = "West US" 1534 resource_group_name = "${azurerm_resource_group.test.name}" 1535 } 1536 1537 resource "azurerm_subnet" "test" { 1538 name = "acctsub-%d" 1539 resource_group_name = "${azurerm_resource_group.test.name}" 1540 virtual_network_name = "${azurerm_virtual_network.test.name}" 1541 address_prefix = "10.0.2.0/24" 1542 } 1543 1544 resource "azurerm_network_interface" "test" { 1545 name = "acctni-%d" 1546 location = "West US" 1547 resource_group_name = "${azurerm_resource_group.test.name}" 1548 1549 ip_configuration { 1550 name = "testconfiguration1" 1551 subnet_id = "${azurerm_subnet.test.id}" 1552 private_ip_address_allocation = "dynamic" 1553 } 1554 } 1555 1556 resource "azurerm_storage_account" "test" { 1557 name = "accsa%d" 1558 resource_group_name = "${azurerm_resource_group.test.name}" 1559 location = "westus" 1560 account_type = "Standard_LRS" 1561 1562 tags { 1563 environment = "staging" 1564 } 1565 } 1566 1567 resource "azurerm_storage_container" "test" { 1568 name = "vhds" 1569 resource_group_name = "${azurerm_resource_group.test.name}" 1570 storage_account_name = "${azurerm_storage_account.test.name}" 1571 container_access_type = "private" 1572 } 1573 1574 resource "azurerm_virtual_machine" "test" { 1575 name = "acctvm-%d" 1576 location = "West US" 1577 resource_group_name = "${azurerm_resource_group.test.name}" 1578 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1579 vm_size = "Standard_A0" 1580 1581 storage_image_reference { 1582 publisher = "MicrosoftWindowsServer" 1583 offer = "WindowsServer" 1584 sku = "2012-Datacenter" 1585 version = "latest" 1586 } 1587 1588 storage_os_disk { 1589 name = "myosdisk1" 1590 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1591 caching = "ReadWrite" 1592 create_option = "FromImage" 1593 } 1594 1595 os_profile { 1596 computer_name = "winhost01" 1597 admin_username = "testadmin" 1598 admin_password = "Password1234!" 1599 } 1600 1601 os_profile_windows_config { 1602 winrm { 1603 protocol = "http" 1604 } 1605 } 1606 } 1607 ` 1608 1609 var testAccAzureRMVirtualMachine_withAvailabilitySet = ` 1610 resource "azurerm_resource_group" "test" { 1611 name = "acctestRG-%d" 1612 location = "West US" 1613 } 1614 1615 resource "azurerm_virtual_network" "test" { 1616 name = "acctvn-%d" 1617 address_space = ["10.0.0.0/16"] 1618 location = "West US" 1619 resource_group_name = "${azurerm_resource_group.test.name}" 1620 } 1621 1622 resource "azurerm_subnet" "test" { 1623 name = "acctsub-%d" 1624 resource_group_name = "${azurerm_resource_group.test.name}" 1625 virtual_network_name = "${azurerm_virtual_network.test.name}" 1626 address_prefix = "10.0.2.0/24" 1627 } 1628 1629 resource "azurerm_network_interface" "test" { 1630 name = "acctni-%d" 1631 location = "West US" 1632 resource_group_name = "${azurerm_resource_group.test.name}" 1633 1634 ip_configuration { 1635 name = "testconfiguration1" 1636 subnet_id = "${azurerm_subnet.test.id}" 1637 private_ip_address_allocation = "dynamic" 1638 } 1639 } 1640 1641 resource "azurerm_storage_account" "test" { 1642 name = "accsa%d" 1643 resource_group_name = "${azurerm_resource_group.test.name}" 1644 location = "westus" 1645 account_type = "Standard_LRS" 1646 1647 tags { 1648 environment = "staging" 1649 } 1650 } 1651 1652 resource "azurerm_availability_set" "test" { 1653 name = "availabilityset%d" 1654 location = "West US" 1655 resource_group_name = "${azurerm_resource_group.test.name}" 1656 } 1657 1658 resource "azurerm_storage_container" "test" { 1659 name = "vhds" 1660 resource_group_name = "${azurerm_resource_group.test.name}" 1661 storage_account_name = "${azurerm_storage_account.test.name}" 1662 container_access_type = "private" 1663 } 1664 1665 resource "azurerm_virtual_machine" "test" { 1666 name = "acctvm-%d" 1667 location = "West US" 1668 resource_group_name = "${azurerm_resource_group.test.name}" 1669 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1670 vm_size = "Standard_A0" 1671 availability_set_id = "${azurerm_availability_set.test.id}" 1672 delete_os_disk_on_termination = true 1673 1674 storage_image_reference { 1675 publisher = "Canonical" 1676 offer = "UbuntuServer" 1677 sku = "14.04.2-LTS" 1678 version = "latest" 1679 } 1680 1681 storage_os_disk { 1682 name = "myosdisk1" 1683 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1684 caching = "ReadWrite" 1685 create_option = "FromImage" 1686 } 1687 1688 os_profile { 1689 computer_name = "hostname%d" 1690 admin_username = "testadmin" 1691 admin_password = "Password1234!" 1692 } 1693 1694 os_profile_linux_config { 1695 disable_password_authentication = false 1696 } 1697 } 1698 ` 1699 1700 var testAccAzureRMVirtualMachine_updateAvailabilitySet = ` 1701 resource "azurerm_resource_group" "test" { 1702 name = "acctestRG-%d" 1703 location = "West US" 1704 } 1705 1706 resource "azurerm_virtual_network" "test" { 1707 name = "acctvn-%d" 1708 address_space = ["10.0.0.0/16"] 1709 location = "West US" 1710 resource_group_name = "${azurerm_resource_group.test.name}" 1711 } 1712 1713 resource "azurerm_subnet" "test" { 1714 name = "acctsub-%d" 1715 resource_group_name = "${azurerm_resource_group.test.name}" 1716 virtual_network_name = "${azurerm_virtual_network.test.name}" 1717 address_prefix = "10.0.2.0/24" 1718 } 1719 1720 resource "azurerm_network_interface" "test" { 1721 name = "acctni-%d" 1722 location = "West US" 1723 resource_group_name = "${azurerm_resource_group.test.name}" 1724 1725 ip_configuration { 1726 name = "testconfiguration1" 1727 subnet_id = "${azurerm_subnet.test.id}" 1728 private_ip_address_allocation = "dynamic" 1729 } 1730 } 1731 1732 resource "azurerm_storage_account" "test" { 1733 name = "accsa%d" 1734 resource_group_name = "${azurerm_resource_group.test.name}" 1735 location = "westus" 1736 account_type = "Standard_LRS" 1737 1738 tags { 1739 environment = "staging" 1740 } 1741 } 1742 1743 resource "azurerm_availability_set" "test" { 1744 name = "updatedAvailabilitySet%d" 1745 location = "West US" 1746 resource_group_name = "${azurerm_resource_group.test.name}" 1747 } 1748 1749 resource "azurerm_storage_container" "test" { 1750 name = "vhds" 1751 resource_group_name = "${azurerm_resource_group.test.name}" 1752 storage_account_name = "${azurerm_storage_account.test.name}" 1753 container_access_type = "private" 1754 } 1755 1756 resource "azurerm_virtual_machine" "test" { 1757 name = "acctvm-%d" 1758 location = "West US" 1759 resource_group_name = "${azurerm_resource_group.test.name}" 1760 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1761 vm_size = "Standard_A0" 1762 availability_set_id = "${azurerm_availability_set.test.id}" 1763 delete_os_disk_on_termination = true 1764 1765 storage_image_reference { 1766 publisher = "Canonical" 1767 offer = "UbuntuServer" 1768 sku = "14.04.2-LTS" 1769 version = "latest" 1770 } 1771 1772 storage_os_disk { 1773 name = "myosdisk1" 1774 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1775 caching = "ReadWrite" 1776 create_option = "FromImage" 1777 } 1778 1779 os_profile { 1780 computer_name = "hostname%d" 1781 admin_username = "testadmin" 1782 admin_password = "Password1234!" 1783 } 1784 1785 os_profile_linux_config { 1786 disable_password_authentication = false 1787 } 1788 } 1789 ` 1790 1791 var testAccAzureRMVirtualMachine_updateMachineName = ` 1792 resource "azurerm_resource_group" "test" { 1793 name = "acctestRG-%d" 1794 location = "West US" 1795 } 1796 1797 resource "azurerm_virtual_network" "test" { 1798 name = "acctvn-%d" 1799 address_space = ["10.0.0.0/16"] 1800 location = "West US" 1801 resource_group_name = "${azurerm_resource_group.test.name}" 1802 } 1803 1804 resource "azurerm_subnet" "test" { 1805 name = "acctsub-%d" 1806 resource_group_name = "${azurerm_resource_group.test.name}" 1807 virtual_network_name = "${azurerm_virtual_network.test.name}" 1808 address_prefix = "10.0.2.0/24" 1809 } 1810 1811 resource "azurerm_network_interface" "test" { 1812 name = "acctni-%d" 1813 location = "West US" 1814 resource_group_name = "${azurerm_resource_group.test.name}" 1815 1816 ip_configuration { 1817 name = "testconfiguration1" 1818 subnet_id = "${azurerm_subnet.test.id}" 1819 private_ip_address_allocation = "dynamic" 1820 } 1821 } 1822 1823 resource "azurerm_storage_account" "test" { 1824 name = "accsa%d" 1825 resource_group_name = "${azurerm_resource_group.test.name}" 1826 location = "westus" 1827 account_type = "Standard_LRS" 1828 1829 tags { 1830 environment = "staging" 1831 } 1832 } 1833 1834 resource "azurerm_storage_container" "test" { 1835 name = "vhds" 1836 resource_group_name = "${azurerm_resource_group.test.name}" 1837 storage_account_name = "${azurerm_storage_account.test.name}" 1838 container_access_type = "private" 1839 } 1840 1841 resource "azurerm_virtual_machine" "test" { 1842 name = "acctvm-%d" 1843 location = "West US" 1844 resource_group_name = "${azurerm_resource_group.test.name}" 1845 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1846 vm_size = "Standard_A0" 1847 delete_os_disk_on_termination = true 1848 1849 storage_image_reference { 1850 publisher = "Canonical" 1851 offer = "UbuntuServer" 1852 sku = "14.04.2-LTS" 1853 version = "latest" 1854 } 1855 1856 storage_os_disk { 1857 name = "myosdisk1" 1858 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1859 caching = "ReadWrite" 1860 create_option = "FromImage" 1861 } 1862 1863 os_profile { 1864 computer_name = "newhostname%d" 1865 admin_username = "testadmin" 1866 admin_password = "Password1234!" 1867 } 1868 1869 os_profile_linux_config { 1870 disable_password_authentication = false 1871 } 1872 } 1873 ` 1874 1875 var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore = ` 1876 resource "azurerm_resource_group" "test" { 1877 name = "acctestRG-%d" 1878 location = "West US" 1879 } 1880 1881 resource "azurerm_virtual_network" "test" { 1882 name = "acctvn-%d" 1883 address_space = ["10.0.0.0/16"] 1884 location = "West US" 1885 resource_group_name = "${azurerm_resource_group.test.name}" 1886 } 1887 1888 resource "azurerm_subnet" "test" { 1889 name = "acctsub-%d" 1890 resource_group_name = "${azurerm_resource_group.test.name}" 1891 virtual_network_name = "${azurerm_virtual_network.test.name}" 1892 address_prefix = "10.0.2.0/24" 1893 } 1894 1895 resource "azurerm_network_interface" "test" { 1896 name = "acctni-%d" 1897 location = "West US" 1898 resource_group_name = "${azurerm_resource_group.test.name}" 1899 1900 ip_configuration { 1901 name = "testconfiguration1" 1902 subnet_id = "${azurerm_subnet.test.id}" 1903 private_ip_address_allocation = "dynamic" 1904 } 1905 } 1906 1907 resource "azurerm_storage_account" "test" { 1908 name = "accsa%d" 1909 resource_group_name = "${azurerm_resource_group.test.name}" 1910 location = "westus" 1911 account_type = "Standard_LRS" 1912 1913 tags { 1914 environment = "staging" 1915 } 1916 } 1917 1918 resource "azurerm_storage_container" "test" { 1919 name = "vhds" 1920 resource_group_name = "${azurerm_resource_group.test.name}" 1921 storage_account_name = "${azurerm_storage_account.test.name}" 1922 container_access_type = "private" 1923 } 1924 1925 resource "azurerm_virtual_machine" "test" { 1926 name = "acctvm-%d" 1927 location = "West US" 1928 resource_group_name = "${azurerm_resource_group.test.name}" 1929 network_interface_ids = ["${azurerm_network_interface.test.id}"] 1930 vm_size = "Standard_A0" 1931 delete_os_disk_on_termination = true 1932 1933 storage_image_reference { 1934 publisher = "Canonical" 1935 offer = "UbuntuServer" 1936 sku = "14.04.2-LTS" 1937 version = "latest" 1938 } 1939 1940 storage_os_disk { 1941 name = "myosdisk1" 1942 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 1943 caching = "ReadWrite" 1944 create_option = "FromImage" 1945 disk_size_gb = "45" 1946 } 1947 1948 os_profile { 1949 computer_name = "hostname%d" 1950 admin_username = "testadmin" 1951 admin_password = "Password1234!" 1952 } 1953 1954 os_profile_linux_config { 1955 disable_password_authentication = false 1956 } 1957 1958 tags { 1959 environment = "Production" 1960 cost-center = "Ops" 1961 } 1962 } 1963 ` 1964 1965 var testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter = ` 1966 resource "azurerm_resource_group" "test" { 1967 name = "acctestRG-%d" 1968 location = "West US" 1969 } 1970 1971 resource "azurerm_virtual_network" "test" { 1972 name = "acctvn-%d" 1973 address_space = ["10.0.0.0/16"] 1974 location = "West US" 1975 resource_group_name = "${azurerm_resource_group.test.name}" 1976 } 1977 1978 resource "azurerm_subnet" "test" { 1979 name = "acctsub-%d" 1980 resource_group_name = "${azurerm_resource_group.test.name}" 1981 virtual_network_name = "${azurerm_virtual_network.test.name}" 1982 address_prefix = "10.0.2.0/24" 1983 } 1984 1985 resource "azurerm_network_interface" "test" { 1986 name = "acctni-%d" 1987 location = "West US" 1988 resource_group_name = "${azurerm_resource_group.test.name}" 1989 1990 ip_configuration { 1991 name = "testconfiguration1" 1992 subnet_id = "${azurerm_subnet.test.id}" 1993 private_ip_address_allocation = "dynamic" 1994 } 1995 } 1996 1997 resource "azurerm_storage_account" "test" { 1998 name = "accsa%d" 1999 resource_group_name = "${azurerm_resource_group.test.name}" 2000 location = "westus" 2001 account_type = "Standard_LRS" 2002 2003 tags { 2004 environment = "staging" 2005 } 2006 } 2007 2008 resource "azurerm_storage_container" "test" { 2009 name = "vhds" 2010 resource_group_name = "${azurerm_resource_group.test.name}" 2011 storage_account_name = "${azurerm_storage_account.test.name}" 2012 container_access_type = "private" 2013 } 2014 2015 resource "azurerm_virtual_machine" "test" { 2016 name = "acctvm-%d" 2017 location = "West US" 2018 resource_group_name = "${azurerm_resource_group.test.name}" 2019 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2020 vm_size = "Standard_A0" 2021 delete_os_disk_on_termination = true 2022 2023 storage_image_reference { 2024 publisher = "CoreOS" 2025 offer = "CoreOS" 2026 sku = "Stable" 2027 version = "latest" 2028 } 2029 2030 storage_os_disk { 2031 name = "myosdisk1" 2032 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2033 caching = "ReadWrite" 2034 create_option = "FromImage" 2035 disk_size_gb = "45" 2036 } 2037 2038 os_profile { 2039 computer_name = "hostname%d" 2040 admin_username = "testadmin" 2041 admin_password = "Password1234!" 2042 } 2043 2044 os_profile_linux_config { 2045 disable_password_authentication = false 2046 } 2047 2048 tags { 2049 environment = "Production" 2050 cost-center = "Ops" 2051 } 2052 } 2053 ` 2054 2055 var testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged = ` 2056 resource "azurerm_resource_group" "test" { 2057 name = "acctestRG-%d" 2058 location = "West US" 2059 } 2060 2061 resource "azurerm_virtual_network" "test" { 2062 name = "acctvn-%d" 2063 address_space = ["10.0.0.0/16"] 2064 location = "West US" 2065 resource_group_name = "${azurerm_resource_group.test.name}" 2066 } 2067 2068 resource "azurerm_subnet" "test" { 2069 name = "acctsub-%d" 2070 resource_group_name = "${azurerm_resource_group.test.name}" 2071 virtual_network_name = "${azurerm_virtual_network.test.name}" 2072 address_prefix = "10.0.2.0/24" 2073 } 2074 2075 resource "azurerm_network_interface" "test" { 2076 name = "acctni-%d" 2077 location = "West US" 2078 resource_group_name = "${azurerm_resource_group.test.name}" 2079 2080 ip_configuration { 2081 name = "testconfiguration1" 2082 subnet_id = "${azurerm_subnet.test.id}" 2083 private_ip_address_allocation = "dynamic" 2084 } 2085 } 2086 2087 resource "azurerm_storage_account" "test" { 2088 name = "accsa%d" 2089 resource_group_name = "${azurerm_resource_group.test.name}" 2090 location = "westus" 2091 account_type = "Standard_LRS" 2092 2093 tags { 2094 environment = "staging" 2095 } 2096 } 2097 2098 resource "azurerm_storage_container" "test" { 2099 name = "vhds" 2100 resource_group_name = "${azurerm_resource_group.test.name}" 2101 storage_account_name = "${azurerm_storage_account.test.name}" 2102 container_access_type = "private" 2103 } 2104 2105 resource "azurerm_virtual_machine" "test" { 2106 name = "acctvm-%d" 2107 location = "West US" 2108 resource_group_name = "${azurerm_resource_group.test.name}" 2109 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2110 vm_size = "Standard_A0" 2111 2112 storage_image_reference { 2113 publisher = "Canonical" 2114 offer = "UbuntuServer" 2115 sku = "14.04.2-LTS" 2116 version = "latest" 2117 } 2118 2119 storage_os_disk { 2120 name = "myosdisk1" 2121 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdiskchanged2.vhd" 2122 caching = "ReadWrite" 2123 create_option = "FromImage" 2124 disk_size_gb = "45" 2125 } 2126 2127 os_profile { 2128 computer_name = "hostname%d" 2129 admin_username = "testadmin" 2130 admin_password = "Password1234!" 2131 } 2132 2133 os_profile_linux_config { 2134 disable_password_authentication = false 2135 } 2136 2137 tags { 2138 environment = "Production" 2139 cost-center = "Ops" 2140 } 2141 } 2142 ` 2143 2144 var testAccAzureRMVirtualMachine_windowsLicenseType = ` 2145 resource "azurerm_resource_group" "test" { 2146 name = "acctestRG-%d" 2147 location = "West US" 2148 } 2149 2150 resource "azurerm_virtual_network" "test" { 2151 name = "acctvn-%d" 2152 address_space = ["10.0.0.0/16"] 2153 location = "West US" 2154 resource_group_name = "${azurerm_resource_group.test.name}" 2155 } 2156 2157 resource "azurerm_subnet" "test" { 2158 name = "acctsub-%d" 2159 resource_group_name = "${azurerm_resource_group.test.name}" 2160 virtual_network_name = "${azurerm_virtual_network.test.name}" 2161 address_prefix = "10.0.2.0/24" 2162 } 2163 2164 resource "azurerm_network_interface" "test" { 2165 name = "acctni-%d" 2166 location = "West US" 2167 resource_group_name = "${azurerm_resource_group.test.name}" 2168 2169 ip_configuration { 2170 name = "testconfiguration1" 2171 subnet_id = "${azurerm_subnet.test.id}" 2172 private_ip_address_allocation = "dynamic" 2173 } 2174 } 2175 2176 resource "azurerm_storage_account" "test" { 2177 name = "accsa%d" 2178 resource_group_name = "${azurerm_resource_group.test.name}" 2179 location = "westus" 2180 account_type = "Standard_LRS" 2181 2182 tags { 2183 environment = "staging" 2184 } 2185 } 2186 2187 resource "azurerm_storage_container" "test" { 2188 name = "vhds" 2189 resource_group_name = "${azurerm_resource_group.test.name}" 2190 storage_account_name = "${azurerm_storage_account.test.name}" 2191 container_access_type = "private" 2192 } 2193 2194 resource "azurerm_virtual_machine" "test" { 2195 name = "acctvm-%d" 2196 location = "West US" 2197 resource_group_name = "${azurerm_resource_group.test.name}" 2198 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2199 vm_size = "Standard_A0" 2200 license_type = "Windows_Server" 2201 2202 storage_image_reference { 2203 publisher = "MicrosoftWindowsServer" 2204 offer = "WindowsServer-HUB" 2205 sku = "2008-R2-SP1-HUB" 2206 version = "latest" 2207 } 2208 2209 storage_os_disk { 2210 name = "myosdisk1" 2211 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2212 caching = "ReadWrite" 2213 create_option = "FromImage" 2214 } 2215 2216 os_profile { 2217 computer_name = "winhost01" 2218 admin_username = "testadmin" 2219 admin_password = "Password1234!" 2220 } 2221 2222 os_profile_windows_config { 2223 enable_automatic_upgrades = false 2224 provision_vm_agent = true 2225 } 2226 } 2227 ` 2228 2229 var testAccAzureRMVirtualMachine_plan = ` 2230 resource "azurerm_resource_group" "test" { 2231 name = "acctestRG-%d" 2232 location = "West US" 2233 } 2234 2235 resource "azurerm_virtual_network" "test" { 2236 name = "acctvn-%d" 2237 address_space = ["10.0.0.0/16"] 2238 location = "West US" 2239 resource_group_name = "${azurerm_resource_group.test.name}" 2240 } 2241 2242 resource "azurerm_subnet" "test" { 2243 name = "acctsub-%d" 2244 resource_group_name = "${azurerm_resource_group.test.name}" 2245 virtual_network_name = "${azurerm_virtual_network.test.name}" 2246 address_prefix = "10.0.2.0/24" 2247 } 2248 2249 resource "azurerm_network_interface" "test" { 2250 name = "acctni-%d" 2251 location = "West US" 2252 resource_group_name = "${azurerm_resource_group.test.name}" 2253 2254 ip_configuration { 2255 name = "testconfiguration1" 2256 subnet_id = "${azurerm_subnet.test.id}" 2257 private_ip_address_allocation = "dynamic" 2258 } 2259 } 2260 2261 resource "azurerm_storage_account" "test" { 2262 name = "accsa%d" 2263 resource_group_name = "${azurerm_resource_group.test.name}" 2264 location = "westus" 2265 account_type = "Standard_LRS" 2266 2267 tags { 2268 environment = "staging" 2269 } 2270 } 2271 2272 resource "azurerm_storage_container" "test" { 2273 name = "vhds" 2274 resource_group_name = "${azurerm_resource_group.test.name}" 2275 storage_account_name = "${azurerm_storage_account.test.name}" 2276 container_access_type = "private" 2277 } 2278 2279 resource "azurerm_virtual_machine" "test" { 2280 name = "acctvm-%d" 2281 location = "West US" 2282 resource_group_name = "${azurerm_resource_group.test.name}" 2283 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2284 vm_size = "Standard_DS1_v2" 2285 2286 storage_image_reference { 2287 publisher = "kemptech" 2288 offer = "vlm-azure" 2289 sku = "freeloadmaster" 2290 version = "latest" 2291 } 2292 2293 storage_os_disk { 2294 name = "myosdisk1" 2295 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2296 caching = "ReadWrite" 2297 create_option = "FromImage" 2298 disk_size_gb = "45" 2299 } 2300 2301 os_profile { 2302 computer_name = "hostname%d" 2303 admin_username = "testadmin" 2304 admin_password = "Password1234!" 2305 } 2306 2307 os_profile_linux_config { 2308 disable_password_authentication = false 2309 } 2310 2311 plan { 2312 name = "freeloadmaster" 2313 publisher = "kemptech" 2314 product = "vlm-azure" 2315 } 2316 2317 tags { 2318 environment = "Production" 2319 cost-center = "Ops" 2320 } 2321 } 2322 ` 2323 2324 var testAccAzureRMVirtualMachine_linuxMachineWithSSH = ` 2325 resource "azurerm_resource_group" "test" { 2326 name = "acctestrg%s" 2327 location = "southcentralus" 2328 } 2329 2330 resource "azurerm_virtual_network" "test" { 2331 name = "acctvn%s" 2332 address_space = ["10.0.0.0/16"] 2333 location = "southcentralus" 2334 resource_group_name = "${azurerm_resource_group.test.name}" 2335 } 2336 2337 resource "azurerm_subnet" "test" { 2338 name = "acctsub%s" 2339 resource_group_name = "${azurerm_resource_group.test.name}" 2340 virtual_network_name = "${azurerm_virtual_network.test.name}" 2341 address_prefix = "10.0.2.0/24" 2342 } 2343 2344 resource "azurerm_network_interface" "test" { 2345 name = "acctni%s" 2346 location = "southcentralus" 2347 resource_group_name = "${azurerm_resource_group.test.name}" 2348 2349 ip_configuration { 2350 name = "testconfiguration1" 2351 subnet_id = "${azurerm_subnet.test.id}" 2352 private_ip_address_allocation = "dynamic" 2353 } 2354 } 2355 2356 resource "azurerm_storage_account" "test" { 2357 name = "accsa%s" 2358 resource_group_name = "${azurerm_resource_group.test.name}" 2359 location = "southcentralus" 2360 account_type = "Standard_LRS" 2361 } 2362 2363 resource "azurerm_storage_container" "test" { 2364 name = "vhds" 2365 resource_group_name = "${azurerm_resource_group.test.name}" 2366 storage_account_name = "${azurerm_storage_account.test.name}" 2367 container_access_type = "private" 2368 } 2369 2370 resource "azurerm_virtual_machine" "test" { 2371 name = "acctvm%s" 2372 location = "southcentralus" 2373 resource_group_name = "${azurerm_resource_group.test.name}" 2374 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2375 vm_size = "Standard_A0" 2376 2377 storage_image_reference { 2378 publisher = "Canonical" 2379 offer = "UbuntuServer" 2380 sku = "14.04.2-LTS" 2381 version = "latest" 2382 } 2383 2384 storage_os_disk { 2385 name = "myosdisk1" 2386 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2387 caching = "ReadWrite" 2388 create_option = "FromImage" 2389 disk_size_gb = "45" 2390 } 2391 2392 os_profile { 2393 computer_name = "hostname%s" 2394 admin_username = "testadmin" 2395 admin_password = "Password1234!" 2396 } 2397 2398 os_profile_linux_config { 2399 disable_password_authentication = true 2400 ssh_keys { 2401 path = "/home/testadmin/.ssh/authorized_keys" 2402 key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCfGyt5W1eJVpDIxlyvAWO594j/azEGohmlxYe7mgSfmUCWjuzILI6nHuHbxhpBDIZJhQ+JAeduXpii61dmThbI89ghGMhzea0OlT3p12e093zqa4goB9g40jdNKmJArER3pMVqs6hmv8y3GlUNkMDSmuoyI8AYzX4n26cUKZbwXQ== mk@mk3" 2403 } 2404 } 2405 } 2406 ` 2407 2408 var testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved = ` 2409 resource "azurerm_resource_group" "test" { 2410 name = "acctestrg%s" 2411 location = "southcentralus" 2412 } 2413 2414 resource "azurerm_virtual_network" "test" { 2415 name = "acctvn%s" 2416 address_space = ["10.0.0.0/16"] 2417 location = "southcentralus" 2418 resource_group_name = "${azurerm_resource_group.test.name}" 2419 } 2420 2421 resource "azurerm_subnet" "test" { 2422 name = "acctsub%s" 2423 resource_group_name = "${azurerm_resource_group.test.name}" 2424 virtual_network_name = "${azurerm_virtual_network.test.name}" 2425 address_prefix = "10.0.2.0/24" 2426 } 2427 2428 resource "azurerm_network_interface" "test" { 2429 name = "acctni%s" 2430 location = "southcentralus" 2431 resource_group_name = "${azurerm_resource_group.test.name}" 2432 2433 ip_configuration { 2434 name = "testconfiguration1" 2435 subnet_id = "${azurerm_subnet.test.id}" 2436 private_ip_address_allocation = "dynamic" 2437 } 2438 } 2439 2440 resource "azurerm_storage_account" "test" { 2441 name = "accsa%s" 2442 resource_group_name = "${azurerm_resource_group.test.name}" 2443 location = "southcentralus" 2444 account_type = "Standard_LRS" 2445 } 2446 2447 resource "azurerm_storage_container" "test" { 2448 name = "vhds" 2449 resource_group_name = "${azurerm_resource_group.test.name}" 2450 storage_account_name = "${azurerm_storage_account.test.name}" 2451 container_access_type = "private" 2452 } 2453 2454 resource "azurerm_virtual_machine" "test" { 2455 name = "acctvm%s" 2456 location = "southcentralus" 2457 resource_group_name = "${azurerm_resource_group.test.name}" 2458 network_interface_ids = ["${azurerm_network_interface.test.id}"] 2459 vm_size = "Standard_A0" 2460 2461 storage_image_reference { 2462 publisher = "Canonical" 2463 offer = "UbuntuServer" 2464 sku = "14.04.2-LTS" 2465 version = "latest" 2466 } 2467 2468 storage_os_disk { 2469 name = "myosdisk1" 2470 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2471 caching = "ReadWrite" 2472 create_option = "FromImage" 2473 disk_size_gb = "45" 2474 } 2475 2476 os_profile { 2477 computer_name = "hostname%s" 2478 admin_username = "testadmin" 2479 admin_password = "Password1234!" 2480 } 2481 2482 os_profile_linux_config { 2483 disable_password_authentication = true 2484 } 2485 } 2486 ` 2487 2488 var testAccAzureRMVirtualMachine_primaryNetworkInterfaceId = ` 2489 resource "azurerm_resource_group" "test" { 2490 name = "acctestRG-%d" 2491 location = "West US" 2492 } 2493 2494 resource "azurerm_virtual_network" "test" { 2495 name = "acctvn-%d" 2496 address_space = ["10.0.0.0/16"] 2497 location = "West US" 2498 resource_group_name = "${azurerm_resource_group.test.name}" 2499 } 2500 2501 resource "azurerm_subnet" "test" { 2502 name = "acctsub-%d" 2503 resource_group_name = "${azurerm_resource_group.test.name}" 2504 virtual_network_name = "${azurerm_virtual_network.test.name}" 2505 address_prefix = "10.0.2.0/24" 2506 } 2507 2508 resource "azurerm_network_interface" "test" { 2509 name = "acctni-%d" 2510 location = "West US" 2511 resource_group_name = "${azurerm_resource_group.test.name}" 2512 2513 ip_configuration { 2514 name = "testconfiguration1" 2515 subnet_id = "${azurerm_subnet.test.id}" 2516 private_ip_address_allocation = "dynamic" 2517 } 2518 } 2519 2520 resource "azurerm_network_interface" "test2" { 2521 name = "acctni2-%d" 2522 location = "West US" 2523 resource_group_name = "${azurerm_resource_group.test.name}" 2524 2525 ip_configuration { 2526 name = "testconfiguration2" 2527 subnet_id = "${azurerm_subnet.test.id}" 2528 private_ip_address_allocation = "dynamic" 2529 } 2530 } 2531 2532 resource "azurerm_storage_account" "test" { 2533 name = "accsa%d" 2534 resource_group_name = "${azurerm_resource_group.test.name}" 2535 location = "westus" 2536 account_type = "Standard_LRS" 2537 2538 tags { 2539 environment = "staging" 2540 } 2541 } 2542 2543 resource "azurerm_storage_container" "test" { 2544 name = "vhds" 2545 resource_group_name = "${azurerm_resource_group.test.name}" 2546 storage_account_name = "${azurerm_storage_account.test.name}" 2547 container_access_type = "private" 2548 } 2549 2550 resource "azurerm_virtual_machine" "test" { 2551 name = "acctvm-%d" 2552 location = "West US" 2553 resource_group_name = "${azurerm_resource_group.test.name}" 2554 network_interface_ids = ["${azurerm_network_interface.test.id}","${azurerm_network_interface.test2.id}"] 2555 primary_network_interface_id = "${azurerm_network_interface.test.id}" 2556 vm_size = "Standard_A3" 2557 2558 storage_image_reference { 2559 publisher = "Canonical" 2560 offer = "UbuntuServer" 2561 sku = "14.04.2-LTS" 2562 version = "latest" 2563 } 2564 2565 storage_os_disk { 2566 name = "myosdisk1" 2567 vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" 2568 caching = "ReadWrite" 2569 create_option = "FromImage" 2570 disk_size_gb = "45" 2571 } 2572 2573 os_profile { 2574 computer_name = "hostname" 2575 admin_username = "testadmin" 2576 admin_password = "Password1234!" 2577 } 2578 2579 os_profile_linux_config { 2580 disable_password_authentication = false 2581 } 2582 2583 tags { 2584 environment = "Production" 2585 cost-center = "Ops" 2586 } 2587 } 2588 `