Skip to content

Commit

Permalink
WIP: Add backup VM
Browse files Browse the repository at this point in the history
  • Loading branch information
JimMadge committed Nov 12, 2024
1 parent 12dcc65 commit ceb302a
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion data_safe_haven/infrastructure/programs/sre/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)

0 comments on commit ceb302a

Please sign in to comment.