0

TL;DR

The following line works fine as part of an ARM script ran in an Azure DevOps ARM Template Deployment task but, when ran from PowerShell, it fails to pull the subscription and the resource group.

"serverFarmId": "[concat('/subscriptions/', subscription(), '/resourcegroups/', resourceGroup(), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"

how can I set the subscription and resource group variables so the ARM functions can pull the values?

P.S. It's ok If I have to first get them and then set them manually for the script to consume, as long as I can use the same script for DevOps and PowerShell.


Here's the resources section of the template which, again, when deployed from a pipeline it pulls the subscription and the resource group from whatever is set in the task parameters.

"resources": [
{
  "apiVersion": "2018-11-01",
  "name": "[parameters('name')]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "tags": {},
  "dependsOn": [
    "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
  ],
  "properties": {
    "name": "[parameters('name')]",
    "siteConfig": {
      "metadata": [
        {
          "name": "CURRENT_STACK",
          "value": "[parameters('currentStack')]"
        }
      ]
    },
    "serverFarmId": "[concat('/subscriptions/', subscription(), '/resourcegroups/', resourceGroup(), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
    "clientAffinityEnabled": true
  }
},
{
  "apiVersion": "2018-11-01",
  "name": "[parameters('hostingPlanName')]",
  "type": "Microsoft.Web/serverfarms",
  "location": "[resourceGroup().location]",
  "kind": "",
  "tags": {},
  "dependsOn": [],
  "properties": {
    "name": "[parameters('hostingPlanName')]"
  },
  "sku": {
    "Tier": "[parameters('sku')]",
    "Name": "[parameters('skuCode')]"
  }
}
]
2
  • Could you please share the Powershell command that you use to deploy your ARM template ? Commented Nov 9, 2021 at 12:42
  • 1
    Your answer was the solution, adding the .subscriptionId and .name got it running from powershell. Commented Nov 9, 2021 at 12:45

1 Answer 1

1

subscription() and resourceGroup() do return objects based on your context. You should consider querying attributes instead like : subscription().subscriptionId and resourceGroup().name considering how you are constructing your ID. I am not sure why it works in your ARM template though.

As a side comment, you could make use of the resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2], ...) function as explained here, under the hood it performs the same as you did (concat).

Sign up to request clarification or add additional context in comments.

1 Comment

I tested it from PS and it worked, later today I'll rerun the pipeline to ensure that it continues to work from the pipeline, if so I'll mark it as the accepted answer. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.