Azure / Azure/bicep

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

Open
#19,267 0 comments 0 reactions 1 assignee Claimed by @anthony-c-martin View on GitHub
story: bicep deploy
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.41.2 (3e403ea7c1)

**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:
```json
{
"experimentalFeaturesEnabled": {
"deployCommands": true
}
}

```

Create main.bicepparam with content:

```bicep
var subscriptionId = readCliArg('subscriptionId')

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

Create main.bicep file with content:

```bicep
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:

```sh
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:

```bicep
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.