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

Added support for patch_mode in resource_linux_virtual_machine. #13866

Merged
merged 4 commits into from
Nov 3, 2021
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
21 changes: 21 additions & 0 deletions internal/services/compute/linux_virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(v.(string)),
}
}

if v, ok := d.GetOk("license_type"); ok {
params.VirtualMachineProperties.LicenseType = utils.String(v.(string))
}
Expand Down Expand Up @@ -930,6 +945,12 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface
}
}

if d.HasChange("patch_mode") {
update.VirtualMachineProperties.OsProfile.LinuxConfiguration.PatchSettings = &compute.LinuxPatchSettings{
PatchMode: compute.LinuxVMGuestPatchMode(d.Get("patch_mode").(string)),
}
}

if d.HasChange("allow_extension_operations") {
allowExtensionOperations := d.Get("allow_extension_operations").(bool)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ 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, "AutomaticByPlatform"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("patch_mode").HasValue("AutomaticByPlatform"),
),
},
{
Config: r.linuxPatchModeSetting(data, "ImageDefault"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("patch_mode").HasValue("ImageDefault"),
),
},
data.ImportStep(),
})
}

func (r LinuxVirtualMachineResource) authPassword(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -210,3 +233,39 @@ resource "azurerm_linux_virtual_machine" "test" {
}
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) linuxPatchModeSetting(data acceptance.TestData, patchMode string) 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,
]
patch_mode = "%s"

admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}

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

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "20.04-LTS"
version = "latest"
}
}
`, r.template(data), data.RandomInteger, patchMode)
}
2 changes: 2 additions & 0 deletions website/docs/r/linux_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`. 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`.
Expand Down