通过ARM模板配置经典云服务 [英] Provision classic cloud service via ARM template

查看:54
本文介绍了通过ARM模板配置经典云服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的一个项目中,我们试图在Azure上自动化云组件的部署.对于大多数组件(基本上是所有ARM组件,例如Redis,Service bus,App Service等),我们能够使用ARM模板和Powershell脚本来实现.

In one of our project, we are trying to automate deployment of cloud components on Azure. For majority of components (basically all ARM components like Redis, Service bus, App Service etc.) we were able to achieve it using ARM templates and Powershell script.

但是,我们受困于 Cloud Service(经典)组件.云服务组件中仅包含WebRole,无需配置VM.

However, we are stuck at Cloud Service (classic) component. Cloud service component contains only WebRole in it and no VM needs to be provisioned.

我们可以通过经典的部署模型,即在Power Shell中使用ASM命令.但是由于ARM模型支持从azure门户进行资源调配和部署,因此我想知道ARM REST API也必须对此组件提供现成的支持.我试图弄清楚,但找不到任何相关文档.

We can go via classic deployment model i.e. using ASM commands in power shell. But since, ARM model supports provisioning and deployment from azure portal so I was wondering ARM REST API's must have out of box support for this component as well. I try to figure out but couldn't find any related documentation to it.

Azure模板(AzureDeploy.json)

Azure template (AzureDeploy.json)

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "parameters": {
        "name": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "resources": [
         {
            "apiVersion": "2014-06-01",
            "name": "[parameters('name')]",
            "location": "[parameters('location')]",
            "type": "Microsoft.ClassicCompute/domainNames"
        }
    ]
}

Powershell脚本:

Powershell script:

Param(
    [string] $ResourceGroupLocation = 'South India',
    [string] $ResourceGroupName = 'FreeTrial',
    [string] $TemplateFile = 'AzureDeploy.json'
)

$TemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateFile))

New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop 
New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
                                   -ResourceGroupName $ResourceGroupName `
                                   -TemplateFile $TemplateFile `
                                   -Force -Verbose

如果我尝试执行上述脚本,则执行会在一个小时左右的检查部署中停滞,必须手动终止脚本执行. .

If I try to execute the above script, execution gets stuck at Checking deployment for an hour or so and have to manually kill the script execution. .

但是,如果我在Power Shell中运行以下命令,它将成功在门户网站中创建资源:

However, if I ran following command in power shell, it succesfully creates a resource in portal:

New-AzureRmResource-位置南印度" -ResourceName "cloudsmplservice" -ResourceType "Microsoft.ClassicCompute/domainNames" -ResourceGroupName"FreeTrial"

New-AzureRmResource -Location "South India" -ResourceName "cloudsmplservice" -ResourceType "Microsoft.ClassicCompute/domainNames" -ResourceGroupName "FreeTrial"

但是我不明白ARM模板方法有什么问题.有人可以用第一种方法指导我解决这个问题吗?

But I do not understand what's an issue with ARM template approach. Can someone please direct me to the problem in first approach?

附录:

我发现了一个奇怪的行为.如果我在资源定义中对资源名称值进行了硬编码或在Powershell提示时将其传递,则部署可以正常进行.

I found a strange behaviour. If I hardcode the resource name value in the resource definition OR pass it when powershell prompt for it, deployment works fine.

但是,如果我为参数设置了一些默认值或通过参数文件传递了它,则它不起作用.

However, if I set some default Value for parameter OR pass it via parameter file, its not working.

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "cloudName": {
      "type": "string",
      "defaultValue": "cloudsrvc"
    }
  },
  "resources": [
    {
      "apiVersion": "2015-06-01",
      "name": "[parameters('cloudName')]",
      "location": "[resourceGroup().location]",
      "type": "Microsoft.ClassicCompute/domainNames"
    }
  ]
}


附录2:

似乎是一些powershell配置问题.将向Azure团队报告更多详细信息.因此,到目前为止,它可以通过简单的步骤进行复制:

Seems like some powershell configuration issue. Will report it to Azure team with more details. So, far was able to reproduce it with simple steps:

  1. 天蓝色创建新的VM.
  2. 导入的AzureRM模块.
  3. 尝试使用默认值模板配置云服务. (如前所述)
  4. 现在尝试通过从powershell传递参数来进行配置. (工作正常)
  5. 现在使用默认值模板重试. (工作正常)

推荐答案

我建议您从Azure门户中的模板部署验证您的Cloud Service ARM模板.

I will recommend you to validate your Cloud Service ARM Template from the Template Deployment in the Azure portal.

我能够使用下面的模板部署裸机Cloud Service,并且部署可以在几秒钟内成功完成.

I am able to deploy a bare metal Cloud Service using the template below and the deployment is successful within seconds.

当您尝试从Azure门户创建新的Cloud Service时,还可以通过单击Automation选项来对Cloud Service ARM模板进行反向工程".

You can also "reverse engineer" the Cloud Service ARM Template by clicking on the Automation option when try to create a new Cloud Service from the Azure portal.

我没有看到通过ARM模板方法实现Cloud Service自动化的问题.

I didn't see the problem in automating Cloud Service by the ARM Template approach.

注意:

我已将其部署在印度南部位置,并且可以正常工作.

I have deployed this in South India location and it works.

附录:

我已经使用您的PowerShell脚本按以下方式部署了模板,它也可以正常工作.

I have deployed the template as below using your PowerShell script and it works as well.

Azure PowerShell版本为 4.3.1(2017年8月).

Azure PowerShell version is 4.3.1 (August 2017).

屏幕截图如下.

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "resources": [
        {
            "apiVersion": "2016-11-01",
            "name": "[parameters('name')]",
            "location": "[parameters('location')]",
            "type": "Microsoft.ClassicCompute/domainNames"
        }
    ]
}

附录2:

尝试使用具有默认参数值的模板,并且部署也可以成功进行.

Try with template with default param values and the deployment is also working successful.

注意:我注意到您的api版本比较旧,而我的云服务的api版本是 2016-11-01

Note: I notice your api version is older and the api version for my cloud service is 2016-11-01

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "name": {
      "type": "string",
      "defaultValue": "[resourceGroup().name]"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [
    {
      "apiVersion": "2016-11-01",
      "name": "[parameters('name')]",
      "location": "[parameters('location')]",
      "type": "Microsoft.ClassicCompute/domainNames"
    }
  ]
}

这篇关于通过ARM模板配置经典云服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆