Skip to content
Draft
Show file tree
Hide file tree
Changes from 11 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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<!-- markdownlint-disable MD041 -->
## (Unreleased)

* _No changes yet_
ENHANCEMENTS:
* Reduce costs by starting and stopping Service Bus and function apps via `tre-start` and `tre-stop` ([#3953](https://github.com/microsoft/AzureTRE/issues/3953))
Comment thread
JC-wk marked this conversation as resolved.
Outdated

BUG FIXES:

## (0.28.0) (March 2, 2026)
**BREAKING CHANGES**
Expand Down
83 changes: 83 additions & 0 deletions devops/scripts/control_tre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if [[ -z ${TRE_ID:-} ]]; then
exit 1
fi

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
core_rg_name="rg-${TRE_ID}"
fw_name="fw-${TRE_ID}"
agw_name="agw-$TRE_ID"
Expand All @@ -25,7 +26,28 @@ fi
az config set extension.use_dynamic_install=yes_without_prompt
az --version

# shellcheck disable=SC1091
source "${SCRIPT_DIR}/kv_add_network_exception.sh"

if [[ "$1" == *"start"* ]]; then
# Recreate Service Bus if it doesn't exist
if [[ $(az servicebus namespace list --resource-group "${core_rg_name}" --query "[?name=='sb-${TRE_ID}'] | length(@)") == 0 ]]; then
echo "Ensuring Service Bus diagnostic settings are removed"
subscription_id=$(az account show --query id -o tsv)
diag_id="/subscriptions/${subscription_id}/resourceGroups/${core_rg_name}/providers/Microsoft.ServiceBus/namespaces/sb-${TRE_ID}/providers/microsoft.insights/diagnosticSettings/diagnostics-sb-${TRE_ID}"
az resource delete --ids "${diag_id}" 2>/dev/null || true

echo "Recreating Service Bus"
# shellcheck disable=SC2154
"${SCRIPT_DIR}/terraform_wrapper.sh" \
-d "${SCRIPT_DIR}/../../core/terraform" \
-g "${TF_VAR_mgmt_resource_group_name}" \
-s "${TF_VAR_mgmt_storage_account_name}" \
-n "${TF_VAR_terraform_state_container_name}" \
-k "${TRE_ID}" \
-c "terraform apply -auto-approve"
fi

if [[ $(az network firewall list --output json --query "[?resourceGroup=='${core_rg_name}'&&name=='${fw_name}'] | length(@)") != 0 ]]; then
CURRENT_PUBLIC_IP=$(az network firewall ip-config list -f "${fw_name}" -g "${core_rg_name}" --query "[0].publicIpAddress" -o tsv)
if [ -z "$CURRENT_PUBLIC_IP" ]; then
Expand Down Expand Up @@ -70,9 +92,70 @@ if [[ "$1" == *"start"* ]]; then
az vm start --resource-group "${core_rg_name}" --name "${vm_name}" &
done

echo "Starting Function Apps"
Comment thread
JC-wk marked this conversation as resolved.
az functionapp list --resource-group "${core_rg_name}" --query "[?state=='Stopped'].name" -o tsv |
while read -r name; do
echo "Starting Function App ${name}"
az functionapp start --resource-group "${core_rg_name}" --name "${name}" &
done

echo "Starting Web Apps"
az webapp list --resource-group "${core_rg_name}" --query "[?state=='Stopped'].name" -o tsv |
while read -r name; do
echo "Starting Web App ${name}"
az webapp start --resource-group "${core_rg_name}" --name "${name}" &
done

# We don't start workspace VMs despite maybe stopping them because we don't know if they need to be on.

elif [[ "$1" == *"stop"* ]]; then

echo "Stopping Function Apps"
az functionapp list --resource-group "${core_rg_name}" --query "[?state=='Running'].name" -o tsv |
while read -r name; do
echo "Stopping Function App ${name}"
az functionapp stop --resource-group "${core_rg_name}" --name "${name}" &
done

echo "Stopping Web Apps"
Comment thread
SvenAelterman marked this conversation as resolved.
az webapp list --resource-group "${core_rg_name}" --query "[?state=='Running'].name" -o tsv |
while read -r name; do
echo "Stopping Web App ${name}"
az webapp stop --resource-group "${core_rg_name}" --name "${name}" &
done

# Stopping all Function Apps in workspaces
Comment thread
JC-wk marked this conversation as resolved.
Outdated
az functionapp list --query "[?(starts_with(resourceGroup,'${core_rg_name}-ws') || starts_with(resourceGroup,'${core_rg_name^^}-WS')) && state=='Running'][name, resourceGroup]" -o tsv |
while read -r name rg; do
echo "Stopping Function App ${name} in ${rg}"
az functionapp stop --resource-group "${rg}" --name "${name}" &
done

# Stopping all Web Apps in workspaces
az webapp list --query "[?(starts_with(resourceGroup,'${core_rg_name}-ws') || starts_with(resourceGroup,'${core_rg_name^^}-WS')) && state=='Running'][name, resourceGroup]" -o tsv |
while read -r name rg; do
echo "Stopping Web App ${name} in ${rg}"
az webapp stop --resource-group "${rg}" --name "${name}" &
done

# Destroy Service Bus
sb_id=$(az servicebus namespace show --name "sb-${TRE_ID}" --resource-group "${core_rg_name}" --query id -o tsv 2>/dev/null || true)
if [[ -n "${sb_id}" ]]; then
echo "Deleting diagnostic settings for Service Bus"
# shellcheck disable=SC2015
{ az monitor diagnostic-settings list --resource "${sb_id}" --query "value[].name" -o tsv 2>/dev/null \
&& az monitor diagnostic-settings list --resource "${sb_id}" --query "[].name" -o tsv 2>/dev/null ; } |
while read -r diag_name; do
if [[ -n "${diag_name}" ]]; then
echo "Deleting diagnostic setting ${diag_name}"
az monitor diagnostic-settings delete --resource "${sb_id}" --name "${diag_name}" --output none || true
fi
done

echo "Destroying Service Bus"
az servicebus namespace delete --name "sb-${TRE_ID}" --resource-group "${core_rg_name}" &
fi

if [[ $(az network firewall list --output json --query "[?resourceGroup=='${core_rg_name}'&&name=='${fw_name}'] | length(@)") != 0 ]]; then
IPCONFIG_NAME=$(az network firewall ip-config list -f "${fw_name}" -g "${core_rg_name}" --query "[0].name" -o tsv)

Expand Down
2 changes: 1 addition & 1 deletion devops/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.3"
__version__ = "0.6.4"
Loading