#!/usr/bin/env bash # Metantel, Deploy on Azure: the whole deployment, in Azure Cloud Shell (Bash), by your Azure admin: # # bash <(curl -fsSL https://metantel.com/azure/org/v1/deploy.sh) # # It runs as you, in the subscription Cloud Shell is using, and talks only to Azure (and fetches Metantel's two # templates from metantel.com). Read it first if you like. It: # 1. checks the prerequisites (about a minute; creates nothing): your roles, the subscription, confidential VM quota, # your Azure AI Foundry and its model quota; # 2. asks six questions and shows exactly what it will create; nothing happens until you say yes; # 3. connects: the resource group metantel-cell with your policy rules on it, delegated to Metantel (Azure Lighthouse: # Reader and Virtual Machine Contributor, on that group only) [connect.json]; # 4. waits for Metantel to place the sealed system disk in that group (usually 5 to 15 minutes); # 5. deploys the network, the sign-in front, your key, the logs, the confidential VM and the two sign-in apps in your # Entra ID (about 15 minutes) [main.json]; # 6. prints the admin page's address for you and the manager you named. # # Safe to run again: it picks up where it was (if Cloud Shell timed out, open it again and run the same line). set -euo pipefail BASE=${METANTEL_BASE:-https://metantel.com/azure/org/v1} tpl() { case "$BASE" in /*) printf '%s\n' --template-file "$BASE/$1" ;; *) printf '%s\n' --template-uri "$BASE/$1" ;; esac; } # a local copy, for Metantel's own tests PREFIX=${METANTEL_PREFIX:-metantel} CELL_RG=$PREFIX-cell NET_RG=$PREFIX-network B=$'\033[1m' G=$'\033[32m' R=$'\033[31m' Y=$'\033[33m' N=$'\033[0m' say() { printf '\n%s%s%s\n' "$B" "$*" "$N"; } ok() { printf ' %s✓%s %s\n' "$G" "$N" "$*"; } bad() { printf ' %s✗%s %s\n' "$R" "$N" "$*"; FAILED=1; } warn() { printf ' %s!%s %s\n' "$Y" "$N" "$*"; } ask() { local v; read -r -p " $1${2:+ [$2]}: " v /dev/null || true) case "$quota_id" in FreeTrial*) bad "This is a free trial subscription ($quota_id): it can't get confidential VM quota. Use a pay-as-you-go, Enterprise Agreement or Microsoft Customer Agreement subscription." ;; "") warn "Couldn't read the subscription's type; carrying on." ;; *) ok "Subscription type: $quota_id" ;; esac me=$(az ad signed-in-user show --query id -o tsv 2>/dev/null || true) if [ -z "$me" ]; then bad "Couldn't read your account in Microsoft Entra ID (Microsoft Graph refused). Use a work account of this directory." else roles=$(az role assignment list --assignee "$me" --scope "/subscriptions/$sid" --include-inherited --include-groups \ --query "[].roleDefinitionName" -o tsv 2>/dev/null || true) if grep -qx "Owner" <<<"$roles" \ || { grep -qx "Contributor" <<<"$roles" && grep -Eqx "User Access Administrator|Role Based Access Control Administrator" <<<"$roles"; }; then ok "Azure role: Owner of the subscription" else bad "You need the Owner role on this subscription (it gives Metantel its delegated access and the VM its access to your Foundry). Yours: $(tr '\n' ',' <<<"$roles" | sed 's/,$//; s/,/, /g')" fi dirroles=$(az rest --method get --url 'https://graph.microsoft.com/v1.0/me/memberOf/microsoft.graph.directoryRole?$select=displayName' \ --query "value[].displayName" -o tsv 2>/dev/null || true) if grep -Eqx "Global Administrator|Cloud Application Administrator|Application Administrator" <<<"$dirroles"; then ok "Entra role: $(grep -Ex 'Global Administrator|Cloud Application Administrator|Application Administrator' <<<"$dirroles" | head -1)" else bad "You need Cloud Application Administrator (or Application Administrator, or Global Administrator) in Microsoft Entra ID, to create Metantel's two sign-in apps and consent for everyone once. If the role is eligible in Privileged Identity Management, activate it, then run this again." fi fi # Region: step 1's group if it exists, else asked. loc=$(az group show -n "$CELL_RG" --query location -o tsv 2>/dev/null || true) if [ -n "$loc" ]; then ok "Already connected (resource group $CELL_RG in $loc)" else loc=$(ask "Azure region for Metantel (e.g. centralindia, westeurope, eastus2)" "centralindia" | tr -d ' ' | lower) fi for p in Microsoft.Compute Microsoft.Network Microsoft.KeyVault Microsoft.Web Microsoft.OperationalInsights \ Microsoft.Insights Microsoft.ManagedServices Microsoft.CognitiveServices Microsoft.PolicyInsights; do st=$(az provider show -n "$p" --query registrationState -o tsv 2>/dev/null || echo NotRegistered) [ "$st" = Registered ] || { echo " Registering $p with your subscription (once)…"; az provider register -n "$p" --wait -o none; } done ok "Resource providers registered" # The free self-hosted Starter, up to 10 people (1 Dec 2026: larger plans come later; METANTEL_PLAN is for Metantel's tests). case "$(lower <<<"${METANTEL_PLAN:-Starter}")" in team) plan=Team fam=standardECASv5Family need=4 ;; *) plan=Starter fam=standardDCASv5Family need=2 ;; esac ok "Plan: $plan (free, up to $([ "$plan" = Team ] && echo 100 || echo 10) people)" free=$(az vm list-usage -l "$loc" --query "[?name.value=='$fam'] | [0].{l:limit, c:currentValue}" -o tsv 2>/dev/null | awk '{print int($1-$2)}' || true) if [ "${free:-0}" -ge "$need" ]; then ok "Confidential VM quota in $loc: $free vCPUs free, $need needed" else bad "Not enough confidential VM quota in $loc: $plan needs $need vCPUs of $fam, ${free:-0} free. Request it (no charge): https://portal.azure.com/#view/Microsoft_Azure_Capacity/QuotaMenuBlade/~/myQuotas" fi foundries=() flocs=() while IFS=$'\t' read -r f l; do [ -n "$f" ] && { foundries+=("$f"); flocs+=("$l"); }; done \ < <(az cognitiveservices account list --query "[?kind=='AIServices' || kind=='OpenAI'].[id, location]" -o tsv 2>/dev/null || true) foundry="" create=no if [ ${#foundries[@]} -eq 0 ]; then bad "No Azure AI Foundry resource in this subscription. Create one (any region), then run this again." else # Each Foundry with its group, region and whether it already has Metantel's three models. Only a Foundry that is # clearly the one (the only one, or the only one with the three models) is offered as the default; otherwise the # admin picks a number, and an answer that isn't one of them is asked again. three() { grep -qx gpt-6-luna <<<"$1" && grep -qx Decision-1.1 <<<"$1" && grep -qx text-embedding-3-small <<<"$1"; } echo " Your Azure AI Foundry resources:" def="" ready=0 for i in "${!foundries[@]}"; do f=${foundries[$i]} floc=${flocs[$i]:-} d=$(az cognitiveservices account deployment list -n "${f##*/}" -g "$(cut -d/ -f5 <<<"$f")" --query "[].name" -o tsv 2>/dev/null || true) note="needs the three models (created for you)"; if three "$d"; then note="has Metantel's three models"; ready=$((ready + 1)); def=$((i + 1)); fi printf ' %d. %s group %s, %s, %s\n' $((i + 1)) "${f##*/}" "$(cut -d/ -f5 <<<"$f")" "${floc:-?}" "$note" done [ "$ready" = 1 ] || def="" [ ${#foundries[@]} = 1 ] && def=1 n="" while ! [[ "$n" =~ ^[0-9]+$ ]] || [ "$n" -lt 1 ] || [ "$n" -gt ${#foundries[@]} ]; do n=$(ask "Which one should Metantel use? Type its number (1-${#foundries[@]})" "$def") done foundry=${foundries[$((n - 1))]} fname=${foundry##*/} frg=$(cut -d/ -f5 <<<"$foundry") ok "Foundry: $fname (group $frg)" have=$(az cognitiveservices account deployment list -n "$fname" -g "$frg" --query "[].name" -o tsv 2>/dev/null || true) if three "$have"; then ok "$fname already has the three model deployments" else create=yes floc=$(az cognitiveservices account show -n "$fname" -g "$frg" --query location -o tsv) if [ "$plan" = Team ]; then caps="750 500 500"; else caps="100 100 100"; fi set -- $caps usage=$(az cognitiveservices usage list -l "$floc" --query "[].{n:name.value,l:limit,c:currentValue}" -o tsv 2>/dev/null || true) for pair in "OpenAI.GlobalStandard.gpt-6-luna:$1:GPT-6 Luna" "AIServices.GlobalStandard.Microsoft-Decision-1.1:$2:Microsoft Decision-1.1" \ "OpenAI.GlobalStandard.text-embedding-3-small:$3:text-embedding-3-small"; do q=${pair%%:*} rest=${pair#*:} want=${rest%%:*} label=${rest#*:} left=$(awk -v q="$q" '$1==q {print int($2-$3)}' <<<"$usage") if [ -z "$left" ] || [ "$left" -lt "$want" ]; then bad "$label: $plan needs ${want}K tokens a minute (Global Standard) in $floc; ${left:-0}K free. Request model access and quota in Azure AI Foundry, or pick another Foundry." else ok "$label quota in $floc: ${left}K tokens a minute free, ${want}K needed" fi done fi fi if [ "$FAILED" = 1 ]; then say "${R}Some prerequisites are missing (✗ above).${N}" echo " These are for your Azure and Entra admins to settle. Nothing was created. Run this line again afterwards." echo " The full list: https://metantel.com/docs/deploy-on-azure#prerequisites" exit 1 fi # ── 2. the questions ────────────────────────────────────────────────────────────────────────────────────────────── say "2. About your organization" org=$(ask "Organization name (shown in Flow Console and on the admin page)") [ -n "$org" ] || { echo "An organization name is needed."; exit 1; } mine=$(az ad signed-in-user show --query "mail || userPrincipalName" -o tsv 2>/dev/null || echo "${who##*#}") mgr=$(ask "Who manages Metantel day to day (people, keys, usage)? Their work email" "$mine") mgr_id="" if [ "$(lower <<<"$mgr")" != "$(lower <<<"$mine")" ]; then mgr_id=$(az ad user show --id "$mgr" --query id -o tsv 2>/dev/null \ || az ad user list --filter "mail eq '$mgr' or userPrincipalName eq '$mgr'" --query "[0].id" -o tsv 2>/dev/null || true) if [ -n "$mgr_id" ]; then ok "$mgr will be a Metantel admin (no Azure role needed)" else warn "$mgr isn't in this directory; you'll be the Metantel admin and can add them later (Setup on the admin page)."; fi fi signin=$(ask "Who may sign in: everyone in your organization (up to the seats) or only people you assign? (everyone/assigned)" "everyone") case "$(lower <<<"$signin")" in assigned*) signin=assigned ;; *) signin=everyone ;; esac models_line=""; [ "$create" = yes ] && models_line=$'\n'" 4. Create the three model deployments in ${foundry##*/}." say "Ready. In subscription \"$sname\", as you, this will:" cat <"${TMPDIR:-/tmp}/metantel-connect.err" \ || { cat "${TMPDIR:-/tmp}/metantel-connect.err" >&2; echo " Connecting failed (above). Fix what it names and run this line again."; exit 1; } ok "Connected; your policy rules are on $CELL_RG" # ── 4. the sealed system disk ───────────────────────────────────────────────────────────────────────────────────── say "4. Waiting for Metantel to place the sealed system disk (usually 5 to 15 minutes; up to 45 the first time in a region)" for i in $(seq 1 135); do st=$(az disk show -g "$CELL_RG" -n "$PREFIX-cell-os" --query provisioningState -o tsv 2>/dev/null || true) [ "$st" = Succeeded ] && break [ $((i % 6)) = 1 ] && echo " $(date +%H:%M) still waiting… (status: https://metantel.com/deploy-on-azure#status)" sleep 20 done [ "${st:-}" = Succeeded ] || { echo " The disk isn't there after 45 minutes. Run this line again later, or write to projects@metantel.com."; exit 1; } ok "The system disk is in place" # ── 5. deploy ───────────────────────────────────────────────────────────────────────────────────────────────────── # A re-run: the VM exists and Metantel operates it (licence, updates), so it stays as it is; the front keeps its key. deploy_cell=true; front_key_arg=() if az vm show -g "$CELL_RG" -n "$PREFIX-cell" -o none 2>/dev/null; then deploy_cell=false fk=$(az webapp list -g "$NET_RG" --query "[0].name" -o tsv 2>/dev/null || true) [ -n "$fk" ] && fk=$(az webapp config appsettings list -g "$NET_RG" -n "$fk" --query "[?name=='FRONT_KEY'].value | [0]" -o tsv 2>/dev/null || true) [ -n "$fk" ] && front_key_arg=(frontKey="$fk") fi deploy() { # az lock delete -g "$NET_RG" -n metantel-network-read-only -o none 2>/dev/null || true # a re-run after the fallback az deployment sub create -n metantel -l "$loc" $(tpl main.json) \ --parameters location="$loc" prefix="$PREFIX" organizationName="$org" tier="$plan" adminEmail="$mgr" \ managerObjectId="$mgr_id" whoCanSignIn="$signin" foundryId="$foundry" \ createModelDeployments="$([ "$create" = yes ] && echo true || echo false)" protection="$1" \ deployCell="$deploy_cell" ${front_key_arg[@]+"${front_key_arg[@]}"} \ -o none 2>"${TMPDIR:-/tmp}/metantel-deploy.err" } denied_registration() { grep -q DeploymentStackTenantRegistrationFailed "${TMPDIR:-/tmp}/metantel-deploy.err" 2>/dev/null \ || az deployment operation sub list -n metantel --query "[?properties.provisioningState=='Failed'].properties.statusMessage" -o json 2>/dev/null \ | grep -q DeploymentStackTenantRegistrationFailed } say "5. Deploying (about 15 minutes; it runs in Azure)" protection=deny if ! deploy deny; then if denied_registration; then warn "Azure couldn't set up deny assignments in this directory yet (its own one-time registration failed). Trying again in two minutes…" sleep 120 if ! deploy deny; then if denied_registration; then warn "Still failing on Azure's side. Protecting $NET_RG with a ReadOnly lock instead: nobody can change it until an Owner removes the lock, which the Activity log records." protection=lock deploy lock || { cat "${TMPDIR:-/tmp}/metantel-deploy.err" >&2; exit 1; } else cat "${TMPDIR:-/tmp}/metantel-deploy.err" >&2; exit 1; fi fi else cat "${TMPDIR:-/tmp}/metantel-deploy.err" >&2 echo " The deployment failed (above). Fix what it names and run this line again: it picks up where it was." exit 1 fi fi admin_page=$(az deployment sub show -n metantel --query properties.outputs.adminPage.value -o tsv) endpoint=${admin_page%/admin} app=${endpoint#https://}; app=${app%%.*} also=""; [ -n "$mgr_id" ] && also=" and $mgr" prot="deny assignment on $NET_RG (only you can change it)"; [ "$protection" = lock ] && prot="ReadOnly lock on $NET_RG" # ── 6. done ─────────────────────────────────────────────────────────────────────────────────────────────────────── say "${G}Done.${N}${B} Metantel activates your licence within about 10 minutes." cat < "Your organization's deployment" > $endpoint > Sign in with Microsoft Protection: $prot Send this to ${mgr:-your manager}: Metantel is ready on our Azure. Admin page: $admin_page Sign in with Microsoft (your work account; no Azure role needed). Start on its Setup tab. To find the address again: Azure portal > resource group $NET_RG > the App Service $app > Default domain, then add /admin. Or run this line again: it changes nothing and prints it. EOF