Skip to content

Commit

Permalink
Use script for Linux VM
Browse files Browse the repository at this point in the history
  • Loading branch information
marrobi committed Jan 2, 2025
1 parent 4877121 commit c2477fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
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

0 comments on commit c2477fa

Please sign in to comment.