Skip to content

"bicep deploy" does not allow for deployments in scopes other than resourceGroup #19267

@gXkch

Description

@gXkch

Bicep version
Bicep CLI version 0.41.2 (3e403ea)

Describe the bug
Using bicep deploy or bicep what-if does only work if bicep resources are deployed with resource group as target scope. Trying to deploy a bicep file with target scope scubscription fails because location for deployment cannot be set.

To Reproduce
Create bicepconfig.json with content:

{
    "experimentalFeaturesEnabled": {
        "deployCommands": true
    }
}

Create main.bicepparam with content:

var subscriptionId = readCliArg('subscriptionId')

using 'main.bicep' with {
  scope: '/subscriptions/${subscriptionId}'
  mode: 'deployment'
}

Create main.bicep file with content:

targetScope = 'subscription'

resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
  name: 'sample-rg'
  location: 'westeurope'
}

The following error gets produced when trying to execute bicep deploy or bicep what-if:

Unhandled exception. Azure.RequestFailedException: The 'location' property must be specified for 'main'. Please see https://aka.ms/arm-deployment-subscription for usage details.
Status: 400 (Bad Request)
ErrorCode: InvalidDeployment

Content:
{"error":{"code":"InvalidDeployment","message":"The 'location' property must be specified for 'main'. Please see https://aka.ms/arm-deployment-subscription for usage details."}}

Proposal:
Add an option to set the deployment location for scopes like subscription or management group:

var subscriptionId = readCliArg('subscriptionId')

using 'main.bicep' with {
  scope: '/subscriptions/${subscriptionId}'
  mode: 'deployment'
  location: 'westeurope'
}

I did not find anything in the documentation that show how to do this. If there is a way, please document it.

Metadata

Metadata

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions