sqlRoleDefinitions - role definition exists when running a second time
- Dominant language
- TypeScript
- Stars
- 108
- Forks
- 44
- Avg merge
- 18h 53m
- Merged PRs (30d)
- 29
Description
I'm using the following as part of a module.
It throws an error (the second time of running)
> A Role Definition with the name [Read Write Role] already exists, please choose a unique name for your new Role Definition.
How can I get it to create the role if it doesn't exist, but return the role definition if it _does_ exist?
```
@description('The name of the Cosmos DB account will have this role assigned to it')
param cosmosDbAccountName string
var roleDefinitionId = guid('sql-role-definition', cosmosDbAccount.id)
resource cosmosDbAccount 'Microsoft.DocumentDB/databaseAccounts@2023-11-15' existing = {
name: cosmosDbAccountName
}
var dataActions = [
'Microsoft.DocumentDB/databaseAccounts/readMetadata'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/executeQuery'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*'
]
resource sqlRoleDefinition 'Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions@2024-02-15-preview' = {
parent: cosmosDbAccount
name: roleDefinitionId
properties: {
roleName: 'Read Write Role'
type: 'CustomRole'
assignableScopes: [
cosmosDbAccount.id
]
permissions: [
{
dataActions: dataActions
}
]
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the sqlRoleDefinition resource in the provided Bicep module and the Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions@2024-02-15-preview resource type. Check how a second deployment handles the existing role definition and whether the declared name and roleDefinitionId are sufficient. Done means the module can be deployed twice without the duplicate-definition error while retaining the existing role definition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100