3
votes

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.

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

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.


What I have tried so far

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 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. Script execution.


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

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

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


Addendum:

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"
    }
  ]
}

Addendum2:

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. Created a fresh VM in azure.
  2. Imported AzureRM modules.
  3. Try to provision cloud service with default value template. (Stuck as mentioned)
  4. Try to provision now by passing the parameter from powershell. (Worked fine)
  5. Now try again with default value template. (Worked fine)
2

2 Answers

4
votes

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

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

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.

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

Note:

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

Addendum:

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

Azure PowerShell version is 4.3.1 (August 2017).

Screenshot as below. enter image description here

{
    "$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"
        }
    ]
}

Addendum 2:

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

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

enter image description here

{
  "$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"
    }
  ]
}
1
votes

We also could use the REST API to do that,I test it with fiddler.

https://management.azure.com/subscriptions/{subscriptionid}/resourceGroups/{resourcegroupname}/providers/Microsoft.ClassicCompute/domainNames/{cloudservicename}?api-version=2016-04-01

enter image description here

Note: please make sure that your subcription support to create the cloudservice in that location. If it is not supported, we will get the following error.

The location constraint is not valid