Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit

Permalink
Grant az role to create resource groups
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiddelkoop committed Dec 2, 2021
1 parent e7b3b16 commit 32e2f1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 11 additions & 4 deletions scripts/azure-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@ REPO="git@${GITHUB}:CLASS/${PROJECT}.git"

echo "=== azure-create.sh $PROJECT $BRANCH"
SUBSCRIPTION=$(az account show --query id -otsv)
RESOURCE_GROUP=$VM
RESOURCE_GROUP="rg-${VM}-dev"

echo "+++ creating resource group $RESOURCE_GROUP $SUBSCRIPTION"
az group create --resource-group $RESOURCE_GROUP --location $LOCATION

echo "+++ creating VM $VM"
# Ubuntu is "Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest"
# Debian is "Debian:debian-10:10:latest"
# Resource Group scope "subscriptions/$SUBSCRIPTION/resourceGroups/$RESOURCE_GROUP"
az vm create --resource-group $RESOURCE_GROUP --name $VM \
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest \
--size Standard_D4_v4 \
--size Standard_D2_v4 \
--storage-sku Standard_LRS \
--public-ip-sku Standard \
--assign-identity \
--scope "subscriptions/$SUBSCRIPTION/resourceGroups/$RESOURCE_GROUP" \
--admin-username $NAME

IP=$(az vm show --name essentials --resource-group essentials -d --query publicIps -otsv)
IP=$(az vm show --name $VM --resource-group $RESOURCE_GROUP -d --query publicIps -otsv)
IDENTITY=$(az vm show --name $VM --resource-group $RESOURCE_GROUP --query identity.principalId -otsv)

echo "+++ assign the VM the Contributor role to the subscription ($IDENTITY to $SUBSCRIPTION)"
az role assignment create --assignee $IDENTITY --scope /subscriptions/$SUBSCRIPTION --role Contributor

echo "+++ wait for boot and cloud-init ${VM} ${IP}"
ssh-keygen -R $IP
Expand All @@ -40,7 +46,8 @@ while ! ssh $NAME@$IP sudo cloud-init status --wait ; do
done

echo "+++ configuring VM"
ssh -A $NAME@$VM <<EOF
ssh -A $NAME@$IP <<EOF
echo '--- connected to $NAME@IP'
sudo apt-get update
sudo apt-get install --yes azure-cli
az login --identity
Expand Down
7 changes: 5 additions & 2 deletions scripts/azure-delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Static Config - update *.sh files
VM=essentials

RESOURCE_GROUP=$VM
echo "=== azure-delete.sh $PROJECT $BRANCH"
SUBSCRIPTION=$(az account show --query id -otsv)
RESOURCE_GROUP="rg-${VM}-dev"

az vm delete --resource-group $RESOURCE_GROUP --name $VM --yes
#az group delete --resource-group $RESOURCE_GROUP --yes
az group delete --resource-group $RESOURCE_GROUP --yes

0 comments on commit 32e2f1c

Please sign in to comment.