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

Fix deletion of Guacamole VM in stopped state #4245

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ BUG FIXES:
* Bump terraform version in windows VM template ([#4212](https://github.com/microsoft/AzureTRE/issues/4212))
* Upgrade azurerm terraform provider from v3.112.0 to v3.117.0 to mitiagte storage account deployment issue ([#4004](https://github.com/microsoft/AzureTRE/issues/4004))
* Fix VM actions where Workspace shared storage doesn't allow shared key access ([#4222](https://github.com/microsoft/AzureTRE/issues/4222))

* Unable to delete virtual machines, add skip_shutdown_and_force_delete = true ([#4135](https://github.com/microsoft/AzureTRE/issues/4135))
COMPONENTS:

## 0.19.1
Expand Down
26 changes: 26 additions & 0 deletions templates/scripts/delete_azure_resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Parameters
tre_id=$1
workspace_id=$2
workspace_service_id=$3
user_resource_id=$4

# Build the tag filter query
tag_filters="--tag tre_resource_id=$tre_id"
[ -n "$workspace_id" ] && tag_filters="$tag_filters --tag tre_workspace_id=$workspace_id"
[ -n "$workspace_service_id" ] && tag_filters="$tag_filters --tag tre_workspace_service_id=$workspace_service_id"
[ -n "$user_resource_id" ] && tag_filters="$tag_filters --tag tre_user_resource_id=$user_resource_id"

# login to azure
az login --identity

# Get the resource IDs with the specified tags
resource_ids=$(az resource list "$tag_filters" --query "[].id" -o tsv)

# Delete the resources
if [ -n "$resource_ids" ]; then
az resource delete --ids "$resource_ids" --yes
else
echo "No resources found with the specified tags."
fi
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ FROM --platform=linux/amd64 debian:bookworm-slim
# PORTER_MIXINS

# Use the BUNDLE_DIR build argument to copy files into the bundle
RUN mkdir -p ${BUNDLE_DIR}/app
# hadolint ignore=DL3022
COPY --from=scripts --link . ${BUNDLE_DIR}/scripts/

COPY --link . ${BUNDLE_DIR}/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export PORTER_BUILD_CONTEXT="scripts=../../../../scripts"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
schemaVersion: 1.0.0
name: tre-service-guacamole-linuxvm
version: 1.2.3
version: 1.3.1
description: "An Azure TRE User Resource Template for Guacamole (Linux)"
dockerfile: Dockerfile.tmpl
registry: azuretre
Expand Down Expand Up @@ -244,6 +244,15 @@ uninstall:
container_name: ${ bundle.parameters.tfstate_container_name }
key: ${ bundle.parameters.id }

- exec:
description: "Run the clean_up_resources.sh script"
command: "./scripts/delete_azure_resources.sh"
arguments:
- ${ bundle.parameters.tre_id }
- ${ bundle.parameters.workspace_id }
- ${ bundle.parameters.parent_service_id }
- ${ bundle.parameters.id }

start:
- terraform:
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ provider "azurerm" {
recover_soft_deleted_certificates = true
recover_soft_deleted_keys = true
}
virtual_machine {
skip_shutdown_and_force_delete = true
}
}
storage_use_azuread = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ provider "azurerm" {
recover_soft_deleted_certificates = true
recover_soft_deleted_keys = true
}
virtual_machine {
skip_shutdown_and_force_delete = true
}
}
storage_use_azuread = true
}
Loading