无法部署Azure资源管理器模板

时间:2018-09-03 08:01:38

标签: azure powershell azure-resource-manager

我正在尝试创建一个Azure资源管理器模板来创建一个应用程序服务计划和一个应用程序服务。

但是。尝试部署模板时出现以下错误,

17:40:27 - The following parameter values will be used for this operation:
   17:40:27 -     setup-sites-non-prod-service-planName: setup-sites-non-prod-service-plan
   17:40:27 -     setup-sites-non-prod-service-planSkuName: F1
   17:40:27 - Build started.
   17:40:27 - Project "ARM_OnlineSetup.deployproj" (StageArtifacts target(s)):
   17:40:27 - Project "ARM_OnlineSetup.deployproj" (ContentFilesProjectOutputGroup target(s)):
    17:40:27 - Done building project "ARM_OnlineSetup.deployproj".
    17:40:27 - Done building project "ARM_OnlineSetup.deployproj".
    17:40:27 - Build succeeded.
    17:40:27 - Launching PowerShell script with the following command:
    17:40:27 - 'C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_OnlineSetup\Deploy-AzureResourceGroup.ps1' -StorageAccountName '' -ResourceGroupName 'setup-sites-non-prod-resource-group' -ResourceGroupLocation 'australiasoutheast' -TemplateFile 'C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_OnlineSetup\azuredeploy.json' -TemplateParametersFile 

  'C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_OnlineSetup\azuredeploy.parameters.json' -ArtifactStagingDirectory '.' -DSCSourceFolder '.\DSC'
    17:40:28 - [ERROR] Get-AzureRmEnvironment : The term 'Get-AzureRmEnvironment' is not recognized 
    17:40:28 - [ERROR] as the name of a cmdlet, function, script file, or operable program. Check the 
    17:40:28 - [ERROR] spelling of the name, or if a path was included, verify that the path is 
    17:40:28 - [ERROR] correct and try again.
    17:40:28 - [ERROR] At line:1 char:176
    17:40:28 - [ERROR] + ... 'true' }; if ((Get-AzureRmEnvironment -Name 'AzureCloud') -eq $null) { 
    17:40:28 - [ERROR] Set-Azure ...
    17:40:28 - [ERROR] +                    ~~~~~~~~~~~~~~~~~~~~~~
    17:40:28 - [ERROR]     + CategoryInfo          : ObjectNotFound: (Get-AzureRmEnvironment:String)  
    17:40:28 - [ERROR]    [], CommandNotFoundException
    17:40:28 - [ERROR]     + FullyQualifiedErrorId : CommandNotFoundException
    17:40:28 - [ERROR]  
    17:40:28 - [ERROR] Add-AzureRMAccount : The term 'Add-AzureRMAccount' is not recognized as the 
    17:40:28 - [ERROR] name of a cmdlet, function, script file, or operable program. Check the 
    17:40:28 - [ERROR] spelling of the name, or if a path was included, verify that the path is 
    17:40:28 - [ERROR] correct and try again.
    17:40:28 - [ERROR] At line:1 char:602
    17:40:28 - [ERROR] + ... ws.net/'  }; ((Add-AzureRMAccount -SubscriptionId 
    17:40:28 - [ERROR] 'fa801c3f-d70d-49cf-84fe-1cc1d ...
    17:40:28 - [ERROR] +                    ~~~~~~~~~~~~~~~~~~
    17:40:28 - [ERROR]     + CategoryInfo          : ObjectNotFound: (Add-AzureRMAccount:String) [],  
    17:40:28 - [ERROR]    CommandNotFoundException
    17:40:28 - [ERROR]     + FullyQualifiedErrorId : CommandNotFoundException
    17:40:28 - [ERROR]  
    17:40:28 - [ERROR] C:\Users\manjunathj\Documents\Study\ARM_OnlineSetup\bin\Debug\staging\ARM_Onlin
    17:40:28 - [ERROR] eSetup\Deploy-AzureResourceGroup.ps1 : The term 'New-AzureRmResourceGroup' is 
    17:40:28 - [ERROR] not recognized as the name of a cmdlet, function, script file, or operable 
    17:40:28 - [ERROR] program. Check the spelling of the name, or if a path was included, verify 
    17:40:28 - [ERROR] that the path is correct and try again.
    17:40:28 - [ERROR] At line:1 char:3434
    17:40:28 - [ERROR] + $UI = 'VS-'; if (!(Test-Path 'C:\Users\manjunathj\AppData\Roaming\Windows 
    17:40:28 - [ERROR] Azure  ...
    17:40:28 - [ERROR] + 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    17:40:28 - [ERROR] ~~~
    17:40:28 - [ERROR]     + CategoryInfo          : ObjectNotFound: (New-AzureRmResourceGroup:String 
    17:40:28 - [ERROR]    ) [Deploy-AzureResourceGroup.ps1], CommandNotFoundException
    17:40:28 - [ERROR]     + FullyQualifiedErrorId : CommandNotFoundException,Deploy-AzureResourceGro 
    17:40:28 - [ERROR]    up.ps1
    17:40:28 - [ERROR]  
    17:40:28 - 
    17:40:28 - Deploying template using PowerShell script failed.

PFB我的json文件作为模板,

{  
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
 "setup-sites-non-prod-service-planName": {
  "type": "string",
  "defaultValue": "setup-sites-non-prod-service-plan",
  "minLength": 1
 },
"setup-sites-non-prod-service-planSkuName": {
  "type": "string",
  "defaultValue": "F1",
  "allowedValues": [
    "F1",
    "D1",
    "B1",
    "B2",
    "B3",
    "S1",
    "S2",
    "S3",
    "P1",
    "P2",
    "P3",
    "P4"
  ],
  "metadata": {
    "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
  }
}
},
"variables": {
"setup-remserv-com-au-npName": "[concat('setup-remserv-com-au-np', uniqueString(resourceGroup().id))]"
},
"resources": [
{
  "name": "[variables('setup-remserv-com-au-npName')]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "apiVersion": "2015-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', parameters('setup-sites-non-prod-service-planName'))]"
  ],
  "tags": {
    "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', parameters('setup-sites-non-prod-service-planName')))]": "Resource",
    "displayName": "setup-remserv-com-au-np"
  },
  "properties": {
    "name": "[variables('setup-remserv-com-au-npName')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('setup-sites-non-prod-service-planName'))]"
  }
},
{
  "name": "[parameters('setup-sites-non-prod-service-planName')]",
  "type": "Microsoft.Web/serverfarms",
  "location": "[resourceGroup().location]",
  "apiVersion": "2015-08-01",
  "sku": {
    "name": "[parameters('setup-sites-non-prod-service-planSkuName')]"
  },
  "dependsOn": [ ],
  "tags": {
    "displayName": "setup-sites-non-prod-service-plan"
  },
  "properties": {
    "name": "[parameters('setup-sites-non-prod-service-planName')]",
    "numberOfWorkers": 1
  }
}
],
"outputs": {}
}

2 个答案:

答案 0 :(得分:0)

您需要获取Azure RM模块。打开Powershell并执行以下命令:

Install-Module AzureRM

然后做:

Import-Module AzureRM

您可以从Powershellgallery获得它: https://www.powershellgallery.com/packages/AzureRM/6.13.1

答案 1 :(得分:0)

在使用Az模块和来自github的部署脚本(Deploy-AzureResourceGroup.ps1)时遇到了相同的问题。部署脚本仍引用AzureRm模块,因为我猜这部分代码尚未在github上更新。我将以下代码替换为

#Requires -Module AzureRM.Resources
#Requires -Module Azure.Storage
#Requires -Module @{ModuleName="AzureRm.Profile";ModuleVersion="3.0"}

此代码

#Requires -Module Az.Resources
#Requires -Module Az.Storage
#Requires -Module @{ModuleName="Az.Accounts";ModuleVersion="1.6.4"}

,并且还将所有 Get-AzureRmResourceGroup 引用替换为 Get-AzResourceGroup ,并将 Test-AzureRmResourceGroupDeployment 引用替换为 Test-AzResourceGroupDeployment Deploy-AzureResourceGroup.ps1代码中的“ strong>”。