Skip to content

Commit

Permalink
azurerm_virtual_machine_scale_set - prevent `public_ip_address_… (#3767)
Browse files Browse the repository at this point in the history
This commit is fixing #3763 when we perform a simple update on an existing scale-set the definition of the scale-set was changed on the publicIPAddressConfiguration field.
  • Loading branch information
alexsapran authored and katbyte committed Jul 3, 2019
1 parent d49fe40 commit e8087db
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 5 deletions.
18 changes: 13 additions & 5 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -1326,13 +1326,21 @@ func flattenAzureRmVirtualMachineScaleSetNetworkProfile(profile *compute.Virtual
config["primary"] = *properties.Primary
}

if properties.PublicIPAddressConfiguration != nil {
publicIpInfo := properties.PublicIPAddressConfiguration
if publicIpInfo := properties.PublicIPAddressConfiguration; publicIpInfo != nil {
publicIpConfigs := make([]map[string]interface{}, 0, 1)
publicIpConfig := make(map[string]interface{})
publicIpConfig["name"] = *publicIpInfo.Name
publicIpConfig["domain_name_label"] = *publicIpInfo.VirtualMachineScaleSetPublicIPAddressConfigurationProperties.DNSSettings
publicIpConfig["idle_timeout"] = *publicIpInfo.VirtualMachineScaleSetPublicIPAddressConfigurationProperties.IdleTimeoutInMinutes
if publicIpName := publicIpInfo.Name; publicIpName != nil {
publicIpConfig["name"] = *publicIpName
}
if publicIpProperties := publicIpInfo.VirtualMachineScaleSetPublicIPAddressConfigurationProperties; publicIpProperties != nil {
if dns := publicIpProperties.DNSSettings; dns != nil {
publicIpConfig["domain_name_label"] = *dns.DomainNameLabel
}
if timeout := publicIpProperties.IdleTimeoutInMinutes; timeout != nil {
publicIpConfig["idle_timeout"] = *timeout
}
publicIpConfigs = append(publicIpConfigs, publicIpConfig)
}
config["public_ip_address_configuration"] = publicIpConfigs
}

Expand Down
222 changes: 222 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,36 @@ func TestAccAzureRMVirtualMachineScaleSet_basicPublicIP(t *testing.T) {
})
}

func TestUnitAzureRMVirtualMachineScaleSet_basicPublicIP_simpleUpdate(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := tf.AccRandTimeInt()
location := testLocation()
config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(ri, location)
updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updated_tags(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),
testCheckAzureRMVirtualMachineScaleSetIsPrimary(resourceName, true),
testCheckAzureRMVirtualMachineScaleSetPublicIPName(resourceName, "TestPublicIPConfiguration"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetPublicIPName(resourceName, "TestPublicIPConfiguration"),
),
},
},
})
}

func TestAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -1721,6 +1751,198 @@ resource "azurerm_virtual_machine_scale_set" "test" {
`, rInt, location)
}

func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(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-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_basicEmptyPublicIP_updated_tags(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"
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_basicApplicationSecurity(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit e8087db

Please sign in to comment.