使用 Azure CLI 创建托管应用程序定义Create a managed application definition with Azure CLI

此脚本会将托管应用程序定义发布到服务目录。This script publishes a managed application definition to a service catalog.

若要运行此示例,请安装最新版本的 Azure CLITo run this sample, install the latest version of the Azure CLI. 若要开始,请运行 az login 以创建与 Azure 的连接。To start, run az login to create a connection with Azure.

适用于 Azure CLI 的示例是针对 bash shell 编写的。Samples for the Azure CLI are written for the bash shell. 若要在 Windows PowerShell 或命令提示符中运行此示例,可能需要更改脚本的元素。To run this sample in Windows PowerShell or Command Prompt, you may need to change elements of the script.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

示例脚本Sample script

#!/bin/bash

# Create resource group
az group create --name appDefinitionGroup --location chinaeast

# Get Azure Active Directory group to manage the application
groupid=$(az ad group show --group appManagers --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 "ManagedStorage" \
  --location "chinaeast" \
  --resource-group appDefinitionGroup \
  --lock-level ReadOnly \
  --display-name "Managed Storage Account" \
  --description "Managed Azure Storage Account" \
  --authorizations "$groupid:$roleid" \
  --package-file-uri "https://raw.githubusercontent.com/Azure/azure-managedapp-samples/master/Managed%20Application%20Sample%20Packages/201-managed-storage-account/managedstorage.zip"

脚本说明Script explanation

此脚本使用以下命令创建托管应用程序定义。This script uses the following command to create the managed application definition. 表中的每条命令均链接到特定于命令的文档。Each command in the table links to command-specific documentation.

CommandCommand 说明Notes
az managedapp definition createaz managedapp definition create 创建托管应用程序定义。Create a managed application definition. 提供包含所需文件的包。Provide the package that contains the required files.

后续步骤Next steps