From ceb302a3de00d5a5fffe41d13304c2a5e7d11bc7 Mon Sep 17 00:00:00 2001 From: Jim Madge Date: Tue, 12 Nov 2024 15:19:37 +0000 Subject: [PATCH] WIP: Add backup VM --- .../infrastructure/programs/sre/backup.py | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/data_safe_haven/infrastructure/programs/sre/backup.py b/data_safe_haven/infrastructure/programs/sre/backup.py index ae1eb1f7ba..e48583c4dc 100644 --- a/data_safe_haven/infrastructure/programs/sre/backup.py +++ b/data_safe_haven/infrastructure/programs/sre/backup.py @@ -2,7 +2,10 @@ from collections.abc import Mapping -from pulumi import ComponentResource, Input, ResourceOptions +from pulumi import ComponentResource, Input, Output, ResourceOptions + +from data_safe_haven.infrastructure.components import LinuxVMComponentProps, VMComponent +from data_safe_haven.functions import b64encode, replace_separators class SREBackupProps: @@ -39,3 +42,36 @@ def __init__( super().__init__("dsh:sre:BackupComponent", name, {}, opts) child_opts = ResourceOptions.merge(opts, ResourceOptions(parent=self)) child_tags = {"component": "backup"} | (tags if tags else {}) + + # Template cloud init + cloudinit = Output.all( + apt_proxy_server_hostname=props.apt_proxy_server_hostname, + storage_account_desired_state_name=props.storage_account_desired_state_name, + storage_account_data_private_user_name=props.storage_account_data_private_user_name, + storage_account_data_private_sensitive_name=props.storage_account_data_private_sensitive_name, + ).apply(lambda kwargs: self.template_cloudinit(**kwargs)) + + # Backup virtual machine + VMComponent( + replace_separators(f"{self._name}_vm_backup", "_"), + LinuxVMComponentProps( + admin_password=props.admin_password, + admin_username=props.admin_username, + b64cloudinit=cloudinit.apply(b64encode), + data_collection_rule_id=props.data_collection_rule_id, + data_collection_endpoint_id=props.data_collection_endpoint_id, + ip_address_private=..., + location=props.location, + maintenance_configuration_id=props.maintenance_configuration_id, + resource_group_name=props.resource_group_name, + subnet_name=props.subnet_workspaces_name, + virtual_network_name=props.virtual_network_name, + virtual_network_resource_group_name=props.resource_group_name, + vm_name=Output.concat( + stack_name, "-vm-backup" + ).apply(lambda s: replace_separators(s, "-")), + vm_size="Standard_B2s_v2", + ), + opts=child_opts, + tags=child_tags, + )