Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_linux_virtual_machine_scale_set, azurerm_windows_virtual_machine_scale_set - add public_ip_prefix_id when patching the VMSS #24939

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ func TestAccLinuxVirtualMachineScaleSet_networkPublicIPFromPrefix(t *testing.T)
),
},
data.ImportStep("admin_password"),
{
Config: r.networkPublicIPFromPrefixUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
})
}

Expand Down Expand Up @@ -1603,8 +1610,62 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
subnet_id = azurerm_subnet.test.id

public_ip_address {
name = "first"
public_ip_prefix_id = azurerm_public_ip_prefix.test.id
name = "first"
idle_timeout_in_minutes = 4
public_ip_prefix_id = azurerm_public_ip_prefix.test.id
}
}
}
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r LinuxVirtualMachineScaleSetResource) networkPublicIPFromPrefixUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_public_ip_prefix" "test" {
name = "acctestpublicipprefix-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_linux_virtual_machine_scale_set" "test" {
name = "acctestvmss-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "Standard_F2"
instances = 1
admin_username = "adminuser"
admin_password = "P@ssword1234!"

disable_password_authentication = false

source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts"
version = "latest"
}

os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}

network_interface {
name = "primary"
primary = true

ip_configuration {
name = "first"
primary = true
subnet_id = azurerm_subnet.test.id

public_ip_address {
name = "first"
idle_timeout_in_minutes = 5
public_ip_prefix_id = azurerm_public_ip_prefix.test.id
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions internal/services/compute/virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,12 @@ func expandVirtualMachineScaleSetPublicIPAddressUpdate(raw map[string]interface{
publicIPAddressConfig.VirtualMachineScaleSetUpdatePublicIPAddressConfigurationProperties.IdleTimeoutInMinutes = utils.Int32(int32(raw["idle_timeout_in_minutes"].(int)))
}

if publicIPPrefixID := raw["public_ip_prefix_id"].(string); publicIPPrefixID != "" {
publicIPAddressConfig.VirtualMachineScaleSetUpdatePublicIPAddressConfigurationProperties.PublicIPPrefix = &compute.SubResource{
ID: utils.String(publicIPPrefixID),
}
}

return &publicIPAddressConfig
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ func TestAccWindowsVirtualMachineScaleSet_networkPublicIPFromPrefix(t *testing.T
),
},
data.ImportStep("admin_password"),
{
Config: r.networkPublicIPFromPrefixUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
})
}

Expand Down Expand Up @@ -1566,8 +1573,60 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" {
subnet_id = azurerm_subnet.test.id

public_ip_address {
name = "first"
public_ip_prefix_id = azurerm_public_ip_prefix.test.id
name = "first"
idle_timeout_in_minutes = 4
public_ip_prefix_id = azurerm_public_ip_prefix.test.id
}
}
}
}
`, r.template(data), data.RandomInteger)
}

func (r WindowsVirtualMachineScaleSetResource) networkPublicIPFromPrefixUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_public_ip_prefix" "test" {
name = "acctestpublicipprefix-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_windows_virtual_machine_scale_set" "test" {
name = local.vm_name
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "Standard_F2"
instances = 1
admin_username = "adminuser"
admin_password = "P@ssword1234!"

source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}

os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}

network_interface {
name = "primary"
primary = true

ip_configuration {
name = "first"
primary = true
subnet_id = azurerm_subnet.test.id

public_ip_address {
name = "first"
idle_timeout_in_minutes = 5
public_ip_prefix_id = azurerm_public_ip_prefix.test.id
}
}
}
Expand Down
Loading