2016-06-11 00:37:14 +02:00
|
|
|
package azurerm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAzureRMVirtualMachineScaleSet_basicLinux(t *testing.T) {
|
|
|
|
ri := acctest.RandInt()
|
|
|
|
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basicLinux, ri, ri, ri, ri, ri, ri, ri, ri)
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: config,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
//func TestAccAzureRMVirtualMachineScaleSet_basicWindowsMachine(t *testing.T) {
|
|
|
|
// ri := acctest.RandInt()
|
|
|
|
// rs := acctest.RandString(6)
|
|
|
|
// config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basicWindows, ri, ri, ri, ri, ri, ri, rs, ri)
|
|
|
|
// resource.Test(t, resource.TestCase{
|
|
|
|
// PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
// Providers: testAccProviders,
|
|
|
|
// CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
|
|
|
|
// Steps: []resource.TestStep{
|
|
|
|
// {
|
|
|
|
// Config: config,
|
|
|
|
// Check: resource.ComposeTestCheckFunc(
|
|
|
|
// testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
|
|
|
|
// ),
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//}
|
2016-06-11 00:37:14 +02:00
|
|
|
|
|
|
|
func testCheckAzureRMVirtualMachineScaleSetExists(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
// Ensure we have enough information in state to look up in API
|
|
|
|
rs, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
|
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
|
|
if !hasResourceGroup {
|
|
|
|
return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
|
|
|
|
|
|
|
|
resp, err := conn.Get(resourceGroup, name)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Bad: Get on vmScaleSetClient: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode == http.StatusNotFound {
|
|
|
|
return fmt.Errorf("Bad: VirtualMachineScaleSet %q (resource group: %q) does not exist", name, resourceGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCheckAzureRMVirtualMachineScaleSetDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "azurerm_virtual_machine_scale_set" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
|
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
|
|
|
|
|
|
resp, err := conn.Get(resourceGroup, name)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusNotFound {
|
|
|
|
return fmt.Errorf("Virtual Machine Scale Set still exists:\n%#v", resp.Properties)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAccAzureRMVirtualMachineScaleSet_basicLinux = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acctestrg-%d"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_network" "test" {
|
|
|
|
name = "acctvn-%d"
|
|
|
|
address_space = ["10.0.0.0/16"]
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_subnet" "test" {
|
|
|
|
name = "acctsub-%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
virtual_network_name = "${azurerm_virtual_network.test.name}"
|
|
|
|
address_prefix = "10.0.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_interface" "test" {
|
|
|
|
name = "acctni-%d"
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
|
|
|
|
ip_configuration {
|
|
|
|
name = "testconfiguration1"
|
|
|
|
subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
private_ip_address_allocation = "dynamic"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_storage_account" "test" {
|
|
|
|
name = "accsa%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
location = "westus"
|
|
|
|
account_type = "Standard_LRS"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
environment = "staging"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_storage_container" "test" {
|
|
|
|
name = "vhds"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
storage_account_name = "${azurerm_storage_account.test.name}"
|
|
|
|
container_access_type = "private"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_machine_scale_set" "test" {
|
|
|
|
name = "acctvmss-%d"
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
upgrade_policy_mode = "Manual"
|
|
|
|
|
|
|
|
sku {
|
|
|
|
name = "Standard_A0"
|
|
|
|
tier = "Standard"
|
|
|
|
capacity = 2
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
os_profile {
|
2016-06-11 00:37:14 +02:00
|
|
|
computer_name_prefix = "testvm-%d"
|
|
|
|
admin_username = "myadmin"
|
|
|
|
admin_password = "Passwword1234"
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
network_profile {
|
2016-06-11 00:37:14 +02:00
|
|
|
name = "TestNetworkProfile-%d"
|
|
|
|
primary = true
|
|
|
|
ip_configuration {
|
|
|
|
name = "TestIPConfiguration"
|
|
|
|
subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
storage_profile_os_disk {
|
2016-06-11 00:37:14 +02:00
|
|
|
name = "osDiskProfile"
|
|
|
|
caching = "ReadWrite"
|
|
|
|
create_option = "FromImage"
|
|
|
|
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
storage_profile_image_reference {
|
2016-06-11 00:37:14 +02:00
|
|
|
publisher = "Canonical"
|
|
|
|
offer = "UbuntuServer"
|
|
|
|
sku = "14.04.2-LTS"
|
|
|
|
version = "latest"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAzureRMVirtualMachineScaleSet_basicWindows = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acctestrg-%d"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_network" "test" {
|
|
|
|
name = "acctvn-%d"
|
|
|
|
address_space = ["10.0.0.0/16"]
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_subnet" "test" {
|
|
|
|
name = "acctsub-%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
virtual_network_name = "${azurerm_virtual_network.test.name}"
|
|
|
|
address_prefix = "10.0.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_interface" "test" {
|
|
|
|
name = "acctni-%d"
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
|
|
|
|
ip_configuration {
|
|
|
|
name = "testconfiguration1"
|
|
|
|
subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
private_ip_address_allocation = "dynamic"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_storage_account" "test" {
|
|
|
|
name = "accsa%d"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
location = "westus"
|
|
|
|
account_type = "Standard_LRS"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
environment = "staging"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_storage_container" "test" {
|
|
|
|
name = "vhds"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
storage_account_name = "${azurerm_storage_account.test.name}"
|
|
|
|
container_access_type = "private"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_machine_scale_set" "test" {
|
|
|
|
name = "acctvmss-%d"
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
upgrade_policy_mode = "Manual"
|
|
|
|
|
|
|
|
sku {
|
|
|
|
name = "Standard_A0"
|
|
|
|
tier = "Standard"
|
|
|
|
capacity = 2
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
os_profile {
|
2016-06-11 00:37:14 +02:00
|
|
|
computer_name_prefix = "vm-%s"
|
|
|
|
admin_username = "myadmin"
|
|
|
|
admin_password = "Passwword1234"
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
network_profile {
|
2016-06-11 00:37:14 +02:00
|
|
|
name = "TestNetworkProfile-%d"
|
|
|
|
primary = true
|
|
|
|
ip_configuration {
|
|
|
|
name = "TestIPConfiguration"
|
|
|
|
subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
storage_profile_os_disk {
|
2016-06-11 00:37:14 +02:00
|
|
|
name = "osDiskProfile"
|
|
|
|
caching = "ReadWrite"
|
|
|
|
create_option = "FromImage"
|
|
|
|
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
|
|
|
|
}
|
|
|
|
|
2016-06-11 10:12:20 +02:00
|
|
|
storage_profile_image_reference {
|
2016-06-11 00:37:14 +02:00
|
|
|
publisher = "MicrosoftWindowsServer"
|
|
|
|
offer = "WindowsServer"
|
|
|
|
sku = "2012-R2-Datacenter"
|
|
|
|
version = "4.0.20160518"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|