10

I am new to writing Azure Resource Manager templates; I have a requirement where I need to retrieve my Azure Storage Account Connection String. I am able to retrieve it's access key using [listKeys(variables('storageAccountId'), '2019-04-01').keys[0].value] where storageAccountId is [resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))] but I'm unable to do so for the connection string(primary).

Now, my question is like we have listKeys function to retrieve the access keys, do we have some system function for retrieving connection string also? Or do we need to concatenate and create the connection string? I have the values for Storage Account Name & Resource Group Name. How can I do this using ARM?

The Inquisitive Coder
  • 1,085
  • 3
  • 20
  • 43

1 Answers1

15

According to my research, Azure ARM template does not provide the function that we can use to list storage account connection string. We just can ARM template function to list access key(listkeys) list account SAS token(listAccountSas) or list service SAS token(listServiceSas). For more details, please refer to the document.

So if you want to get storage account connection string, I suggest you use Azure ARM template function concat to combine the connection string. For example

"outputs": {  
        "storageAccountConnectionString": {  
            "type": "string",  
            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId(parameters('resourceGroupName'),'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-04-01').keys[0].value,';EndpointSuffix=core.windows.net')]"  
        },

        }  
    }  
Jim Xu
  • 21,610
  • 2
  • 19
  • 39
  • 1
    But if we validate with ARM TTK for marketplace deployments, it complains about hardcoded `core.windows.net`, and even if we break the string with inner concat(), I am still getting weird error while deployment like - `expected token 'Identifier' and actual 'LeftSquareBracket'.'.` even if all ARM TTK tests passes. – Koder101 Nov 07 '21 at 15:28