Skip to content

fix: Set disk zone to null when creating ZRS disk#237

Merged
jchancellor-ms merged 2 commits into
Azure:v0.21.0-mergefrom
Rickmarges:patch-1
Jun 5, 2026
Merged

fix: Set disk zone to null when creating ZRS disk#237
jchancellor-ms merged 2 commits into
Azure:v0.21.0-mergefrom
Rickmarges:patch-1

Conversation

@Rickmarges
Copy link
Copy Markdown
Contributor

@Rickmarges Rickmarges commented Apr 10, 2026

Description

ZRS disks can't be created with an availablity zone. When a VM is created with the zone variable set to anything other than null, this value is also used for creating disk leading to errors.
This change will check for the presence of ZRS in the type string. If present, it will always set zone to null.

Fixes #236

Type of Change

  • Non-module change (e.g. CI/CD, documentation, etc.)
  • Azure Verified Module updates:
    • Bugfix containing backwards compatible bug fixes
      • Someone has opened a bug report issue, and I have included "Closes #{bug_report_issue_number}" in the PR description.
      • The bug was found by the module author, and no one has opened an issue to report it yet.
    • Feature update backwards compatible feature updates.
    • Breaking changes.
    • Update to documentation

Checklist

  • I'm sure there are no other open Pull Requests for the same update/change
  • My corresponding pipelines / checks run clean and green without any errors or warnings
  • I did run all pre-commit checks

ZRS disks can't be created with an availablity zone. When a VM is created with the zone variable set to anything other than `null`, this value is also used for creating disk leading to errors.
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs: Triage 🔍 Maintainers need to triage still label Apr 10, 2026
Copy link
Copy Markdown

@jtracey93 jtracey93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Rickmarges for the PR. Could you please add a new example or update one of the existing ones to test out the functionality you've added here around ZRS?

This way we know its working and also doesnt regress in future updates

Thanks

@Rickmarges Rickmarges requested a review from jtracey93 April 29, 2026 15:23
@jchancellor-ms jchancellor-ms changed the base branch from main to v0.21.0-merge June 5, 2026 20:18
@jchancellor-ms
Copy link
Copy Markdown
Contributor

Moving into a merge branch so we can run the tests.

@jchancellor-ms jchancellor-ms merged commit 810a61b into Azure:v0.21.0-merge Jun 5, 2026
3 checks passed
jchancellor-ms added a commit that referenced this pull request Jun 6, 2026
* gallery app and azapi fixes

* azapi and gallery app fixes

* interface spec updates

* lock and doc fixes

* test region updates

* version updates

* role_assignments aad_check default to false

* example and dependency updates

* sku_selector azapi version fix

* fix(vm): relax random provider constraint for cross-module compatibility (#245)

* fix(vm): relax random provider constraint for cross-module compatibility

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Bas Veenendaal <bas@novygate.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: accept gzipped base64 payloads in custom_data validation (#238)

* fix: accept gzipped base64 payloads in custom_data validation (#207)

* test: add example for gzipped and plaintext custom_data (#207)

---------

Co-authored-by: Martin Oehlert <453360+MO2k4@users.noreply.github.com>

* fix: Set disk zone to null when creating ZRS disk (#237)

* Set disk zone to null when creating ZRS disk

ZRS disks can't be created with an availablity zone. When a VM is created with the zone variable set to anything other than `null`, this value is also used for creating disk leading to errors.

* Add zonal vm with ZRS disk example

* feat: add os_managed_disk_id support for attaching existing managed disk as OS disk (#234)

* feat: add os_managed_disk_id support for attaching existing managed disk as OS disk

Add support for the os_managed_disk_id parameter on both azurerm_linux_virtual_machine
and azurerm_windows_virtual_machine resources, allowing users to create VMs from
existing managed disks (Attach mode).

Changes:
- variables.tf: Add os_managed_disk_id variable with format validation and mutual
  exclusivity check against source_image_resource_id
- locals.tf: Add os_disk_is_imported local for readability
- locals.auth.tf: Skip credential generation when os_managed_disk_id is set
  (admin_username=null, no random password/SSH key generation)
- main.linux_vm.tf: Add os_managed_disk_id, conditionally null out ConflictsWith
  fields (admin_password, computer_name, custom_data, provision_vm_agent, patch_mode,
  patch_assessment_mode, bypass_platform_safety_checks, reboot_setting), update
  source_image_reference and admin_ssh_key conditions
- main.windows_vm.tf: Same as Linux plus Windows-specific ConflictsWith fields
  (enable_automatic_updates, hotpatching_enabled)

Provider behavior reference (azurerm_linux/windows_virtual_machine):
- os_managed_disk_id ExactlyOneOf: admin_username, source_image_id, source_image_reference
- ConflictsWith (shared): admin_password, computer_name, custom_data,
  provision_vm_agent, patch_mode, patch_assessment_mode,
  bypass_platform_safety_checks_on_user_schedule_enabled, reboot_setting
- ConflictsWith (Windows): hotpatching_enabled, enable_automatic_updates
- When set, Provider uses CreateOption=Attach and skips OsProfile

Closes #230

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore: run pre-commit to sync docs and mapotf ordering

* fix: harden os_managed_disk_id attach mode and add example

- Fix admin_password_linux/windows locals to return null when
  os_disk_is_imported, preventing random_password[0] resolution errors
- Fix password_secret_count and ssh_secret_count to return 0 when
  os_disk_is_imported, skipping unnecessary Key Vault secret creation
- Add lifecycle precondition to prevent os_managed_disk_id and
  os_disk.diff_disk_settings from being set simultaneously
- Add examples/linux_os_managed_disk/ for e2e test coverage of the
  attach-from-managed-disk path
- Update source_image_reference variable description to mention
  os_managed_disk_id mutual exclusivity
- Run pre-commit to sync docs and formatting

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: add os_disk_attach_mode variable for plan-time determinism

When os_managed_disk_id is set from a computed resource attribute (e.g.,
azurerm_managed_disk.example.id), Terraform cannot determine the null
check at plan time, causing 'count depends on resource attributes that
cannot be determined' errors.

Add os_disk_attach_mode (bool, default false) that users must set to
true alongside os_managed_disk_id. This ensures count expressions are
deterministic during planning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: guard SSH key and credential name locals for attach mode

- Add os_disk_is_imported check to admin_ssh_key local to skip SSH key
  generation when tls_private_key.this is empty in attach mode
- Add os_disk_is_imported check to admin_ssh_key_secret_value local
- Use coalesce(admin_username, 'imported') in credential secret names
  to prevent null string interpolation errors when admin_username is
  null in attach mode

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: null out os_disk.storage_account_type in attach mode

The AzureRM Provider enforces ConflictsWith between
os_disk.storage_account_type and os_managed_disk_id. When attaching
an existing managed disk, storage_account_type must be null since
the disk type is already determined by the existing disk.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* pre-commit clean-up

* deprecated hallucination

* var dup cleanup

* example lint fixes

* exception example update

* avssec for linux example

---------

Co-authored-by: Bas Veenendaal <bas@basveenendaal.com>
Co-authored-by: Bas Veenendaal <bas@novygate.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Martin Oehlert <mo1987@gmx.net>
Co-authored-by: Martin Oehlert <453360+MO2k4@users.noreply.github.com>
Co-authored-by: Rickmarges <rickmarges@gmail.com>
Co-authored-by: lonegunmanb <lonegunmanb@hotmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Triage 🔍 Maintainers need to triage still

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZRS disks fail with zonal VM due to forced zone assignment (OS disk included)[AVM Module Issue]:

3 participants