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