Skip to content

Commit

Permalink
Add acceptance tests that demonstrate the problem
Browse files Browse the repository at this point in the history
The acceptance tests added here are describing the issue as reported by
this ticket terraform-providers/terraform-provider-azurerm/hashicorp#3812
  • Loading branch information
alexsapran committed Jul 10, 2019
1 parent c80b021 commit e2844c4
Showing 1 changed file with 301 additions and 4 deletions.
305 changes: 301 additions & 4 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,67 @@ func TestUnitAzureRMVirtualMachineScaleSet_basicPublicIP_simpleUpdate(t *testing
})
}

func TestUnitAzureRMVirtualMachineScaleSet_updateNetworkProfile(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := tf.AccRandTimeInt()
location := testLocation()
config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(ri, location)
updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyNetworkProfile_true_ipforwarding(ri, location)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
testCheckAzureRMVirtualMachineScaleSetIPForwarding(resourceName, false),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetIPForwarding(resourceName, true),
),
},
},
})
}

func TestUnitAzureRMVirtualMachineScaleSet_updateNetworkProfile_ipconfiguration_dns_name_label(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := tf.AccRandTimeInt()
location := testLocation()
config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(ri, location)
updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updatedDNS_label(ri, location)

expectedDNS := fmt.Sprintf("test-domain-label-%[1]d", ri)
updatedDNS := fmt.Sprintf("test-updated-domain-label-%[1]d", ri)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
testCheckAzureRMVirtualMachineScaleSetDomainNameLabel(resourceName, expectedDNS),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetDomainNameLabel(resourceName, updatedDNS),
),
},
},
})
}

func TestAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -1266,6 +1327,49 @@ func testCheckAzureRMVirtualMachineScaleSetAcceleratedNetworking(name string, bo
}
}

func testCheckAzureRMVirtualMachineScaleSetIPForwarding(name string, boolean bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
resp, err := testGetAzureRMVirtualMachineScaleSet(s, name)
if err != nil {
return err
}

n := resp.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations
if n == nil || len(*n) == 0 {
return fmt.Errorf("Bad: Could not get network interface configurations for scale set %v", name)
}

ipForwarding := *(*n)[0].EnableIPForwarding
if ipForwarding != boolean {
return fmt.Errorf("Bad: Primary set incorrectly for scale set %v\n Wanted: %+v Received: %+v", name, boolean, ipForwarding)
}

return nil
}
}

func testCheckAzureRMVirtualMachineScaleSetDomainNameLabel(name string, expected string) resource.TestCheckFunc {
return func(s *terraform.State) error {
resp, err := testGetAzureRMVirtualMachineScaleSet(s, name)
if err != nil {
return err
}

n := resp.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations
if n == nil || len(*n) == 0 {
return fmt.Errorf("Bad: Could not get network interface configurations for scale set %v", name)
}

ipconfig := *(*n)[0].IPConfigurations
dnsLabel := *ipconfig[0].PublicIPAddressConfiguration.DNSSettings.DomainNameLabel
if dnsLabel != expected {
return fmt.Errorf("Bad: Primary set incorrectly for scale set %v\n Wanted: %+v Received: %+v", name, expected, dnsLabel)
}

return nil
}
}

func testCheckAzureRMVirtualMachineScaleSetOverprovision(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
resp, err := testGetAzureRMVirtualMachineScaleSet(s, name)
Expand Down Expand Up @@ -1796,11 +1900,11 @@ resource "azurerm_virtual_machine_scale_set" "test" {
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
tags = {
state = "create"
}
sku {
name = "Standard_D1_v2"
tier = "Standard"
Expand Down Expand Up @@ -1892,11 +1996,107 @@ resource "azurerm_virtual_machine_scale_set" "test" {
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
tags = {
state = "update"
}
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 0
}
os_profile {
computer_name_prefix = "testvm-%[1]d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile-%[1]d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
primary = true
public_ip_address_configuration {
name = "TestPublicIPConfiguration"
domain_name_label = "test-domain-label-%[1]d"
idle_timeout = 4
}
}
}
storage_profile_os_disk {
name = "osDiskProfile"
caching = "ReadWrite"
create_option = "FromImage"
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
`, rInt, location)
}

func testAccAzureRMVirtualMachineScaleSet_basicEmptyNetworkProfile_true_ipforwarding(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%[1]d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%[1]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_storage_account" "test" {
name = "accsa%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "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-%[1]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
tags = {
state = "update"
}
sku {
name = "Standard_D1_v2"
tier = "Standard"
Expand All @@ -1912,6 +2112,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
network_profile {
name = "TestNetworkProfile-%[1]d"
primary = true
ip_forwarding = true
ip_configuration {
name = "TestIPConfiguration"
Expand Down Expand Up @@ -1943,6 +2144,102 @@ resource "azurerm_virtual_machine_scale_set" "test" {
`, rInt, location)
}

func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updatedDNS_label(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%[1]d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%[1]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_storage_account" "test" {
name = "accsa%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "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-%[1]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
tags = {
state = "create"
}
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 0
}
os_profile {
computer_name_prefix = "testvm-%[1]d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile-%[1]d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
primary = true
public_ip_address_configuration {
name = "TestPublicIPConfiguration"
domain_name_label = "test-updated-domain-label-%[1]d"
idle_timeout = 4
}
}
}
storage_profile_os_disk {
name = "osDiskProfile"
caching = "ReadWrite"
create_option = "FromImage"
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
`, rInt, location)
}

func testAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit e2844c4

Please sign in to comment.