Skip to content

Commit

Permalink
Added support for patch_mode in resource_linux_virtual_machine.
Browse files Browse the repository at this point in the history
  • Loading branch information
atombrella committed Oct 22, 2021
1 parent a64ec86 commit b73d6d2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
15 changes: 15 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(compute.LinuxVMGuestPatchMode(v.(string))),
}
}

if v, ok := d.GetOk("license_type"); ok {
params.VirtualMachineProperties.LicenseType = utils.String(v.(string))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
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`. 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`.
Expand Down

0 comments on commit b73d6d2

Please sign in to comment.