Getting the right storage container name in a Bicep template
When creating a blob storage container in an ARM/Bicep template, as a non-nested resource, you create a top-level resource like Microsoft.Storage/storageAccounts/blobServices/containers
. However, the name
property of that container cannot simply be something like somecontainer
, because it needs to indicate the storage account, and the blob service. So the name
must be something like mystorageaccount/default/somecontaine
.
If you want to use the container in other places of the Bicep template, you certainly want to refer to the container object and take the name from there, rather then using the literal container name string (and them preventing Bicep from creating the appropriate dependsOn
). But referring to container.name
unfortunately gives us the 3-segment name, and we only want the last segment.
Therefore, we need to use ARM string functions to retrieve the last segment, i.e. the text after the last /
character in the name.
Assuming you have a string x
, you could use this Bicep expression to extract the name, i.e. for a/b/c
get c
:
substring(x, lastIndexOf(x,'/') + 1, length(x) - lastIndexOf(x, '/') - 1)
See below for a quick Bicep sample:
Deploying this template would give you the following outputs (just with a different storage account name):
Last updated