Azure / Azure/bicep

Bicep Snapshots and reference Graph resources

Open
#18,109 2 comments 1 reaction 0 assignees View on GitHub
Bicep Snapshot
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.37.4 (27cc8db2ed)

**Describe the bug**
when executing bicep snapshot on template that reference Graph extension resources those references are not displayed correctly.

**To Reproduce**
Let's have the following example

main.bicep

```bicep
extension 'br:mcr.microsoft.com/bicep/extensions/microsoftgraph/v1.0:1.0.0' as microsoftGraphV1_0

param upn string

resource user 'Microsoft.Graph/users@v1.0' existing = {
userPrincipalName: upn
}

resource roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: '00000000-0000-0000-0000-000000000000'
scope: resourceGroup()
properties: {
principalId: user.id
roleDefinitionId: '00000000-0000-0000-0000-000000000000'
}
}
```

param.bicepparam
```bicepparam
using 'main.bicep'

param upn = 'stan@contoso.com'

```

the end result when running snapshot command is:

```json
{
"predictedResources": [
{
"id": "[format('/subscriptions/f4b90a18-b44d-439b-a1b7-3c7fae8a8d54/resourceGroups/{0}/providers/Microsoft.Authorization/roleAssignments/00000000-0000-0000-0000-000000000000', resourceGroup().name)]",
"type": "Microsoft.Authorization/roleAssignments",
"name": "00000000-0000-0000-0000-000000000000",
"apiVersion": "2022-04-01",
"properties": {
"principalId": "[reference('user').id]",
"roleDefinitionId": "00000000-0000-0000-0000-000000000000"
}
}
],
"diagnostics": []
}
```

You can see the reference is reference('user').id which for me is not correct representation. You are missing the resource type and the name of the actual resource. You only have the name of the resource as defined within template which is not useful information at all. It is confusing information. The value should be `"[reference('Microsoft.Graph/users/stan@contoso.com', 'v1.0').id]"`.

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with main.bicep and param.bicepparam using the bicep snapshot command, then trace how the Microsoft.Graph/users reference is rendered in the snapshot JSON. Done means the predicted resource uses the actual Graph resource type and name, such as Microsoft.Graph/users/stan@contoso.com with API version v1.0, rather than reference('user').id.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.