diff --git a/internal/services/compute/linux_virtual_machine_resource.go b/internal/services/compute/linux_virtual_machine_resource.go index 41a74dd6c7e49..4d9ed1072bd66 100644 --- a/internal/services/compute/linux_virtual_machine_resource.go +++ b/internal/services/compute/linux_virtual_machine_resource.go @@ -211,6 +211,15 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource { ForceNew: true, }, + "patch_mode": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(compute.LinuxVMGuestPatchModeAutomaticByPlatform), + string(compute.LinuxVMGuestPatchModeImageDefault), + }, false), + }, + "proximity_placement_group_id": { Type: pluginsdk.TypeString, Optional: true, @@ -416,6 +425,12 @@ func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface Tags: tags.Expand(t), } + if v, ok := d.GetOk("patch_mode"); ok { + params.VirtualMachineProperties.OsProfile.LinuxConfiguration.PatchSettings = &compute.LinuxPatchSettings{ + PatchMode: compute.LinuxVMGuestPatchMode(compute.LinuxVMGuestPatchMode(v.(string))), + } + } + if v, ok := d.GetOk("license_type"); ok { params.VirtualMachineProperties.LicenseType = utils.String(v.(string)) } diff --git a/internal/services/compute/linux_virtual_machine_resource_auth_test.go b/internal/services/compute/linux_virtual_machine_resource_auth_test.go index 4254fd248f633..72ce3dc0a7c49 100644 --- a/internal/services/compute/linux_virtual_machine_resource_auth_test.go +++ b/internal/services/compute/linux_virtual_machine_resource_auth_test.go @@ -72,6 +72,21 @@ func TestAccLinuxVirtualMachine_authSSHMultipleKeys(t *testing.T) { }) } +func TestAccLinuxVirtualMachine_linuxPatchModeSetting(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") + r := LinuxVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.linuxPatchModeSetting(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (r LinuxVirtualMachineResource) authPassword(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -210,3 +225,35 @@ resource "azurerm_linux_virtual_machine" "test" { } `, r.template(data), data.RandomInteger) } + +func (r LinuxVirtualMachineResource) linuxPatchModeSetting(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + admin_password = "password1234!" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + patch_mode = "AutomaticByOS" +} +`, r.template(data), data.RandomInteger) +} diff --git a/website/docs/r/linux_virtual_machine.html.markdown b/website/docs/r/linux_virtual_machine.html.markdown index f9afeba995c88..4c82489770964 100644 --- a/website/docs/r/linux_virtual_machine.html.markdown +++ b/website/docs/r/linux_virtual_machine.html.markdown @@ -152,6 +152,8 @@ The following arguments are supported: * `identity` - (Optional) An `identity` block as defined below. +* `patch_mode` - (Optional) Specifies the mode of in-guest patching to this Linux Virtual Machine. Possible values are `AutomaticByPlatform` and `ImageDefault`. Changing this forces a new resource to be created. Defaults to `ImageDefault`. + * `max_bid_price` - (Optional) The maximum price you're willing to pay for this Virtual Machine, in US Dollars; which must be greater than the current spot price. If this bid price falls below the current spot price the Virtual Machine will be evicted using the `eviction_policy`. Defaults to `-1`, which means that the Virtual Machine should not be evicted for price reasons. -> **NOTE:** This can only be configured when `priority` is set to `Spot`.