github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/builtin/providers/azurerm/resource_arm_virtual_machine_scale_set_test.go (about) 1 package azurerm 2 3 import ( 4 "fmt" 5 "net/http" 6 "regexp" 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 TestAccAzureRMVirtualMachineScaleSet_basic(t *testing.T) { 16 ri := acctest.RandInt() 17 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basic, ri, ri, ri, ri, ri, ri, ri, ri) 18 resource.Test(t, resource.TestCase{ 19 PreCheck: func() { testAccPreCheck(t) }, 20 Providers: testAccProviders, 21 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 22 Steps: []resource.TestStep{ 23 { 24 Config: config, 25 Check: resource.ComposeTestCheckFunc( 26 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 27 28 // single placement group should default to true 29 testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup("azurerm_virtual_machine_scale_set.test", true), 30 ), 31 }, 32 }, 33 }) 34 } 35 36 func TestAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(t *testing.T) { 37 ri := acctest.RandInt() 38 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse, ri) 39 resource.Test(t, resource.TestCase{ 40 PreCheck: func() { testAccPreCheck(t) }, 41 Providers: testAccProviders, 42 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 43 Steps: []resource.TestStep{ 44 { 45 Config: config, 46 Check: resource.ComposeTestCheckFunc( 47 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 48 testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup("azurerm_virtual_machine_scale_set.test", false), 49 ), 50 }, 51 }, 52 }) 53 } 54 55 func TestAccAzureRMVirtualMachineScaleSet_linuxUpdated(t *testing.T) { 56 resourceName := "azurerm_virtual_machine_scale_set.test" 57 ri := acctest.RandInt() 58 config := testAccAzureRMVirtualMachineScaleSet_linux(ri) 59 updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxUpdated(ri) 60 61 resource.Test(t, resource.TestCase{ 62 PreCheck: func() { testAccPreCheck(t) }, 63 Providers: testAccProviders, 64 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 65 Steps: []resource.TestStep{ 66 { 67 Config: config, 68 Check: resource.ComposeTestCheckFunc( 69 testCheckAzureRMVirtualMachineScaleSetExists(resourceName), 70 ), 71 }, 72 { 73 Config: updatedConfig, 74 Check: resource.ComposeTestCheckFunc( 75 testCheckAzureRMVirtualMachineScaleSetExists(resourceName), 76 ), 77 }, 78 }, 79 }) 80 } 81 82 func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(t *testing.T) { 83 ri := acctest.RandInt() 84 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk, ri, ri, ri, ri, ri, ri) 85 resource.Test(t, resource.TestCase{ 86 PreCheck: func() { testAccPreCheck(t) }, 87 Providers: testAccProviders, 88 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 89 Steps: []resource.TestStep{ 90 { 91 Config: config, 92 Check: resource.ComposeTestCheckFunc( 93 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 94 ), 95 }, 96 }, 97 }) 98 } 99 100 func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) { 101 ri := acctest.RandInt() 102 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basic, ri, ri, ri, ri, ri, ri, ri, ri) 103 resource.Test(t, resource.TestCase{ 104 PreCheck: func() { testAccPreCheck(t) }, 105 Providers: testAccProviders, 106 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 107 Steps: []resource.TestStep{ 108 { 109 Config: config, 110 Check: resource.ComposeTestCheckFunc( 111 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 112 testCheckAzureRMVirtualMachineScaleSetDisappears("azurerm_virtual_machine_scale_set.test"), 113 ), 114 ExpectNonEmptyPlan: true, 115 }, 116 }, 117 }) 118 } 119 120 func TestAccAzureRMVirtualMachineScaleSet_loadBalancer(t *testing.T) { 121 ri := acctest.RandInt() 122 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate, ri, ri, ri, ri, ri, ri, ri) 123 resource.Test(t, resource.TestCase{ 124 PreCheck: func() { testAccPreCheck(t) }, 125 Providers: testAccProviders, 126 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 127 Steps: []resource.TestStep{ 128 { 129 Config: config, 130 Check: resource.ComposeTestCheckFunc( 131 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 132 testCheckAzureRMVirtualMachineScaleSetHasLoadbalancer("azurerm_virtual_machine_scale_set.test"), 133 ), 134 }, 135 }, 136 }) 137 } 138 139 func TestAccAzureRMVirtualMachineScaleSet_loadBalancerManagedDataDisks(t *testing.T) { 140 ri := acctest.RandInt() 141 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplateManagedDataDisks, ri, ri, ri, ri, ri, ri) 142 resource.Test(t, resource.TestCase{ 143 PreCheck: func() { testAccPreCheck(t) }, 144 Providers: testAccProviders, 145 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 146 Steps: []resource.TestStep{ 147 { 148 Config: config, 149 Check: resource.ComposeTestCheckFunc( 150 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 151 testCheckAzureRMVirtualMachineScaleSetHasDataDisks("azurerm_virtual_machine_scale_set.test"), 152 ), 153 }, 154 }, 155 }) 156 } 157 158 func TestAccAzureRMVirtualMachineScaleSet_overprovision(t *testing.T) { 159 ri := acctest.RandInt() 160 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetOverprovisionTemplate, ri, ri, ri, ri, ri, ri) 161 resource.Test(t, resource.TestCase{ 162 PreCheck: func() { testAccPreCheck(t) }, 163 Providers: testAccProviders, 164 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 165 Steps: []resource.TestStep{ 166 { 167 Config: config, 168 Check: resource.ComposeTestCheckFunc( 169 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 170 testCheckAzureRMVirtualMachineScaleSetOverprovision("azurerm_virtual_machine_scale_set.test"), 171 ), 172 }, 173 }, 174 }) 175 } 176 177 func TestAccAzureRMVirtualMachineScaleSet_extension(t *testing.T) { 178 ri := acctest.RandInt() 179 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetExtensionTemplate, ri, ri, ri, ri, ri, ri) 180 resource.Test(t, resource.TestCase{ 181 PreCheck: func() { testAccPreCheck(t) }, 182 Providers: testAccProviders, 183 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 184 Steps: []resource.TestStep{ 185 { 186 Config: config, 187 Check: resource.ComposeTestCheckFunc( 188 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 189 testCheckAzureRMVirtualMachineScaleSetExtension("azurerm_virtual_machine_scale_set.test"), 190 ), 191 }, 192 }, 193 }) 194 } 195 196 func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions(t *testing.T) { 197 ri := acctest.RandInt() 198 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate, ri, ri, ri, ri, ri, ri) 199 resource.Test(t, resource.TestCase{ 200 PreCheck: func() { testAccPreCheck(t) }, 201 Providers: testAccProviders, 202 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 203 Steps: []resource.TestStep{ 204 { 205 Config: config, 206 Check: resource.ComposeTestCheckFunc( 207 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 208 testCheckAzureRMVirtualMachineScaleSetExtension("azurerm_virtual_machine_scale_set.test"), 209 ), 210 }, 211 }, 212 }) 213 } 214 215 func TestAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(t *testing.T) { 216 ri := acctest.RandInt() 217 config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict, ri, ri, ri, ri, ri, ri, ri) 218 resource.Test(t, resource.TestCase{ 219 PreCheck: func() { testAccPreCheck(t) }, 220 Providers: testAccProviders, 221 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 222 Steps: []resource.TestStep{ 223 { 224 Config: config, 225 ExpectError: regexp.MustCompile("Conflict between `vhd_containers`"), 226 //Use below code instead once GH-13019 has been merged 227 //ExpectError: regexp.MustCompile("conflicts with storage_profile_os_disk.0.vhd_containers"), 228 }, 229 }, 230 }) 231 } 232 233 func TestAccAzureRMVirtualMachineScaleSet_NonStandardCasing(t *testing.T) { 234 ri := acctest.RandInt() 235 config := testAccAzureRMVirtualMachineScaleSetNonStandardCasing(ri) 236 resource.Test(t, resource.TestCase{ 237 PreCheck: func() { testAccPreCheck(t) }, 238 Providers: testAccProviders, 239 CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, 240 Steps: []resource.TestStep{ 241 242 resource.TestStep{ 243 Config: config, 244 Check: resource.ComposeTestCheckFunc( 245 testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), 246 ), 247 }, 248 249 resource.TestStep{ 250 Config: config, 251 PlanOnly: true, 252 ExpectNonEmptyPlan: false, 253 }, 254 }, 255 }) 256 } 257 258 func testGetAzureRMVirtualMachineScaleSet(s *terraform.State, resourceName string) (result *compute.VirtualMachineScaleSet, err error) { 259 // Ensure we have enough information in state to look up in API 260 rs, ok := s.RootModule().Resources[resourceName] 261 if !ok { 262 return nil, fmt.Errorf("Not found: %s", resourceName) 263 } 264 265 // Name of the actual scale set 266 name := rs.Primary.Attributes["name"] 267 268 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 269 if !hasResourceGroup { 270 return nil, fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name) 271 } 272 273 conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient 274 275 vmss, err := conn.Get(resourceGroup, name) 276 if err != nil { 277 return nil, fmt.Errorf("Bad: Get on vmScaleSetClient: %s", err) 278 } 279 280 if vmss.StatusCode == http.StatusNotFound { 281 return nil, fmt.Errorf("Bad: VirtualMachineScaleSet %q (resource group: %q) does not exist", name, resourceGroup) 282 } 283 284 return &vmss, err 285 } 286 287 func testCheckAzureRMVirtualMachineScaleSetExists(name string) resource.TestCheckFunc { 288 return func(s *terraform.State) error { 289 _, err := testGetAzureRMVirtualMachineScaleSet(s, name) 290 return err 291 } 292 } 293 294 func testCheckAzureRMVirtualMachineScaleSetDisappears(name string) resource.TestCheckFunc { 295 return func(s *terraform.State) error { 296 // Ensure we have enough information in state to look up in API 297 rs, ok := s.RootModule().Resources[name] 298 if !ok { 299 return fmt.Errorf("Not found: %s", name) 300 } 301 302 name := rs.Primary.Attributes["name"] 303 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 304 if !hasResourceGroup { 305 return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name) 306 } 307 308 conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient 309 310 _, error := conn.Delete(resourceGroup, name, make(chan struct{})) 311 err := <-error 312 if err != nil { 313 return fmt.Errorf("Bad: Delete on vmScaleSetClient: %s", err) 314 } 315 316 return nil 317 } 318 } 319 320 func testCheckAzureRMVirtualMachineScaleSetDestroy(s *terraform.State) error { 321 conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient 322 323 for _, rs := range s.RootModule().Resources { 324 if rs.Type != "azurerm_virtual_machine_scale_set" { 325 continue 326 } 327 328 name := rs.Primary.Attributes["name"] 329 resourceGroup := rs.Primary.Attributes["resource_group_name"] 330 331 resp, err := conn.Get(resourceGroup, name) 332 333 if err != nil { 334 return nil 335 } 336 337 if resp.StatusCode != http.StatusNotFound { 338 return fmt.Errorf("Virtual Machine Scale Set still exists:\n%#v", resp.VirtualMachineScaleSetProperties) 339 } 340 } 341 342 return nil 343 } 344 345 func testCheckAzureRMVirtualMachineScaleSetHasLoadbalancer(name string) resource.TestCheckFunc { 346 return func(s *terraform.State) error { 347 resp, err := testGetAzureRMVirtualMachineScaleSet(s, name) 348 if err != nil { 349 return err 350 } 351 352 n := resp.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations 353 if n == nil || len(*n) == 0 { 354 return fmt.Errorf("Bad: Could not get network interface configurations for scale set %v", name) 355 } 356 357 ip := (*n)[0].IPConfigurations 358 if ip == nil || len(*ip) == 0 { 359 return fmt.Errorf("Bad: Could not get ip configurations for scale set %v", name) 360 } 361 362 pools := (*ip)[0].LoadBalancerBackendAddressPools 363 if pools == nil || len(*pools) == 0 { 364 return fmt.Errorf("Bad: Load balancer backend pools is empty for scale set %v", name) 365 } 366 367 return nil 368 } 369 } 370 371 func testCheckAzureRMVirtualMachineScaleSetOverprovision(name string) resource.TestCheckFunc { 372 return func(s *terraform.State) error { 373 resp, err := testGetAzureRMVirtualMachineScaleSet(s, name) 374 if err != nil { 375 return err 376 } 377 378 if *resp.Overprovision { 379 return fmt.Errorf("Bad: Overprovision should have been false for scale set %v", name) 380 } 381 382 return nil 383 } 384 } 385 386 func testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(name string, expectedSinglePlacementGroup bool) resource.TestCheckFunc { 387 return func(s *terraform.State) error { 388 resp, err := testGetAzureRMVirtualMachineScaleSet(s, name) 389 if err != nil { 390 return err 391 } 392 393 if *resp.SinglePlacementGroup != expectedSinglePlacementGroup { 394 return fmt.Errorf("Bad: Overprovision should have been %t for scale set %v", expectedSinglePlacementGroup, name) 395 } 396 397 return nil 398 } 399 } 400 401 func testCheckAzureRMVirtualMachineScaleSetExtension(name string) resource.TestCheckFunc { 402 return func(s *terraform.State) error { 403 resp, err := testGetAzureRMVirtualMachineScaleSet(s, name) 404 if err != nil { 405 return err 406 } 407 408 n := resp.VirtualMachineProfile.ExtensionProfile.Extensions 409 if n == nil || len(*n) == 0 { 410 return fmt.Errorf("Bad: Could not get extensions for scale set %v", name) 411 } 412 413 return nil 414 } 415 } 416 417 func testCheckAzureRMVirtualMachineScaleSetHasDataDisks(name string) resource.TestCheckFunc { 418 return func(s *terraform.State) error { 419 // Ensure we have enough information in state to look up in API 420 rs, ok := s.RootModule().Resources[name] 421 if !ok { 422 return fmt.Errorf("Not found: %s", name) 423 } 424 425 name := rs.Primary.Attributes["name"] 426 resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] 427 if !hasResourceGroup { 428 return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name) 429 } 430 431 conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient 432 resp, err := conn.Get(resourceGroup, name) 433 if err != nil { 434 return fmt.Errorf("Bad: Get on vmScaleSetClient: %s", err) 435 } 436 437 if resp.StatusCode == http.StatusNotFound { 438 return fmt.Errorf("Bad: VirtualMachineScaleSet %q (resource group: %q) does not exist", name, resourceGroup) 439 } 440 441 storageProfile := resp.VirtualMachineProfile.StorageProfile.DataDisks 442 if storageProfile == nil || len(*storageProfile) == 0 { 443 return fmt.Errorf("Bad: Could not get data disks configurations for scale set %v", name) 444 } 445 446 return nil 447 } 448 } 449 450 var testAccAzureRMVirtualMachineScaleSet_basic = ` 451 resource "azurerm_resource_group" "test" { 452 name = "acctestRG-%d" 453 location = "West US 2" 454 } 455 456 resource "azurerm_virtual_network" "test" { 457 name = "acctvn-%d" 458 address_space = ["10.0.0.0/16"] 459 location = "West US 2" 460 resource_group_name = "${azurerm_resource_group.test.name}" 461 } 462 463 resource "azurerm_subnet" "test" { 464 name = "acctsub-%d" 465 resource_group_name = "${azurerm_resource_group.test.name}" 466 virtual_network_name = "${azurerm_virtual_network.test.name}" 467 address_prefix = "10.0.2.0/24" 468 } 469 470 resource "azurerm_network_interface" "test" { 471 name = "acctni-%d" 472 location = "West US 2" 473 resource_group_name = "${azurerm_resource_group.test.name}" 474 475 ip_configuration { 476 name = "testconfiguration1" 477 subnet_id = "${azurerm_subnet.test.id}" 478 private_ip_address_allocation = "dynamic" 479 } 480 } 481 482 resource "azurerm_storage_account" "test" { 483 name = "accsa%d" 484 resource_group_name = "${azurerm_resource_group.test.name}" 485 location = "West US 2" 486 account_type = "Standard_LRS" 487 488 tags { 489 environment = "staging" 490 } 491 } 492 493 resource "azurerm_storage_container" "test" { 494 name = "vhds" 495 resource_group_name = "${azurerm_resource_group.test.name}" 496 storage_account_name = "${azurerm_storage_account.test.name}" 497 container_access_type = "private" 498 } 499 500 resource "azurerm_virtual_machine_scale_set" "test" { 501 name = "acctvmss-%d" 502 location = "West US 2" 503 resource_group_name = "${azurerm_resource_group.test.name}" 504 upgrade_policy_mode = "Manual" 505 506 sku { 507 name = "Standard_D1_v2" 508 tier = "Standard" 509 capacity = 2 510 } 511 512 os_profile { 513 computer_name_prefix = "testvm-%d" 514 admin_username = "myadmin" 515 admin_password = "Passwword1234" 516 } 517 518 network_profile { 519 name = "TestNetworkProfile-%d" 520 primary = true 521 ip_configuration { 522 name = "TestIPConfiguration" 523 subnet_id = "${azurerm_subnet.test.id}" 524 } 525 } 526 527 storage_profile_os_disk { 528 name = "osDiskProfile" 529 caching = "ReadWrite" 530 create_option = "FromImage" 531 vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"] 532 } 533 534 storage_profile_image_reference { 535 publisher = "Canonical" 536 offer = "UbuntuServer" 537 sku = "16.04-LTS" 538 version = "latest" 539 } 540 } 541 ` 542 543 var testAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse = ` 544 resource "azurerm_resource_group" "test" { 545 name = "acctestRG-%[1]d" 546 location = "West US 2" 547 } 548 549 resource "azurerm_virtual_network" "test" { 550 name = "acctvn-%[1]d" 551 address_space = ["10.0.0.0/16"] 552 location = "West US 2" 553 resource_group_name = "${azurerm_resource_group.test.name}" 554 } 555 556 resource "azurerm_subnet" "test" { 557 name = "acctsub-%[1]d" 558 resource_group_name = "${azurerm_resource_group.test.name}" 559 virtual_network_name = "${azurerm_virtual_network.test.name}" 560 address_prefix = "10.0.2.0/24" 561 } 562 563 resource "azurerm_network_interface" "test" { 564 name = "acctni-%[1]d" 565 location = "West US 2" 566 resource_group_name = "${azurerm_resource_group.test.name}" 567 568 ip_configuration { 569 name = "testconfiguration1" 570 subnet_id = "${azurerm_subnet.test.id}" 571 private_ip_address_allocation = "dynamic" 572 } 573 } 574 575 resource "azurerm_storage_account" "test" { 576 name = "accsa%[1]d" 577 resource_group_name = "${azurerm_resource_group.test.name}" 578 location = "West US 2" 579 account_type = "Standard_LRS" 580 581 tags { 582 environment = "staging" 583 } 584 } 585 586 resource "azurerm_storage_container" "test" { 587 name = "vhds" 588 resource_group_name = "${azurerm_resource_group.test.name}" 589 storage_account_name = "${azurerm_storage_account.test.name}" 590 container_access_type = "private" 591 } 592 593 resource "azurerm_virtual_machine_scale_set" "test" { 594 name = "acctvmss-%[1]d" 595 location = "West US 2" 596 resource_group_name = "${azurerm_resource_group.test.name}" 597 upgrade_policy_mode = "Manual" 598 single_placement_group = false 599 600 sku { 601 name = "Standard_D1_v2" 602 tier = "Standard" 603 capacity = 2 604 } 605 606 os_profile { 607 computer_name_prefix = "testvm-%[1]d" 608 admin_username = "myadmin" 609 admin_password = "Passwword1234" 610 } 611 612 network_profile { 613 name = "TestNetworkProfile-%[1]d" 614 primary = true 615 ip_configuration { 616 name = "TestIPConfiguration" 617 subnet_id = "${azurerm_subnet.test.id}" 618 } 619 } 620 621 storage_profile_os_disk { 622 name = "" 623 caching = "ReadWrite" 624 create_option = "FromImage" 625 managed_disk_type = "Standard_LRS" 626 } 627 628 storage_profile_image_reference { 629 publisher = "Canonical" 630 offer = "UbuntuServer" 631 sku = "16.04-LTS" 632 version = "latest" 633 } 634 } 635 ` 636 637 func testAccAzureRMVirtualMachineScaleSet_linux(rInt int) string { 638 return fmt.Sprintf(` 639 resource "azurerm_resource_group" "test" { 640 name = "acctestrg-%d" 641 location = "West Europe" 642 } 643 resource "azurerm_virtual_network" "test" { 644 name = "acctestvn-%d" 645 resource_group_name = "${azurerm_resource_group.test.name}" 646 location = "${azurerm_resource_group.test.location}" 647 address_space = ["10.0.0.0/8"] 648 } 649 resource "azurerm_subnet" "test" { 650 name = "acctestsn-%d" 651 resource_group_name = "${azurerm_resource_group.test.name}" 652 virtual_network_name = "${azurerm_virtual_network.test.name}" 653 address_prefix = "10.0.1.0/24" 654 } 655 resource "azurerm_storage_account" "test" { 656 name = "accsa%d" 657 resource_group_name = "${azurerm_resource_group.test.name}" 658 location = "${azurerm_resource_group.test.location}" 659 account_type = "Standard_LRS" 660 } 661 resource "azurerm_storage_container" "test" { 662 name = "acctestsc-%d" 663 resource_group_name = "${azurerm_resource_group.test.name}" 664 storage_account_name = "${azurerm_storage_account.test.name}" 665 container_access_type = "private" 666 } 667 resource "azurerm_public_ip" "test" { 668 name = "acctestpip-%d" 669 resource_group_name = "${azurerm_resource_group.test.name}" 670 location = "${azurerm_resource_group.test.location}" 671 public_ip_address_allocation = "static" 672 } 673 resource "azurerm_lb" "test" { 674 name = "acctestlb-%d" 675 resource_group_name = "${azurerm_resource_group.test.name}" 676 location = "${azurerm_resource_group.test.location}" 677 frontend_ip_configuration { 678 name = "ip-address" 679 public_ip_address_id = "${azurerm_public_ip.test.id}" 680 } 681 } 682 resource "azurerm_lb_backend_address_pool" "test" { 683 name = "acctestbap-%d" 684 resource_group_name = "${azurerm_resource_group.test.name}" 685 loadbalancer_id = "${azurerm_lb.test.id}" 686 } 687 resource "azurerm_virtual_machine_scale_set" "test" { 688 name = "acctestvmss-%d" 689 resource_group_name = "${azurerm_resource_group.test.name}" 690 location = "${azurerm_resource_group.test.location}" 691 upgrade_policy_mode = "Automatic" 692 sku { 693 name = "Standard_A0" 694 tier = "Standard" 695 capacity = "1" 696 } 697 os_profile { 698 computer_name_prefix = "prefix" 699 admin_username = "ubuntu" 700 admin_password = "password" 701 custom_data = "custom data!" 702 } 703 os_profile_linux_config { 704 disable_password_authentication = true 705 ssh_keys { 706 path = "/home/ubuntu/.ssh/authorized_keys" 707 key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com" 708 } 709 } 710 network_profile { 711 name = "TestNetworkProfile" 712 primary = true 713 ip_configuration { 714 name = "TestIPConfiguration" 715 subnet_id = "${azurerm_subnet.test.id}" 716 load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"] 717 } 718 } 719 storage_profile_os_disk { 720 name = "osDiskProfile" 721 caching = "ReadWrite" 722 create_option = "FromImage" 723 os_type = "linux" 724 vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"] 725 } 726 storage_profile_image_reference { 727 publisher = "Canonical" 728 offer = "UbuntuServer" 729 sku = "14.04.2-LTS" 730 version = "latest" 731 } 732 } 733 `, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) 734 } 735 736 func testAccAzureRMVirtualMachineScaleSet_linuxUpdated(rInt int) string { 737 return fmt.Sprintf(` 738 resource "azurerm_resource_group" "test" { 739 name = "acctestrg-%d" 740 location = "West Europe" 741 } 742 resource "azurerm_virtual_network" "test" { 743 name = "acctestvn-%d" 744 resource_group_name = "${azurerm_resource_group.test.name}" 745 location = "${azurerm_resource_group.test.location}" 746 address_space = ["10.0.0.0/8"] 747 } 748 resource "azurerm_subnet" "test" { 749 name = "acctestsn-%d" 750 resource_group_name = "${azurerm_resource_group.test.name}" 751 virtual_network_name = "${azurerm_virtual_network.test.name}" 752 address_prefix = "10.0.1.0/24" 753 } 754 resource "azurerm_storage_account" "test" { 755 name = "accsa%d" 756 resource_group_name = "${azurerm_resource_group.test.name}" 757 location = "${azurerm_resource_group.test.location}" 758 account_type = "Standard_LRS" 759 } 760 resource "azurerm_storage_container" "test" { 761 name = "acctestsc-%d" 762 resource_group_name = "${azurerm_resource_group.test.name}" 763 storage_account_name = "${azurerm_storage_account.test.name}" 764 container_access_type = "private" 765 } 766 resource "azurerm_public_ip" "test" { 767 name = "acctestpip-%d" 768 resource_group_name = "${azurerm_resource_group.test.name}" 769 location = "${azurerm_resource_group.test.location}" 770 public_ip_address_allocation = "static" 771 } 772 resource "azurerm_lb" "test" { 773 name = "acctestlb-%d" 774 resource_group_name = "${azurerm_resource_group.test.name}" 775 location = "${azurerm_resource_group.test.location}" 776 frontend_ip_configuration { 777 name = "ip-address" 778 public_ip_address_id = "${azurerm_public_ip.test.id}" 779 } 780 } 781 resource "azurerm_lb_backend_address_pool" "test" { 782 name = "acctestbap-%d" 783 resource_group_name = "${azurerm_resource_group.test.name}" 784 loadbalancer_id = "${azurerm_lb.test.id}" 785 } 786 resource "azurerm_virtual_machine_scale_set" "test" { 787 name = "acctestvmss-%d" 788 resource_group_name = "${azurerm_resource_group.test.name}" 789 location = "${azurerm_resource_group.test.location}" 790 upgrade_policy_mode = "Automatic" 791 sku { 792 name = "Standard_A0" 793 tier = "Standard" 794 capacity = "1" 795 } 796 os_profile { 797 computer_name_prefix = "prefix" 798 admin_username = "ubuntu" 799 admin_password = "password" 800 custom_data = "custom data!" 801 } 802 os_profile_linux_config { 803 disable_password_authentication = true 804 ssh_keys { 805 path = "/home/ubuntu/.ssh/authorized_keys" 806 key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com" 807 } 808 } 809 network_profile { 810 name = "TestNetworkProfile" 811 primary = true 812 ip_configuration { 813 name = "TestIPConfiguration" 814 subnet_id = "${azurerm_subnet.test.id}" 815 load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.test.id}"] 816 } 817 } 818 storage_profile_os_disk { 819 name = "osDiskProfile" 820 caching = "ReadWrite" 821 create_option = "FromImage" 822 os_type = "linux" 823 vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"] 824 } 825 storage_profile_image_reference { 826 publisher = "Canonical" 827 offer = "UbuntuServer" 828 sku = "14.04.2-LTS" 829 version = "latest" 830 } 831 tags { 832 ThisIs = "a test" 833 } 834 } 835 `, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) 836 } 837 838 var testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk = ` 839 resource "azurerm_resource_group" "test" { 840 name = "acctestRG-%d" 841 location = "West US 2" 842 } 843 844 resource "azurerm_virtual_network" "test" { 845 name = "acctvn-%d" 846 address_space = ["10.0.0.0/16"] 847 location = "West US 2" 848 resource_group_name = "${azurerm_resource_group.test.name}" 849 } 850 851 resource "azurerm_subnet" "test" { 852 name = "acctsub-%d" 853 resource_group_name = "${azurerm_resource_group.test.name}" 854 virtual_network_name = "${azurerm_virtual_network.test.name}" 855 address_prefix = "10.0.2.0/24" 856 } 857 858 resource "azurerm_virtual_machine_scale_set" "test" { 859 name = "acctvmss-%d" 860 location = "West US 2" 861 resource_group_name = "${azurerm_resource_group.test.name}" 862 upgrade_policy_mode = "Manual" 863 864 sku { 865 name = "Standard_D1_v2" 866 tier = "Standard" 867 capacity = 2 868 } 869 870 os_profile { 871 computer_name_prefix = "testvm-%d" 872 admin_username = "myadmin" 873 admin_password = "Passwword1234" 874 } 875 876 network_profile { 877 name = "TestNetworkProfile-%d" 878 primary = true 879 ip_configuration { 880 name = "TestIPConfiguration" 881 subnet_id = "${azurerm_subnet.test.id}" 882 } 883 } 884 885 storage_profile_os_disk { 886 name = "" 887 caching = "ReadWrite" 888 create_option = "FromImage" 889 managed_disk_type = "Standard_LRS" 890 } 891 892 storage_profile_image_reference { 893 publisher = "Canonical" 894 offer = "UbuntuServer" 895 sku = "16.04-LTS" 896 version = "latest" 897 } 898 } 899 ` 900 901 var testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate = ` 902 resource "azurerm_resource_group" "test" { 903 name = "acctestrg-%d" 904 location = "southcentralus" 905 } 906 907 resource "azurerm_virtual_network" "test" { 908 name = "acctvn-%d" 909 address_space = ["10.0.0.0/16"] 910 location = "southcentralus" 911 resource_group_name = "${azurerm_resource_group.test.name}" 912 } 913 914 resource "azurerm_subnet" "test" { 915 name = "acctsub-%d" 916 resource_group_name = "${azurerm_resource_group.test.name}" 917 virtual_network_name = "${azurerm_virtual_network.test.name}" 918 address_prefix = "10.0.2.0/24" 919 } 920 921 resource "azurerm_storage_account" "test" { 922 name = "accsa%d" 923 resource_group_name = "${azurerm_resource_group.test.name}" 924 location = "southcentralus" 925 account_type = "Standard_LRS" 926 } 927 928 resource "azurerm_storage_container" "test" { 929 name = "vhds" 930 resource_group_name = "${azurerm_resource_group.test.name}" 931 storage_account_name = "${azurerm_storage_account.test.name}" 932 container_access_type = "private" 933 } 934 935 resource "azurerm_lb" "test" { 936 name = "acctestlb-%d" 937 location = "southcentralus" 938 resource_group_name = "${azurerm_resource_group.test.name}" 939 940 frontend_ip_configuration { 941 name = "default" 942 subnet_id = "${azurerm_subnet.test.id}" 943 private_ip_address_allocation = "Dynamic" 944 } 945 } 946 947 resource "azurerm_lb_backend_address_pool" "test" { 948 name = "test" 949 resource_group_name = "${azurerm_resource_group.test.name}" 950 location = "southcentralus" 951 loadbalancer_id = "${azurerm_lb.test.id}" 952 } 953 954 resource "azurerm_lb_nat_pool" "test" { 955 resource_group_name = "${azurerm_resource_group.test.name}" 956 name = "ssh" 957 loadbalancer_id = "${azurerm_lb.test.id}" 958 protocol = "Tcp" 959 frontend_port_start = 50000 960 frontend_port_end = 50119 961 backend_port = 22 962 frontend_ip_configuration_name = "default" 963 } 964 965 resource "azurerm_virtual_machine_scale_set" "test" { 966 name = "acctvmss-%d" 967 location = "southcentralus" 968 resource_group_name = "${azurerm_resource_group.test.name}" 969 upgrade_policy_mode = "Manual" 970 971 sku { 972 name = "Standard_D1_v2" 973 tier = "Standard" 974 capacity = 1 975 } 976 977 os_profile { 978 computer_name_prefix = "testvm-%d" 979 admin_username = "myadmin" 980 admin_password = "Passwword1234" 981 } 982 983 network_profile { 984 name = "TestNetworkProfile" 985 primary = true 986 ip_configuration { 987 name = "TestIPConfiguration" 988 subnet_id = "${azurerm_subnet.test.id}" 989 load_balancer_backend_address_pool_ids = [ "${azurerm_lb_backend_address_pool.test.id}" ] 990 load_balancer_inbound_nat_rules_ids = ["${azurerm_lb_nat_pool.test.id}"] 991 } 992 } 993 994 storage_profile_os_disk { 995 name = "os-disk" 996 caching = "ReadWrite" 997 create_option = "FromImage" 998 vhd_containers = [ "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}" ] 999 } 1000 1001 storage_profile_image_reference { 1002 publisher = "Canonical" 1003 offer = "UbuntuServer" 1004 sku = "16.04-LTS" 1005 version = "latest" 1006 } 1007 } 1008 ` 1009 1010 var testAccAzureRMVirtualMachineScaleSetOverprovisionTemplate = ` 1011 resource "azurerm_resource_group" "test" { 1012 name = "acctestrg-%d" 1013 location = "southcentralus" 1014 } 1015 1016 resource "azurerm_virtual_network" "test" { 1017 name = "acctvn-%d" 1018 address_space = ["10.0.0.0/16"] 1019 location = "southcentralus" 1020 resource_group_name = "${azurerm_resource_group.test.name}" 1021 } 1022 1023 resource "azurerm_subnet" "test" { 1024 name = "acctsub-%d" 1025 resource_group_name = "${azurerm_resource_group.test.name}" 1026 virtual_network_name = "${azurerm_virtual_network.test.name}" 1027 address_prefix = "10.0.2.0/24" 1028 } 1029 1030 resource "azurerm_storage_account" "test" { 1031 name = "accsa%d" 1032 resource_group_name = "${azurerm_resource_group.test.name}" 1033 location = "southcentralus" 1034 account_type = "Standard_LRS" 1035 } 1036 1037 resource "azurerm_storage_container" "test" { 1038 name = "vhds" 1039 resource_group_name = "${azurerm_resource_group.test.name}" 1040 storage_account_name = "${azurerm_storage_account.test.name}" 1041 container_access_type = "private" 1042 } 1043 1044 resource "azurerm_virtual_machine_scale_set" "test" { 1045 name = "acctvmss-%d" 1046 location = "southcentralus" 1047 resource_group_name = "${azurerm_resource_group.test.name}" 1048 upgrade_policy_mode = "Manual" 1049 overprovision = false 1050 1051 sku { 1052 name = "Standard_D1_v2" 1053 tier = "Standard" 1054 capacity = 1 1055 } 1056 1057 os_profile { 1058 computer_name_prefix = "testvm-%d" 1059 admin_username = "myadmin" 1060 admin_password = "Passwword1234" 1061 } 1062 1063 network_profile { 1064 name = "TestNetworkProfile" 1065 primary = true 1066 ip_configuration { 1067 name = "TestIPConfiguration" 1068 subnet_id = "${azurerm_subnet.test.id}" 1069 } 1070 } 1071 1072 storage_profile_os_disk { 1073 name = "os-disk" 1074 caching = "ReadWrite" 1075 create_option = "FromImage" 1076 vhd_containers = [ "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}" ] 1077 } 1078 1079 storage_profile_image_reference { 1080 publisher = "Canonical" 1081 offer = "UbuntuServer" 1082 sku = "16.04-LTS" 1083 version = "latest" 1084 } 1085 } 1086 ` 1087 1088 var testAccAzureRMVirtualMachineScaleSetExtensionTemplate = ` 1089 resource "azurerm_resource_group" "test" { 1090 name = "acctestrg-%d" 1091 location = "southcentralus" 1092 } 1093 1094 resource "azurerm_virtual_network" "test" { 1095 name = "acctvn-%d" 1096 address_space = ["10.0.0.0/16"] 1097 location = "southcentralus" 1098 resource_group_name = "${azurerm_resource_group.test.name}" 1099 } 1100 1101 resource "azurerm_subnet" "test" { 1102 name = "acctsub-%d" 1103 resource_group_name = "${azurerm_resource_group.test.name}" 1104 virtual_network_name = "${azurerm_virtual_network.test.name}" 1105 address_prefix = "10.0.2.0/24" 1106 } 1107 1108 resource "azurerm_storage_account" "test" { 1109 name = "accsa%d" 1110 resource_group_name = "${azurerm_resource_group.test.name}" 1111 location = "southcentralus" 1112 account_type = "Standard_LRS" 1113 } 1114 1115 resource "azurerm_storage_container" "test" { 1116 name = "vhds" 1117 resource_group_name = "${azurerm_resource_group.test.name}" 1118 storage_account_name = "${azurerm_storage_account.test.name}" 1119 container_access_type = "private" 1120 } 1121 1122 resource "azurerm_virtual_machine_scale_set" "test" { 1123 name = "acctvmss-%d" 1124 location = "southcentralus" 1125 resource_group_name = "${azurerm_resource_group.test.name}" 1126 upgrade_policy_mode = "Manual" 1127 overprovision = false 1128 1129 sku { 1130 name = "Standard_D1_v2" 1131 tier = "Standard" 1132 capacity = 1 1133 } 1134 1135 os_profile { 1136 computer_name_prefix = "testvm-%d" 1137 admin_username = "myadmin" 1138 admin_password = "Passwword1234" 1139 } 1140 1141 network_profile { 1142 name = "TestNetworkProfile" 1143 primary = true 1144 ip_configuration { 1145 name = "TestIPConfiguration" 1146 subnet_id = "${azurerm_subnet.test.id}" 1147 } 1148 } 1149 1150 storage_profile_os_disk { 1151 name = "os-disk" 1152 caching = "ReadWrite" 1153 create_option = "FromImage" 1154 vhd_containers = [ "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}" ] 1155 } 1156 1157 storage_profile_image_reference { 1158 publisher = "Canonical" 1159 offer = "UbuntuServer" 1160 sku = "16.04-LTS" 1161 version = "latest" 1162 } 1163 1164 extension { 1165 name = "CustomScript" 1166 publisher = "Microsoft.Azure.Extensions" 1167 type = "CustomScript" 1168 type_handler_version = "2.0" 1169 auto_upgrade_minor_version = true 1170 settings = <<SETTINGS 1171 { 1172 "commandToExecute": "echo $HOSTNAME" 1173 } 1174 SETTINGS 1175 1176 protected_settings = <<SETTINGS 1177 { 1178 "storageAccountName": "${azurerm_storage_account.test.name}", 1179 "storageAccountKey": "${azurerm_storage_account.test.primary_access_key}" 1180 } 1181 SETTINGS 1182 } 1183 } 1184 ` 1185 1186 var testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate = ` 1187 resource "azurerm_resource_group" "test" { 1188 name = "acctestrg-%d" 1189 location = "southcentralus" 1190 } 1191 1192 resource "azurerm_virtual_network" "test" { 1193 name = "acctvn-%d" 1194 address_space = ["10.0.0.0/16"] 1195 location = "southcentralus" 1196 resource_group_name = "${azurerm_resource_group.test.name}" 1197 } 1198 1199 resource "azurerm_subnet" "test" { 1200 name = "acctsub-%d" 1201 resource_group_name = "${azurerm_resource_group.test.name}" 1202 virtual_network_name = "${azurerm_virtual_network.test.name}" 1203 address_prefix = "10.0.2.0/24" 1204 } 1205 1206 resource "azurerm_storage_account" "test" { 1207 name = "accsa%d" 1208 resource_group_name = "${azurerm_resource_group.test.name}" 1209 location = "southcentralus" 1210 account_type = "Standard_LRS" 1211 } 1212 1213 resource "azurerm_storage_container" "test" { 1214 name = "vhds" 1215 resource_group_name = "${azurerm_resource_group.test.name}" 1216 storage_account_name = "${azurerm_storage_account.test.name}" 1217 container_access_type = "private" 1218 } 1219 1220 resource "azurerm_virtual_machine_scale_set" "test" { 1221 name = "acctvmss-%d" 1222 location = "southcentralus" 1223 resource_group_name = "${azurerm_resource_group.test.name}" 1224 upgrade_policy_mode = "Manual" 1225 overprovision = false 1226 1227 sku { 1228 name = "Standard_D1_v2" 1229 tier = "Standard" 1230 capacity = 1 1231 } 1232 1233 os_profile { 1234 computer_name_prefix = "testvm-%d" 1235 admin_username = "myadmin" 1236 admin_password = "Passwword1234" 1237 } 1238 1239 network_profile { 1240 name = "TestNetworkProfile" 1241 primary = true 1242 ip_configuration { 1243 name = "TestIPConfiguration" 1244 subnet_id = "${azurerm_subnet.test.id}" 1245 } 1246 } 1247 1248 storage_profile_os_disk { 1249 name = "os-disk" 1250 caching = "ReadWrite" 1251 create_option = "FromImage" 1252 vhd_containers = [ "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}" ] 1253 } 1254 1255 storage_profile_image_reference { 1256 publisher = "Canonical" 1257 offer = "UbuntuServer" 1258 sku = "16.04-LTS" 1259 version = "latest" 1260 } 1261 1262 extension { 1263 name = "CustomScript" 1264 publisher = "Microsoft.Azure.Extensions" 1265 type = "CustomScript" 1266 type_handler_version = "2.0" 1267 auto_upgrade_minor_version = true 1268 settings = <<SETTINGS 1269 { 1270 "commandToExecute": "echo $HOSTNAME" 1271 } 1272 SETTINGS 1273 1274 protected_settings = <<SETTINGS 1275 { 1276 "storageAccountName": "${azurerm_storage_account.test.name}", 1277 "storageAccountKey": "${azurerm_storage_account.test.primary_access_key}" 1278 } 1279 SETTINGS 1280 } 1281 1282 extension { 1283 name = "Docker" 1284 publisher = "Microsoft.Azure.Extensions" 1285 type = "DockerExtension" 1286 type_handler_version = "1.0" 1287 auto_upgrade_minor_version = true 1288 } 1289 } 1290 ` 1291 1292 var testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict = ` 1293 resource "azurerm_resource_group" "test" { 1294 name = "acctestRG-%d" 1295 location = "West US 2" 1296 } 1297 1298 resource "azurerm_virtual_network" "test" { 1299 name = "acctvn-%d" 1300 address_space = ["10.0.0.0/16"] 1301 location = "West US 2" 1302 resource_group_name = "${azurerm_resource_group.test.name}" 1303 } 1304 1305 resource "azurerm_subnet" "test" { 1306 name = "acctsub-%d" 1307 resource_group_name = "${azurerm_resource_group.test.name}" 1308 virtual_network_name = "${azurerm_virtual_network.test.name}" 1309 address_prefix = "10.0.2.0/24" 1310 } 1311 1312 resource "azurerm_network_interface" "test" { 1313 name = "acctni-%d" 1314 location = "West US 2" 1315 resource_group_name = "${azurerm_resource_group.test.name}" 1316 1317 ip_configuration { 1318 name = "testconfiguration1" 1319 subnet_id = "${azurerm_subnet.test.id}" 1320 private_ip_address_allocation = "dynamic" 1321 } 1322 } 1323 1324 resource "azurerm_virtual_machine_scale_set" "test" { 1325 name = "acctvmss-%d" 1326 location = "West US 2" 1327 resource_group_name = "${azurerm_resource_group.test.name}" 1328 upgrade_policy_mode = "Manual" 1329 1330 sku { 1331 name = "Standard_D1_v2" 1332 tier = "Standard" 1333 capacity = 2 1334 } 1335 1336 os_profile { 1337 computer_name_prefix = "testvm-%d" 1338 admin_username = "myadmin" 1339 admin_password = "Passwword1234" 1340 } 1341 1342 network_profile { 1343 name = "TestNetworkProfile-%d" 1344 primary = true 1345 ip_configuration { 1346 name = "TestIPConfiguration" 1347 subnet_id = "${azurerm_subnet.test.id}" 1348 } 1349 } 1350 1351 storage_profile_os_disk { 1352 name = "" 1353 caching = "ReadWrite" 1354 create_option = "FromImage" 1355 managed_disk_type = "Standard_LRS" 1356 vhd_containers = ["should_cause_conflict"] 1357 } 1358 1359 storage_profile_image_reference { 1360 publisher = "Canonical" 1361 offer = "UbuntuServer" 1362 sku = "16.04-LTS" 1363 version = "latest" 1364 } 1365 } 1366 ` 1367 1368 var testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplateManagedDataDisks = ` 1369 resource "azurerm_resource_group" "test" { 1370 name = "acctestrg-%d" 1371 location = "southcentralus" 1372 } 1373 resource "azurerm_virtual_network" "test" { 1374 name = "acctvn-%d" 1375 address_space = ["10.0.0.0/16"] 1376 location = "southcentralus" 1377 resource_group_name = "${azurerm_resource_group.test.name}" 1378 } 1379 resource "azurerm_subnet" "test" { 1380 name = "acctsub-%d" 1381 resource_group_name = "${azurerm_resource_group.test.name}" 1382 virtual_network_name = "${azurerm_virtual_network.test.name}" 1383 address_prefix = "10.0.2.0/24" 1384 } 1385 resource "azurerm_lb" "test" { 1386 name = "acctestlb-%d" 1387 location = "southcentralus" 1388 resource_group_name = "${azurerm_resource_group.test.name}" 1389 frontend_ip_configuration { 1390 name = "default" 1391 subnet_id = "${azurerm_subnet.test.id}" 1392 private_ip_address_allocation = "Dynamic" 1393 } 1394 } 1395 resource "azurerm_lb_backend_address_pool" "test" { 1396 name = "test" 1397 resource_group_name = "${azurerm_resource_group.test.name}" 1398 loadbalancer_id = "${azurerm_lb.test.id}" 1399 } 1400 resource "azurerm_virtual_machine_scale_set" "test" { 1401 name = "acctvmss-%d" 1402 location = "southcentralus" 1403 resource_group_name = "${azurerm_resource_group.test.name}" 1404 upgrade_policy_mode = "Manual" 1405 sku { 1406 name = "Standard_A0" 1407 tier = "Standard" 1408 capacity = 1 1409 } 1410 os_profile { 1411 computer_name_prefix = "testvm-%d" 1412 admin_username = "myadmin" 1413 admin_password = "Passwword1234" 1414 } 1415 network_profile { 1416 name = "TestNetworkProfile" 1417 primary = true 1418 ip_configuration { 1419 name = "TestIPConfiguration" 1420 subnet_id = "${azurerm_subnet.test.id}" 1421 load_balancer_backend_address_pool_ids = [ "${azurerm_lb_backend_address_pool.test.id}" ] 1422 } 1423 } 1424 1425 storage_profile_os_disk { 1426 name = "" 1427 caching = "ReadWrite" 1428 create_option = "FromImage" 1429 managed_disk_type = "Standard_LRS" 1430 } 1431 1432 storage_profile_data_disk { 1433 lun = 0 1434 caching = "ReadWrite" 1435 create_option = "Empty" 1436 disk_size_gb = 10 1437 managed_disk_type = "Standard_LRS" 1438 } 1439 1440 storage_profile_image_reference { 1441 publisher = "Canonical" 1442 offer = "UbuntuServer" 1443 sku = "16.04.0-LTS" 1444 version = "latest" 1445 } 1446 } 1447 ` 1448 1449 func testAccAzureRMVirtualMachineScaleSetNonStandardCasing(ri int) string { 1450 return fmt.Sprintf(` 1451 resource "azurerm_resource_group" "test" { 1452 name = "acctestRG-%d" 1453 location = "West US 2" 1454 } 1455 resource "azurerm_virtual_network" "test" { 1456 name = "acctvn-%d" 1457 address_space = ["10.0.0.0/16"] 1458 location = "West US 2" 1459 resource_group_name = "${azurerm_resource_group.test.name}" 1460 } 1461 resource "azurerm_subnet" "test" { 1462 name = "acctsub-%d" 1463 resource_group_name = "${azurerm_resource_group.test.name}" 1464 virtual_network_name = "${azurerm_virtual_network.test.name}" 1465 address_prefix = "10.0.2.0/24" 1466 } 1467 resource "azurerm_network_interface" "test" { 1468 name = "acctni-%d" 1469 location = "West US 2" 1470 resource_group_name = "${azurerm_resource_group.test.name}" 1471 ip_configuration { 1472 name = "testconfiguration1" 1473 subnet_id = "${azurerm_subnet.test.id}" 1474 private_ip_address_allocation = "dynamic" 1475 } 1476 } 1477 resource "azurerm_storage_account" "test" { 1478 name = "accsa%d" 1479 resource_group_name = "${azurerm_resource_group.test.name}" 1480 location = "westus2" 1481 account_type = "Standard_LRS" 1482 tags { 1483 environment = "staging" 1484 } 1485 } 1486 resource "azurerm_storage_container" "test" { 1487 name = "vhds" 1488 resource_group_name = "${azurerm_resource_group.test.name}" 1489 storage_account_name = "${azurerm_storage_account.test.name}" 1490 container_access_type = "private" 1491 } 1492 resource "azurerm_virtual_machine_scale_set" "test" { 1493 name = "acctvmss-%d" 1494 location = "West US 2" 1495 resource_group_name = "${azurerm_resource_group.test.name}" 1496 upgrade_policy_mode = "Manual" 1497 sku { 1498 name = "Standard_A0" 1499 tier = "standard" 1500 capacity = 2 1501 } 1502 os_profile { 1503 computer_name_prefix = "testvm-%d" 1504 admin_username = "myadmin" 1505 admin_password = "Passwword1234" 1506 } 1507 network_profile { 1508 name = "TestNetworkProfile-%d" 1509 primary = true 1510 ip_configuration { 1511 name = "TestIPConfiguration" 1512 subnet_id = "${azurerm_subnet.test.id}" 1513 } 1514 } 1515 storage_profile_os_disk { 1516 name = "osDiskProfile" 1517 caching = "ReadWrite" 1518 create_option = "FromImage" 1519 vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"] 1520 } 1521 storage_profile_image_reference { 1522 publisher = "Canonical" 1523 offer = "UbuntuServer" 1524 sku = "14.04.2-LTS" 1525 version = "latest" 1526 } 1527 } 1528 `, ri, ri, ri, ri, ri, ri, ri, ri) 1529 }