Instantly share code, notes, and snippets.

Embed
What would you like to do?
delete_aci-virtualnetwork
# https://docs.microsoft.com/en-us/azure/container-instances/container-instances-vnet
# log into Azure
az login
# Set variables for resource group, virtual network, and subnet
RES_GROUP=containers1
VNET=vnet1
SUBNET=subnet1
# Get network profile ID
NETWORK_PROFILE_ID=$(az network profile list --resource-group $RES_GROUP --query [0].id --output tsv)
# Delete the network profile
az network profile delete --id $NETWORK_PROFILE_ID -y
# Get the service association link (SAL) ID
SAL_ID=$(az network vnet subnet show --resource-group $RES_GROUP --vnet-name $VNET \
--name $SUBNET --query id --output tsv)/providers/Microsoft.ContainerInstance/serviceAssociationLinks/default
# Delete the default SAL ID for the subnet
az resource delete --ids $SAL_ID --api-version 2018-07-01
# Delete the subnet delegation to Azure Container Instances
az network vnet subnet update --resource-group $RES_GROUP --vnet-name $VNET --name $SUBNET --remove delegations 0
# Delete the subnet
az network vnet subnet delete --resource-group $RES_GROUP --vnet-name $VNET --name $SUBNET
# Delete virtual network
az network vnet delete --resource-group $RES_GROUP --name $VNET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment