Skip to content

Commit

Permalink
Refactor the script for adding identity with compute (Azure#2014)
Browse files Browse the repository at this point in the history
* Refactor the script for adding identity with compute
  • Loading branch information
harneetvirk authored Jan 6, 2023
1 parent 9c88c15 commit b6e30f4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 53 deletions.

This file was deleted.

2 changes: 0 additions & 2 deletions cli/deploy-mlcompute-create-with-user-identity.sh

This file was deleted.

32 changes: 30 additions & 2 deletions cli/deploy-mlcompute-update-to-user-identity.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
IDENTITY=$(az identity create -n my-cluster-identity --query id -o tsv)
az ml compute update --name mycluster --identity-type user_assigned --user-assigned-identities $IDENTITY
export MSI_NAME=my-cluster-identity
export COMPUTE_NAME=mycluster-msi

does_compute_exist()
{
if [ -z $(az ml compute show -n $COMPUTE_NAME --query name) ]; then
echo false
else
echo true
fi
}

echo "Creating MSI $MSI_NAME"
# Get the resource id of the identity
IDENTITY_ID=$(az identity show --name "$MSI_NAME" --query id -o tsv | tail -n1 | tr -d "[:cntrl:]" || true)
if [[ -z $IDENTITY_ID ]]; then
IDENTITY_ID=$(az identity create -n "$MSI_NAME" --query id -o tsv | tail -n1 | tr -d "[:cntrl:]")
fi
echo "MSI created: $MSI_NAME"
sleep 15 # Let the previous command finish: https://github.com/Azure/azure-cli/issues/8530


echo "Checking if compute $COMPUTE_NAME already exists"
if [ "$(does_compute_exist)" == "true" ]; then
echo "Skipping, compute: $COMPUTE_NAME exists"
else
echo "Provisioning compute: $COMPUTE_NAME"
az ml compute create --name "$COMPUTE_NAME" --type amlcompute --identity-type user_assigned --user-assigned-identities "$IDENTITY_ID"
fi
az ml compute update --name "$COMPUTE_NAME" --identity-type user_assigned --user-assigned-identities "$IDENTITY_ID"
1 change: 1 addition & 0 deletions infra/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ amlcompute_to_delete=(
minimal-example
basic-example
mycluster
mycluster-msi
location-example
low-pri-example
ssh-example
Expand Down

0 comments on commit b6e30f4

Please sign in to comment.