Azure ARM (7) ARM Template - 使用Visual Studio编辑

简介:

 《Windows Azure Platform 系列文章目录

   

  之前介绍的ARM Template,都是使用文本编辑器来编辑JSON文件的。

  文本讲介绍如何使用Visual Studio,编辑JSON Template。

  本文使用Visual Studio 2015 with Update 3进行编辑,安装了Azure SDK 2.9。

  如果读者使用的是Visual Studio 2013和Azure SDK 2.9,大部门的界面是和笔者的截图类似。笔者强烈建议安装最新的Visual Studio和Azure SDK。

 

  前提:

  1.安装Visual Studio 2015 with Update 3

  2.安装Azure SDK 2.9

 

  1.运行Visual Studio 2015 with Update 3

  2.创建一个Azure Resource Group项目。如下图:

  

  

  3.模板选择Blank Template

  

  

  4.项目创建完毕后,不包含任何项目,我们选择Templates,双击 azuredeploy.json

  

  

  5.显示如下图的JSON Outline,我们可以添加新的资源,点击resources,邮件,Add New Resource。如下图:

   

 

  6.在弹出的界面中,输入Storage Account,然后色织storage account name (必须为小写英文),如下图:

  

 

  7.修改Visual Studio项目中的azuredeploy.json文件,内容如下:

复制代码
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
  "parameters": {
          "leinewstorageType": {
            "type": "string",
            "defaultValue": "Standard_LRS",
            "allowedValues": [
              "Standard_LRS",
              "Standard_ZRS",
              "Standard_GRS",
              "Standard_RAGRS",
              "Premium_LRS"
            ]
          },
          "storageAccounts_leistorageaccount_name": {
            "defaultValue": "leistorageaccount",
            "type": "String"
          }
  },
    "variables": {
        
    },
    "resources": [
      {
        "name": "[parameters('storageAccounts_leistorageaccount_name')]",
        "type": "Microsoft.Storage/storageAccounts",
        "location": "[resourceGroup().location]",
        "apiVersion": "2015-06-15",
        "dependsOn": [],
        "tags": {
          "displayName": "leinewstorage"
        },
        "properties": {
          "accountType": "[parameters('leinewstorageType')]"
        }
      }
    ],
    "outputs": {
    }
}
复制代码

 

  8.修改azuredeploy.parameters.json文件,内容如下:

复制代码
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccounts_leistorageaccount_name": {
      "value": "leinewstorageaccount"
    }
  }
}
复制代码

 

  最后通过Azure PowerShell进行发布,命令如下:

复制代码
# sign in
Write-Host "Logging in...";
Add-AzureRmAccount -EnvironmentName AzureChinaCloud;

# select subscription
Write-Host "Selecting subscription '$subscriptionId'";
Select-AzureRmSubscription -SubscriptionID $subscriptionId;

#创建Resource Group
New-AzureRmResourceGroup -Name $resourceGroupName -Location $resourceGroupLocation

#部署Template
 New-AzureRmResourceGroupDeployment -ResourceGroupName "[ResourceGroupName]" -TemplateFile "[FilePath]" -TemplateParameterFile ["ParameterFilePath"];
复制代码

 

 

  参考资料:https://azure.microsoft.com/en-us/documentation/articles/vs-azure-tools-resource-groups-deployment-projects-create-deploy/



本文转自Lei Zhang博客园博客,原文链接:http://www.cnblogs.com/threestone/p/6005059.html,如需转载请自行联系原作者

目录
相关文章
|
4月前
|
机器学习/深度学习 存储 TensorFlow
Azure 机器学习 - 使用 Visual Studio Code训练图像分类 TensorFlow 模型
Azure 机器学习 - 使用 Visual Studio Code训练图像分类 TensorFlow 模型
71 0
|
4月前
|
机器学习/深度学习 IDE 开发工具
Azure机器学习 - 使用与Azure集成的Visual Studio Code机器学习实战
Azure机器学习 - 使用与Azure集成的Visual Studio Code机器学习实战
104 0
|
5月前
|
机器学习/深度学习 存储 IDE
Azure机器学习 - 使用与Azure集成的Visual Studio Code实战教程
Azure机器学习 - 使用与Azure集成的Visual Studio Code实战教程
37 0
|
安全 定位技术 网络安全
|
UED 运维 Windows

热门文章

最新文章