Skip to content

[AVM Module Issue]: suggestion to specify a backup vault in another subscription #132

Open
@kewalaka

Description

@kewalaka

Check for previous/existing GitHub issues

  • I have checked for previous/existing GitHub issues

Issue Type?

Feature Request

(Optional) Module Version

v0.17.0

(Optional) Correlation Id

No response

Description

Some organisations centralise their recovery services vaults in a different subscription to VMs. The AzureRM provider doesn't provide an easy way to do this unless using additional provider blocks.

What do you think to the idea of using AzAPI to achieve this?

Sample approach illustrating the use case where it will use the current sub & RG by default:

locals {
  subscription_id      = coalesce(var.rsv_subscription_id, data.azurerm_client_config.current.subscription_id)
  resource_group_name  = coalesce(var.rsv_resource_group_name, var.resource_group_name)
  parent_id            = "/subscriptions/${local.subscription_id}/resourceGroups/${local.resource_group_name}/providers/Microsoft.RecoveryServices/vaults/${each.value.recovery_vault_name}"
}

resource "azapi_resource" "this" {
  for_each = var.azure_backup_configurations

  type      = "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems@2024-04-01"
  name      = each.key
  parent_id = local.parent_id
  body = {
    properties = {
      protectedItemType = "Microsoft.Compute/virtualMachines"
      sourceResourceId  = local.virtualmachine_resource_id
      policyId          = each.value.backup_policy_resource_id
      protectionState   = each.value.protection_state
      diskExclusionProperties = {
        excludeDisks = {
          diskLunList = each.value.exclude_disk_luns
        }
        includeDisks = {
          diskLunList = each.value.include_disk_luns
        }
      }
    }
  }

  depends_on = [
    azurerm_virtual_machine_data_disk_attachment.this_linux,
    azurerm_virtual_machine_data_disk_attachment.this_windows
  ]
}

variable "rsv_subscription_id" {
  description = "Optional subscription ID for the Recovery Services Vault."
  type        = string
  default     = null
}

variable "rsv_resource_group_name" {
  description = "Optional resource group name for the Recovery Services Vault."
  type        = string
  default     = null
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions