Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
2.5 kB
3
Indexable
Never
#!/bin/bash

# Prompt for details
read -r -p "Enter the name of the Azure ML Workspace: " workspaceName
read -r -p "Enter the location (default is japaneast): " location
read -r -p "Enter the description (optional): " description
read -r -p "Enter the SKU name (default is Basic): " skuName
read -r -p "Enter the SKU tier (default is Basic): " skuTier

# Set defaults if not provided
location=${location:-japaneast}
skuName=${skuName:-Basic}
skuTier=${skuTier:-Basic}

# Automatic Resource Group Naming with prefix "alh"
resourceGroupName="alh-rg-${workspaceName}"

# Fetch the current subscription ID dynamically
subscriptionId=$(az account show --query "id" --output tsv)

# Create resource group (if not exists)
az group create --name "$resourceGroupName" --location "$location"

# Deploy the ARM template with timestamped output
timestamp=$(date +"%Y%m%d%H%M%S")
outputFile="${workspaceName}_${timestamp}.json"

az deployment group create \
  --resource-group "$resourceGroupName" \
  --template-file azureml-workspace-template.json \
  --parameters workspaceName="$workspaceName" location="$location" description="$description" skuName="$skuName" skuTier="$skuTier" \
  --output json > "$outputFile"

echo "Deployment output saved to $outputFile"

# Check if managed network is enabled
managedNetworkEnabled=$(az ml workspace show --name "alh${workspaceName}" --resource-group "$resourceGroupName" --query "managedNetwork" --output tsv)

if [ -z "$managedNetworkEnabled" ]; then
    echo "Managed network not found or not enabled. Enabling managed network..."
    
    az ml workspace update \
      --name "alh${workspaceName}" \
      --resource-group "$resourceGroupName" \
      --set managedNetwork.enabled=true
fi

# Adding outbound rules using Azure CLI
echo "Adding outbound rules to the workspace..."

az ml workspace update \
  --name "alh${workspaceName}" \
  --resource-group "$resourceGroupName" \
  --set managedNetwork.outboundRules='[
    {
      "name": "outboundrulemlws",
      "type": "PrivateEndpoint",
      "destination": {
        "serviceResourceId": "/subscriptions/'"$subscriptionId"'/resourceGroups/'"$resourceGroupName"'/providers/Microsoft.MachineLearningServices/workspaces/alh'"${workspaceName}"'",
        "subresourceTarget": "amlworkspace"
      },
      "status": "Active",
      "category": "UserDefined"
    }
  ]'

echo "Outbound rules added successfully."


# TODO Check Azure Subscription: az login
# TODO Create Post-Deployment Guide
Leave a Comment