Create a managed application definition to service catalog and deploy managed application from service catalog with Azure CLI

This script publishes a managed application definition to a service catalog and then deploys a managed application definition from the service catalog.

If you don't have an Azure subscription, create an Azure free account before you begin.


Sample script

Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.

To open the Cloud Shell, just select Try it from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to

When Cloud Shell opens, verify that Bash is selected for your environment. Subsequent sessions will use Azure CLI in a Bash environment, Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press Enter to run it.

Sign in to Azure

Cloud Shell is automatically authenticated under the initial account signed-in with. Use the following script to sign in using a different subscription, replacing <Subscription ID> with your Azure Subscription ID. If you don't have an Azure subscription, create an Azure free account before you begin.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

For more information, see set active subscription or log in interactively

Run the script

# Define and create a managed application

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"

# Create definition for a managed application

# Create a application definition resource group
echo "Creating $appDefinitionResourceGroup in "$location"..."
az group create --name $appDefinitionResourceGroup --location "$location" --tags $tag

# Get Azure Active Directory group to manage the application
groupid=$(az ad group show --group reader --query objectId --output tsv)

# Get role
roleid=$(az role definition list --name Owner --query [].name --output tsv)

# Create the definition for a managed application
az managedapp definition create --name "$managedApp" --location "$location" --resource-group $appDefinitionResourceGroup --lock-level ReadOnly --display-name "Managed Storage Account" --description "Managed Azure Storage Account" --authorizations "$groupid:$roleid" --package-file-uri ""

# Create managed application

# Create application resource group
echo "Creating $appResourceGroup in "$location"..."
az group create --name $appResourceGroup --location "$location" --tags $tag

# Get ID of managed application definition
appid=$(az managedapp definition show --name $managedApp --resource-group $appDefinitionResourceGroup --query id --output tsv)

# Get subscription ID
subid=$(az account show --query id --output tsv)

# Construct the ID of the managed resource group

# Create the managed application
az managedapp create --name storageApp --location "$location" --kind "Servicecatalog" --resource-group $appResourceGroup --managedapp-definition-id $appid --managed-rg-id $managedGroupId --parameters "{\"storageAccountNamePrefix\": {\"value\": \"demostorage\"}, \"storageAccountType\": {\"value\": \"Standard_LRS\"}}"

Clean up resources

Use the following command to remove the resource group and all resources associated with it using the az group delete command - unless you have an ongoing need for these resources. Some of these resources may take a while to create, as well as to delete.

az group delete --name $appResourceGroup -y
az group delete --name $appDefinitionResourceGroup -y

Sample reference

This script uses the following command to create the managed application definition. Each command in the table links to command-specific documentation.

Command Notes
az managedapp definition create Create a managed application definition. Provide the package that contains the required files.

Next steps