Azure: previous deployment from ‘MM/dd/yyyy hh:mm:ss’ is still active

Another helpful Azure error message:

New-AzureRmResourceGroupDeployment : 08:46:04 - Resource Microsoft.Resources/deployments 'linkedTemplate-VM' failed with message '{
  "error": {
    "code": "DeploymentActive",
    "message": "Unable to edit or replace deployment 'linkedTemplate-VM': previous deployment from '6/28/2017 7:45:57 AM' is still active (expiration time is '7/5/2017 7:45:56 AM'). Please see 
https://aka.ms/arm-deploy for usage details."

I have a master template with linked templates. The whole child template (linkedTemplate-VM), which deploys the actual VM, is iterated X number of times, using CopyIndex(), instantiated in the master template. (Where X is the number of VMs I want). When I increased X from 1 to 2, I started getting this error. The reason is that Azure will deploy each copy simultaneously and as “linkedTemplate-VM” was already running for the first VM, it couldn’t run a second time. The solution is to give it a unique name.

The problem I had was that “linkedTemplate-VM” was actually a child of a child template and the copyIndex() function was instantiated in the parent template. The answer is to save the copyIndex() value into a variable in the template where copyIndex() is first instantiated and pass that variable down to the siblings.

In the following example, I declare the variable properties.parameters.seqNo, and it’s value is copyIndex (with padding and an offset. Padding so it resolves as 001, 002… and the offset of 1 is so that it starts counting from 1 as opposed to the default 0).

 

{
        "name": "linkedTemplate-VM-Net",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2016-09-01",
        "dependsOn": [
          "[resourceId('Microsoft.Resources/deployments/', 'linkedTemplate-vNet')]",
          "[resourceId('Microsoft.Resources/deployments/', 'linkedTemplate-SA')]"
        ],
        "copy": {
          "name": "interate",
          "count": "[parameters('vmQty')]"
        },
        "properties": {
          "mode": "Incremental",
          "templateLink": {
            "uri": "[concat(uri(deployment().properties.templateLink.uri, concat(variables('sharedtemplate').nestedFolder,'/', variables('sharedTemplate').nested3, '.json')), parameters('artifactsLocationSasToken'))]",
            "contentVersion": "1.0.0.0"
          },
          "parameters": {
            "sharedVariables": { "value": "[variables('sharedVariables')]" },
            "sharedTemplate": { "value": "[variables('sharedTemplate')]" },
            "vhdStorageAccountName": { "value": "[reference('linkedTemplate-SA').outputs.vhdStorageAccountName.value]" },
            "artifactsLocationSasToken": { "value": "[parameters('artifactsLocationSasToken')]" },
            "adminPassword": { "value": "[parameters('adminPassword')]" },
            "seqNo": { "value": "[padleft(copyIndex(1),3,'0')]" }

          }
        }
      },

In the next level, I retrieve the variable in the parameters block and use it in the name of the linked template (line 14):

"parameters": {
    "seqNo": {
      "type": "string",
      "metadata": {
        "description": "Padded CopyIndex from master"
      }
    },
    "anotherParameter": {}
},
variables:{}
resources :[
 {
  {
      "name": "[concat('linkedTemplate-VM-',parameters('seqNo'))]",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2016-09-01",
      "dependsOn": [
        "[variables('nicName')]"
      ],
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[concat(uri(deployment().properties.templateLink.uri, concat( parameters('sharedTemplate').nested4, '.json')), parameters('artifactsLocationSasToken'))]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "sharedVariables": { "value": "[parameters('sharedVariables')]" },
          "vhdStorageAccountName": { "value": "[parameters('vhdStorageAccountName')]" },
          "artifactsLocationSasToken": { "value": "[parameters('artifactsLocationSasToken')]" },
          "nicName": { "value": "[variables('nicName')]" },
          "adminPassword": { "value": "[parameters('adminPassword')]" },
          "vmNameSuffix": { "value": "[concat(padleft(split(reference(variables('nicName')).ipConfigurations[0].properties.privateIPAddress,parameters('sharedTemplate').delimiter)[1],3,'0'),padleft(split(reference(variables('nicName')).ipConfigurations[0].properties.privateIPAddress,parameters('sharedTemplate').delimiter)[2],3,'0'),padleft(split(reference(variables('nicName')).ipConfigurations[0].properties.privateIPAddress,parameters('sharedTemplate').delimiter)[3],3,'0'))]" },
          "publicIpAddressType": { "value": "[variables('publicIPAddressType')]" },
          "publicIpAddressName": { "value": "[variables('publicIpAddressName')]" }
        }
      }
    }
 }
]

 

HTH

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

This site uses Akismet to reduce spam. Learn how your comment data is processed.