diff --git a/templates/scripts/delete_azure_resources.sh b/templates/scripts/delete_azure_resources.sh new file mode 100755 index 000000000..7de2c5099 --- /dev/null +++ b/templates/scripts/delete_azure_resources.sh @@ -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 diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/Dockerfile.tmpl b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/Dockerfile.tmpl index 4494f207a..2943d9316 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/Dockerfile.tmpl +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/Dockerfile.tmpl @@ -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}/ diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter-build-context.env b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter-build-context.env new file mode 100644 index 000000000..7c2ad444b --- /dev/null +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter-build-context.env @@ -0,0 +1 @@ +export PORTER_BUILD_CONTEXT="scripts=../../../../scripts" diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml index 30895442e..c5bc20e2a 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml @@ -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 @@ -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: