Azure ARM pattern - access to a resource identifier created by one ARM pattern in another ARM pattern

We deploy azure resources using the ARM template as part of our build process before deploying the real application.

So far, all of our application resources have been autonomous within the resource group . for example, a web application that requires a sql server and storage account are grouped into one resource group.

However, we came across a scenario / need where we need to share a resource, for example. storage account in resource groups. Resource group A has a storage account and the web application of resource group B requires the connection / application strings related to the storage account to be in appconfig.json/web.config .

Question

How to create a connection string for an application in resource group B to connect to a resource in resource group A, since I need to get the identifier of resource group A in B

This is how I build the connection string if they are in the same resource group

  "variables" { "storageAccounts_id": "[concat(**resourceGroupA**().id,'/providers/Microsoft.Storage/storageAccounts/', variables('storageAccntName'))]", }, "resources": [ { "apiVersion": "2015-08-01", "type": "config", "name": "connectionstrings", "dependsOn": [ "[resourceId('Microsoft.Web/sites', variables('MyWebSiteName'))]" ], "properties": { "AzureWebJobsDashboard": { "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccntName'),';AccountKey=',concat(listKeys(variables('storageAccounts_id'),'2015-05-01-preview').key1))]", "type": "Custom" }, } } ] 

Notes: I looked at this site https://azure.microsoft.com/en-us/documentation/articles/resource-group-linked-templates/ about related templates, but it doesn’t suit our current build process that uses Octo (if there isn’t something that I might miss) that deploys ARM first and then the application (network).

+5
source share
2 answers

In this case, when the storage account name is known and independent of the resource group (for example, uniqueString (resourceGroup (). Id)), you can simply use a longer form for resourceId () . The full form looks like this:

 resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2]...) 

therefore, we can optionally provide the names subscriptionId and resourceGroupName.

 listKeys(resourceId(parameters('ResourceGroupAName'), 'Microsoft.Storage/storageAccounts', variables('ccPaymentStorageName')) 

If he was in a different subscription, you can also specify a subscription.

 listKeys(resourceId(parameters('SubscriptionId'), parameters('ResourceGroupAName'), 'Microsoft.Storage/storageAccounts', variables('ccPaymentStorageName')) 

If the storage account name depends on a resource group, for example

 "storageName": "[concat('mystorage', uniqueString(resourceGroup().id))]" // in Resource Group A 

then you will also need to always run the template that creates this account and display the repository name and resource group or look for a way to link to another resource group to get an identifier so that the name can be recreated.

I was able to use something like this to "recreate" the resource group identifier so that I could create my own repository account name.

 "otherResourceGroupId": "[concat(subscription().id, '/resourceGroups/', parameters('ResourceGroupName'))]" 

Then I can use this to generate the name accordingly:

 "storageAccountName": "[concat('mystorage', uniqueString(variables('otherResourceGroupId')))]" 
+2
source

You can try two things: 1. use the variable "resourcegroupAid": "concat [(variables ('resourceGroupAName'), '(). Id')]" or 2.RGID ":" resourceid [concat ('/ subscriptions /' , subscription (). SubscriptionId, '/ resourceGroups /', variables ('resourceGroupAName')]) ",

contact https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions

-1
source

All Articles