Skip to content

Commit

Permalink
Add var.tags to OS-disk (#32)
Browse files Browse the repository at this point in the history
* Add workaround for OS-disk tags

Signed-off-by: Melody Sofia Eroshevich <se@cloudeteer.de>

* Add workaround for OS-disk tags

Signed-off-by: Melody Sofia Eroshevich <se@cloudeteer.de>

* Add workaround for OS-disk tags

Signed-off-by: Melody Sofia Eroshevich <se@cloudeteer.de>

* Add workaround for OS-disk tags

Signed-off-by: Melody Sofia Eroshevich <se@cloudeteer.de>

* Add validation for hotpatching_enabled

Signed-off-by: Melody Sofia Eroshevich <se@cloudeteer.de>

---------

Signed-off-by: Melody Sofia Eroshevich <se@cloudeteer.de>
  • Loading branch information
neonwhiskers authored Sep 25, 2024
1 parent 56d1052 commit 756f9ee
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ The following providers are used by this module:

The following resources are used by this module:

- [azapi_resource_action.this](https://registry.terraform.io/providers/azure/azapi/latest/docs/resources/resource_action) (resource)
- [azurerm_backup_protected_vm.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/backup_protected_vm) (resource)
- [azurerm_key_vault_secret.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) (resource)
- [azurerm_linux_virtual_machine.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) (resource)
Expand All @@ -139,6 +140,7 @@ The following resources are used by this module:
- [azapi_client_config.current](https://registry.terraform.io/providers/azure/azapi/latest/docs/data-sources/client_config) (data source)
- [azapi_resource.virtual_machine_image](https://registry.terraform.io/providers/azure/azapi/latest/docs/data-sources/resource) (data source)
- [azapi_resource_list.virtual_machine_images](https://registry.terraform.io/providers/azure/azapi/latest/docs/data-sources/resource_list) (data source)
- [azurerm_managed_disk.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/managed_disk) (data source)

## Required Inputs

Expand Down Expand Up @@ -463,6 +465,8 @@ Description: Should the Windows VM be patched without requiring a reboot? [more

**NOTE**: Hotpatching can only be enabled if the `patch_mode` is set to `AutomaticByPlatform`, the `provision_vm_agent` is set to `true`, your `source_image_reference` references a hotpatching enabled image, and the VM's `size` is set to a [Azure generation 2 VM](https://learn.microsoft.com/en-gb/azure/virtual-machines/generation-2#generation-2-vm-sizes).

**CAUTION**: The setting `bypass_platform_safety_checks_on_user_schedule_enabled` is set to `true` by default. To enable hotpatching, change it to `false`.

Type: `bool`

Default: `false`
Expand Down
15 changes: 15 additions & 0 deletions r-vm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,18 @@ resource "azurerm_windows_virtual_machine" "this" {
]
}
}

data "azurerm_managed_disk" "this" {
name = local.virtual_machine.os_disk[0].name
resource_group_name = var.resource_group_name
}

resource "azapi_resource_action" "this" {
type = "Microsoft.Compute/disks@2024-03-02"
resource_id = data.azurerm_managed_disk.this.id
method = "PATCH"

body = {
tags = var.tags
}
}
5 changes: 5 additions & 0 deletions tests/examples/mocks/azurerm_managed_disk.tfmock.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mock_data "azurerm_managed_disk" {
defaults = {
id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RG-MOCK/providers/Microsoft.Compute/disks/DISK-MOCK"
}
}
5 changes: 5 additions & 0 deletions tests/local/mocks/azurerm_managed_disk.tfmock.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mock_data "azurerm_managed_disk" {
defaults = {
id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RG-MOCK/providers/Microsoft.Compute/disks/DISK-MOCK"
}
}
2 changes: 2 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ variable "hotpatching_enabled" {
Should the Windows VM be patched without requiring a reboot? [more infos](https://learn.microsoft.com/windows-server/get-started/hotpatch)
**NOTE**: Hotpatching can only be enabled if the `patch_mode` is set to `AutomaticByPlatform`, the `provision_vm_agent` is set to `true`, your `source_image_reference` references a hotpatching enabled image, and the VM's `size` is set to a [Azure generation 2 VM](https://learn.microsoft.com/en-gb/azure/virtual-machines/generation-2#generation-2-vm-sizes).
**CAUTION**: The setting `bypass_platform_safety_checks_on_user_schedule_enabled` is set to `true` by default. To enable hotpatching, change it to `false`.
EOT

type = bool
Expand Down

0 comments on commit 756f9ee

Please sign in to comment.