Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference resources in other subscriptions with Bicep?

I use Bicep to create an Azure Function using an app service plan that was created earlier in another subscription.

I get the following error:

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"NotFound","message":"{\r\n  \"Code\": \"NotFound\",\r\n  \"Message\": \"Cannot find ServerFarm with name asp-intsharedep-prod.\",\r\n  \"Target\": null,\r\n  \"Details\": [\r\n    {\r\n      \"Message\": \"Cannot find ServerFarm with name myasp.\"\r\n    },\r\n    {\r\n      \"Code\": \"NotFound\"\r\n    },\r\n    {\r\n      \"ErrorEntity\": {\r\n        \"ExtendedCode\": \"51004\",\r\n        \"MessageTemplate\": \"Cannot find {0} with name {1}.\",\r\n        \"Parameters\": [\r\n          \"ServerFarm\",\r\n          \"myasp\"\r\n        ],\r\n        \"Code\": \"NotFound\",\r\n        \"Message\": \"Cannot find ServerFarm with name myasp.\"\r\n      }\r\n    }\r\n  ],\r\n  \"Innererror\": null\r\n}"}]}}

It is only a simple bicep file, no modules, no targetScope. I refer to my app service plan by:

resource serverFarm 'Microsoft.Web/serverfarms@2020-06-01'  existing = {
  name: aspName
  scope: resourceGroup('subscriptionid','rg-shared-asp')
}

Is it not possible to reference app service plans in other subscriptions?

like image 428
alefa240 Avatar asked Oct 15 '25 08:10

alefa240


1 Answers

The default target scope is resourcegroup. So if you don't state a target scope, the resourcegroup scope is set implicitly. The available scopes are resource group, subscription, management group, and tenant. So if the other subscription is under the same tenant or management group, you can set the scope to either of them. For example, state in your bicep file:

targetScope = 'tenant'

And on az cli:

az deployment tenant create \
  --name demoTenantDeployment \
  --location WestUS \
  --template-file main.bicep

https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/scope-extension-resources#apply-at-deployment-scope

like image 92
MoonHorse Avatar answered Oct 19 '25 04:10

MoonHorse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!