0
votes

Hey It's been days that I am trying to deploy my first logic app with dynamic resource group name and subscription id using Azure DevOps, I looked on several links that doing something like in my template.json file:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "workflows_app_name": {
            "defaultValue": "myLogicApp",
            "type": "String"
        },
        "connections_azuretables_externalid": {
            "value": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/azuretables",
            "type": "String"
        }
....

tried this too:

 "connections_azuretables_externalid": {
            "defaultValue": "[concat('/subscriptions/', subscription().id, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/connections/azuretables')]",
            "type": "String"
        }

and this as well trying to pass resourcegroup name and subscription in paramters:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "workflows_app_name": {
            "defaultValue": "myLogicApp",
            "type": "String"
        },
        "connections_azuretables_externalid": {
            "defaultValue": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('ressourceGroupName'), '/providers/Microsoft.Web/connections/azuretables')]",
            "type": "String"
        },
        "subscriptionId": {
          "type": "String"
        },
        "ressourceGroupName": {
          "type": "String"
        },
.....
}

but getting errors similar to this

Property id '[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('ressourceGroupName'), '/providers/Microsoft.Web/connections/azuretables')]' at path 'properties.parameters.$connections.value.azuretables.connectionId' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'

I know I am missing or misunderstanding something but can't figure it out! Thanks.

2

2 Answers

1
votes

You can add the API property in the properties section of template.json file like below and then refer the variable name in Library of DevOps

"api": {
         "id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/',variables('rgLocation'),'/managedApis/azureblob')]"
       }

In this case the storage location is Blob, you can customize it to storage of your choice

0
votes

Logic App: Pass dynamic subscription id and resource group name in an ARM template

You could try to add Azure Cli task to get the subscription and create a pipeline variable called subscriptionId:

  jobs:
  - job: GetSubscription
    steps:
    - checkout: none
    - task: AzureCLI@2
      inputs:
        azureSubscription: 'CTP.AssuranceDW-Non-Production'
        scriptType: 'ps'
        scriptLocation: 'inlineScript'
        inlineScript: |
          $id = convertfrom-json (az account list --query "[?isDefault].id | [0]")
          Write-Host $id
          echo "##vso[task.setvariable variable=subscriptionId]$id"
    - powershell: Write-Host $(subscriptionId)

Then, we could use the overrideParameters or replacetokens task to pass this value to the ARM template.

Please check the thread How to pass an Azure pipeline variable to an ARM template used by AzureResourceManagerTemplateDeployment@3 task? for some more details.