Subscription scope function #4791
-
Hi Team, I have use case to deploy vnet to different subscription using subscription name ( not subscription id) I have added below function in scope under my module subscription(last(split(tenantResourceId('Microsoft.Subscription/aliases', sub.subscriptionName), '/'))) I am passing subscriptionName under my parameter file FYI I am using service connection on management group to deploy into different subscription under it. Please guide on this. main.biceptargetScope = 'managementGroup'
param subscriptions array
module rg 'RG.bicep' = [for sub in subscriptions: {
name: sub.subscriptionName
scope: subscription(last(split(tenantResourceId('Microsoft.Subscription/aliases', sub.subscriptionName), '/')))
params: {
rgName: sub.rgName
location: sub.location
vnet : sub.vnet
}
}] RG.biceptargetScope = 'subscription'
param rgName string
param location string
param vnet object
resource resgroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: rgName
location: location
}
module network 'network.module.bicep' = {
name: 'rgdeploy'
scope: resourceGroup(rgName)
params: {
vnet:vnet
}
dependsOn: [
resgroup
]
} parameters.json{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptions": {
"value": [
{
"subscriptionName": "es-corporate",
"rgName": "rg-corp-lz-network-we",
"environment": "dev",
"vnet": {
"name": "vnet-corp-lz-we",
"addressPrefix": "xxxxx",
"subnets": [
{
"name": "snet-corp-lz-dev-001",
"addressPrefix": "xxxxxx"
}
]
},
"location" :"westeurope"
}
]
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Unfortunately, alias names are not a valid input for subscriptions. That API was created to create new subscriptions, but that alias value is not used in other contexts. IOW, it's a vehicle to get a subscription GUID, which is what you need to perform any further actions with that subscription. |
Beta Was this translation helpful? Give feedback.
-
So i have been wondering how to handle this request for some time. Now I am wondering are you looking to use the Subscription DisplayName to select the subscription ? e.g. $Search = 'BENWILK'
Invoke-azRestMethod -Method GET -Uri https://management.azure.com/subscriptions?api-version=2021-01-01 | foreach content | convertfrom-json | foreach value | where displayname -match $Search
id : /subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3
authorizationSource : Legacy, RoleBased
managedByTenants : {}
subscriptionId : b8f402aa-20f7-4888-b45c-3cf086dad9c3
tenantId : 72f988bf-86f1-41af-91ab-2d7cd011db47
displayName : MSFT BENWILK AIRS #<-- displayname from search
state : Enabled I originally had thought that the subscription alias was the same as the displayname, however I realize that it is not. So the issue here is that I am sure you can have duplicate displaynames and also there is no guarantee that no one has changed the displayname. So basically the subscription GUID is the reliable way to lookup a subscripiton. If you are using Landing Zones to pre-create the subscriptions and the displaynames and then you want to look up a subscription guid from the displayname I think that could be reliable, given you own the whole process, however once it was handed over, someone can just come along and update the dusscription displayname. So let me know if you still have this ask? If you do, I think we could figure out how to call the list subscriptions and filter on the displayname and then return the guid, if it was within Bicep or within a deployentScript executed from Bicep. |
Beta Was this translation helpful? Give feedback.
-
@brwilkinson So there's no workaround for this yet? My use case is to deploy management group with a bunch of subscriptions and enable |
Beta Was this translation helpful? Give feedback.
Unfortunately, alias names are not a valid input for subscriptions. That API was created to create new subscriptions, but that alias value is not used in other contexts. IOW, it's a vehicle to get a subscription GUID, which is what you need to perform any further actions with that subscription.