此範例指令碼使用 Azure CLI 在新資源群組中建立新的 Azure 應用程式組態執行個體。
如果您沒有 Azure 帳戶,請在開始之前建立 免費帳戶 。
先決條件
在 Azure Cloud Shell 中使用 Bash 環境。 如需詳細資訊,請參閱開始使用 Azure Cloud Shell。
若要在本機執行 CLI 參考命令,請安裝 (部分機器翻譯) Azure CLI。 若您在 Windows 或 macOS 上執行,請考慮在 Docker 容器中執行 Azure CLI。 如需詳細資訊,請參閱如何在 Docker 容器中執行 Azure CLI。
如果您使用的是本機安裝,請使用 az login 命令,透過 Azure CLI 來登入。 請遵循您終端機上顯示的步驟,以完成驗證流程。 如需其他登入選項,請參閱 使用 Azure CLI 向 Azure 進行驗證。
出現提示時,請在第一次使用時安裝 Azure CLI 延伸模組。 如需擴充功能的詳細資訊,請參閱 使用和管理 Azure CLI 的擴充功能。
執行 az version (部分機器翻譯) 以尋找已安裝的版本和相依程式庫。 若要升級至最新版本,請執行 az upgrade。
- 本教學課程需要 2.0 版或更新版本的 Azure CLI。 如果您是使用 Azure Cloud Shell,就已安裝最新版本。
範例指令碼
#!/bin/bash
appConfigName=myTestAppConfigStore
#resource name must be lowercase
myAppConfigStoreName=${appConfigName,,}
myResourceGroupName=$appConfigName"Group"
# Create resource group
az group create --name $myResourceGroupName --location eastus
# Create the Azure AppConfig Service resource and query the hostName
appConfigHostname=$(az appconfig create \
--name $myAppConfigStoreName \
--location eastus \
--resource-group $myResourceGroupName \
--query endpoint \
--sku free \
-o tsv
)
# Get the AppConfig connection string
appConfigConnectionString=$(az appconfig credential list \
--resource-group $myResourceGroupName \
--name $myAppConfigStoreName \
--query "[?name=='Secondary Read Only'] .connectionString" -o tsv)
# Echo the connection string for use in your application
echo "$appConfigConnectionString"
記下新資源群組所產生的實際名稱。 當您想要刪除所有群組資源時,就會用到該資源群組名稱。
清除部署
在執行過範例指令碼之後,您可以使用下列命令來移除資源群組和所有與其相關聯的資源。
az group delete --name myResourceGroup
指令碼說明
此指令碼使用下列命令來建立新的資源群組與應用程式組態存放區。 下表中的每個命令都會連結至命令特定的文件。
| Command | 注意 |
|---|---|
| 請輸入命令:az group create 來建立群組。 | 建立用來存放所有資源的資源群組。 |
| az appconfig create (建立 Azure 應用程式設定) | 建立應用程式組態存放區資源。 |
| az appconfig 認證清單 | 列出應用程式組態存放區的存取金鑰。 |
後續步驟
如需 Azure CLI 的詳細資訊,請參閱 Azure CLI 文件。
您可以在 Azure 應用程式組態 CLI 範例中找到其他的應用程式組態 CLI 指令碼範例。