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

Add backups to workspaces. #4374

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ ENHANCEMENTS:
* Add bundle target to Makefile for handling different bundle types in single command ([#4372](https://github.com/microsoft/AzureTRE/issues/4372))
* Migrate UI to Vite build engine and update dependencies ([#4368](https://github.com/microsoft/AzureTRE/pull/4368))
* Add Windows image field to the Admin VM template ([#4274](https://github.com/microsoft/AzureTRE/pull/4274))
* Update TLS to the latest version for web apps / function apps (([#4351](https://github.com/microsoft/AzureTRE/issues/4351))
* Update TLS to the latest version for web apps / function apps ([#4351](https://github.com/microsoft/AzureTRE/issues/4351))
* Added backup vault to base workspace & updated Azurerm provider to match core. ([[#4362](https://github.com/microsoft/AzureTRE/issues/4362)])

BUG FIXES:
* Fix upgrade when porter install has failed ([#4338](https://github.com/microsoft/AzureTRE/pull/4338))
* Certs shared service: Secret nexus-ssl-password is currently in a deleted but recoverable state ([#4294](https://github.com/microsoft/AzureTRE/issues/4294)])
* Certs shared service: Secret nexus-ssl-password is currently in a deleted but recoverable state ([#4294](https://github.com/microsoft/AzureTRE/issues/4294))
* Fix Cosmos DB local debugging configuration ([#4340](https://github.com/microsoft/AzureTRE/pull/4340))

COMPONENTS:
Expand Down
6 changes: 6 additions & 0 deletions templates/workspaces/base/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@
"source": {
"env": "KEY_STORE_ID"
}
},
{
"name": "enable_backup",
"source": {
"env": "ENABLE_BACKUP"
}
}
]
}
58 changes: 57 additions & 1 deletion templates/workspaces/base/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
schemaVersion: 1.0.0
name: tre-workspace-base
version: 1.9.3
version: 2.0.12
description: "A base Azure TRE workspace"
dockerfile: Dockerfile.tmpl
registry: azuretre
Expand Down Expand Up @@ -126,6 +126,27 @@ parameters:
type: string
default: "GRS"
description: "The redundancy option for the storage account in the workspace: GRS (Geo-Redundant Storage) or ZRS (Zone-Redundant Storage)."
- name: enable_backup
type: boolean
default: true
description: "Enable backups for the workspace, including the vm's & shared storage."
- name: backup_vault_name
type: string
default: ""
description: "The name of the backup vault to use for backups"
- name: backup_vault_vm_backup_policy_name
type: string
default: ""
description: "The name of the backup policy to use for VM backups"
- name: backup_vault_fileshare_backup_policy_name
type: string
default: ""
description: "The name of the backup policy to use for fileshare backups"
- name: workspace_resource_name_suffix
type: string
default: ""
description: "A suffix to append to the workspace resource names"


outputs:
- name: app_role_id_workspace_owner
Expand Down Expand Up @@ -158,6 +179,22 @@ outputs:
applyTo:
- install
- upgrade
- name: backup_vault_name
type: string
applyTo:
- install
- upgrade
- name: backup_vault_vm_backup_policy_name
type: string
applyTo:
- install
- upgrade
- name: backup_vault_fileshare_backup_policy_name
type: string
applyTo:
- install
- upgrade


mixins:
- exec
Expand Down Expand Up @@ -196,6 +233,7 @@ install:
enable_cmk_encryption: ${ bundle.parameters.enable_cmk_encryption }
key_store_id: ${ bundle.parameters.key_store_id }
storage_account_redundancy: ${ bundle.parameters.storage_account_redundancy }
enable_backup: ${ bundle.parameters.enable_backup }
backendConfig:
use_azuread_auth: "true"
use_oidc: "true"
Expand All @@ -210,6 +248,9 @@ install:
- name: client_id
- name: scope_id
- name: sp_id
- name: backup_vault_name
- name: backup_vault_vm_backup_policy_name
- name: backup_vault_fileshare_backup_policy_name

upgrade:
- terraform:
Expand Down Expand Up @@ -241,6 +282,7 @@ upgrade:
enable_cmk_encryption: ${ bundle.parameters.enable_cmk_encryption }
key_store_id: ${ bundle.parameters.key_store_id }
storage_account_redundancy: ${ bundle.parameters.storage_account_redundancy }
enable_backup: ${ bundle.parameters.enable_backup }
backendConfig:
use_azuread_auth: "true"
use_oidc: "true"
Expand All @@ -255,6 +297,9 @@ upgrade:
- name: client_id
- name: scope_id
- name: sp_id
- name: backup_vault_name
- name: backup_vault_vm_backup_policy_name
- name: backup_vault_fileshare_backup_policy_name
- az:
description: "Set Azure Cloud Environment"
arguments:
Expand Down Expand Up @@ -309,10 +354,21 @@ uninstall:
enable_cmk_encryption: ${ bundle.parameters.enable_cmk_encryption }
key_store_id: ${ bundle.parameters.key_store_id }
storage_account_redundancy: ${ bundle.parameters.storage_account_redundancy }
enable_backup: ${ bundle.parameters.enable_backup }
backendConfig:
use_azuread_auth: "true"
use_oidc: "true"
resource_group_name: ${ bundle.parameters.tfstate_resource_group_name }
storage_account_name: ${ bundle.parameters.tfstate_storage_account_name }
container_name: ${ bundle.parameters.tfstate_container_name }
key: ${ bundle.parameters.tre_id }-ws-${ bundle.parameters.id }
outputs:
- name: app_role_id_workspace_owner
- name: app_role_id_workspace_researcher
- name: app_role_id_workspace_airlock_manager
- name: client_id
- name: scope_id
- name: sp_id
- name: backup_vault_name
- name: backup_vault_vm_backup_policy_name
- name: backup_vault_fileshare_backup_policy_name
8 changes: 8 additions & 0 deletions templates/workspaces/base/template_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
"Manual"
],
"updateable": true
},
"enable_backup": {
"type": "boolean",
"title": "Enable Backup",
"description": "Enable backups for the workspace. This covers any VMs deployed, and the workspace file share",
"default": true,
"updateable": true
}
},
"allOf": [
Expand Down Expand Up @@ -304,6 +311,7 @@
"create_aad_groups",
"client_id",
"client_secret",
"enable_backup",
"enable_airlock",
"configure_review_vms",
"airlock_review_config",
Expand Down
31 changes: 15 additions & 16 deletions templates/workspaces/base/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/workspaces/base/terraform/aad/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.117.0"
version = "=4.14.0"
}
azuread = {
source = "hashicorp/azuread"
Expand Down
2 changes: 1 addition & 1 deletion templates/workspaces/base/terraform/airlock/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.117.0"
version = "=4.14.0"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions templates/workspaces/base/terraform/api-permissions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ resource "azurerm_role_assignment" "api_reader" {
role_definition_name = "Reader"
principal_id = data.azurerm_user_assigned_identity.api_id.principal_id
}


Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.117.0"
version = "=4.14.0"
}

azapi = {
Expand Down
136 changes: 136 additions & 0 deletions templates/workspaces/base/terraform/backup/backup.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@

resource "azurerm_recovery_services_vault" "vault" {
name = local.vault_name
location = var.location
resource_group_name = var.resource_group_name
sku = "Standard"
soft_delete_enabled = true
storage_mode_type = "ZoneRedundant" # Possible values are "GeoRedundant", "LocallyRedundant" and "ZoneRedundant". Defaults to "GeoRedundant".
tags = var.tre_workspace_tags

dynamic "identity" {
for_each = var.enable_cmk_encryption ? [1] : []
content {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.encryption_identity[0].id]
}
}

dynamic "encryption" {
for_each = var.enable_cmk_encryption ? [1] : []
content{
key_id = azurerm_key_vault_key.encryption_key[0].versionless_id
infrastructure_encryption_enabled = true
user_assigned_identity_id = azurerm_user_assigned_identity.encryption_identity[0].id
use_system_assigned_identity = false
}
}

lifecycle { ignore_changes = [encryption, tags] }

}

resource "azurerm_backup_policy_vm" "vm_policy" {
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking , should the backup policy live with the workspace service, so for VMs, guacamole workspace service? Then each use resource is going to need to be protected?

Copy link
Author

Choose a reason for hiding this comment

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

humm possibly a good call. I was thinking of doing it this way they they are there allready.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, then the frequency etc coudl be configured across the worksapce. Hmm.

Copy link
Member

Choose a reason for hiding this comment

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

My worry is people think by ticking this box, everthing is being backed up. Many need a note to say "provided supported by the workspace services". The docs need to be clear.

Copy link
Author

Choose a reason for hiding this comment

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

Aggreed. Would it be a possiblity to show a icon on ether user objets or workspace servise that show what is backed up. Also can add a tickbox per service that can enable/disable.
My hope was to add a tab that would show some details about backups/what is backed up. For now have it as show only.

name = local.vm_backup_policy_name
resource_group_name = var.resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.vault.name


timezone = "UTC"

backup {
frequency = "Daily"
time = "22:00"
}

retention_daily {
count = 14
}

retention_weekly {
count = 4
weekdays = ["Sunday"]
}

retention_monthly {
count = 12
weekdays = ["Monday"]
weeks = ["First"]
}

retention_yearly {
count = 2
months = ["December"]
weekdays = ["Sunday"]
weeks = ["Last"]
}

depends_on = [
azurerm_recovery_services_vault.vault
]


}

resource "azurerm_backup_policy_file_share" "file_share_policy" {
name = local.fs_backup_policy_name
resource_group_name = var.resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.vault.name

timezone = "UTC"

backup {
frequency = "Daily"
time = "23:00"
}

retention_daily {
count = 14
}

retention_weekly {
count = 4
weekdays = ["Sunday"]
}

retention_monthly {
count = 12
weekdays = ["Monday"]
weeks = ["First"]
}

retention_yearly {
count = 2
months = ["December"]
weekdays = ["Sunday"]
weeks = ["Last"]
}

depends_on = [
azurerm_recovery_services_vault.vault
]

}

resource "azurerm_backup_container_storage_account" "storage_account" {
resource_group_name = var.resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.vault.name
storage_account_id = var.azurerm_storage_account_id

depends_on = [
azurerm_recovery_services_vault.vault
]
}

resource "azurerm_backup_protected_file_share" "file_share" {
resource_group_name = var.resource_group_name
recovery_vault_name = azurerm_recovery_services_vault.vault.name
source_storage_account_id = var.azurerm_storage_account_id
source_file_share_name = var.shared_storage_name
backup_policy_id = azurerm_backup_policy_file_share.file_share_policy.id

depends_on = [
azurerm_backup_policy_file_share.file_share_policy,
azurerm_backup_container_storage_account.storage_account
]
}
6 changes: 6 additions & 0 deletions templates/workspaces/base/terraform/backup/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
locals {
short_workspace_id = substr(var.tre_resource_id, -4, -1)
vault_name = "arsv-${var.tre_id}-ws-${local.short_workspace_id}"
vm_backup_policy_name = "abp-vm-${var.tre_id}-ws-${local.short_workspace_id}"
fs_backup_policy_name = "abp-fs-${var.tre_id}-ws-${local.short_workspace_id}"
}
Loading