Search code examples
azureazure-resource-managerazure-rm-templateazure-automation

Azure Automation Account & Runbooks ARM Template, uri problem?


i need to deploy Storage Automation Account & 5 runbooks using ARM templates & Azure Devops Pipeline.

I created dev.parameters.json. Here are contents of file.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "comments": "Azure Portal Mentioned - For Python 3.8 (preview) packages use wheel files targeting cp38-amd64",
        "parameters": {
        "automation_account_name": {
            "value": "autoacc-xxxxxxxx-dev"
        },
        "blob_container_name": {
            "value": "python-xxxxxxxxxx-codes"
        },
        "runbook_list_array":{
            "value": ["script1.py","script2.py","script3.py","script4.py","script5.py"]
        },
        "storage_account_name":{
                    "value" : "storxxxxxxxdev"
        }
    }
}

And here is my ARM template (AutomationAccountTemplate.json)

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "automation_account_name": {
      "defaultValue": null,
      "type": "String"
    },
    "runbook_list_array": {
      "defaultValue": null,
      "type": "array"
    },
    "blob_container_name": {
      "defaultValue": null,
      "type": "String"
    },
    "storage_account_name": {
      "defaultValue": null,
      "type": "String"
    }
  },
  "variables": {
  },
  "resources": [
    {
      "type": "Microsoft.Automation/automationAccounts",
      "apiVersion": "2022-08-08",
      "name": "[parameters('automation_account_name')]",
      "location": "[resourceGroup().location]",
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "publicNetworkAccess": true,
        "disableLocalAuth": false,
        "sku": {
          "name": "Basic"
        },
        "encryption": {
          "keySource": "Microsoft.Automation",
          "identity": {}
        }
      }
    },
    {
      "type": "Microsoft.Automation/automationAccounts/runbooks",
      "apiVersion": "2022-08-08",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Automation/automationAccounts', parameters('automation_account_name'))]"
      ],
      "name": "[concat(parameters('automation_account_name'), '/', parameters('runbook_list_array')[copyIndex('runbookLoop')]   )]",
        "copy": {
            "name": "runbookLoop",
            "count": "[length(parameters('runbook_list_array'))]"
        },
      "properties": {
        "description": "Runbook description",
        "runbookType": "Python3",
        "logVerbose": false,
        "logProgress": false,
        "logActivityTrace": 0,
        "publishContentLink": {
          "uri": "[concat('https://', parameters('storage_account_name'), '.blob.core.windows.net/', parameters('blob_container_name'), '/', parameters('runbook_list_array')[copyIndex('runbookLoop')])]"
        }

      }
    }
  ],
  "outputs": {
    "nameResult": {
      "type": "array",
      "value": "[parameters('runbook_list_array')]"
    }
  }
}

When i run pipeline i get this error: When i run pipeline i get this error

I also tried "ARM template test toolkit" it gives me problem with URI:

 URIs Should Be Properly Constructed
    [-] URIs Should Be Properly Constructed (13 ms)
        Function 'concat' found within 'uri' Line: 73, Column: 12

I double checked my URI is ok OR am i missing something ?


Solution

  • ok. The problem is not with the ARM template. The problem is that my pipeline is not able READ script from storage. my issue was fixed after I changed permissions on blob.