hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

Support for `role_definition_name` in `azurerm_cosmosdb_sql_role_assignment` #17527

Open timja opened 2 years ago

timja commented 2 years ago

Is there an existing issue for this?

Community Note

Description

There are two built-in roles. It would be nice to be able to use these directly without having to pass the id in.

For those of you who want to do this in the meantime you can workaround this by doing:

role_definition_id = "${azurerm_cosmosdb_account.cosmosdb.id}/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002"

New or Affected Resource(s)/Data Source(s)

azurerm_cosmosdb_sql_role_assignment

Potential Terraform Configuration

resource "azurerm_cosmosdb_sql_role_assignment" "example" {
  resource_group_name   = azurerm_resource_group.example.name
  account_name          = azurerm_cosmosdb_account.example.name
  role_definition_name  = "Cosmos DB Built-in Data Contributor"
  principal_id          = data.azurerm_client_config.current.object_id
  scope                 = azurerm_cosmosdb_account.example.id
}

References

https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-setup-rbac#built-in-role-definitions

neil-yechenwei commented 2 years ago

Thanks for raising this issue. Seems service API only supports roleDefinitionId for now. Maybe it would be supported by API in the future. If you happen to know, could you share the doc talking about this feature roleDefinitionName? Thanks in advance.

timja commented 2 years ago

It’s not mentioned in the docs but Azure CLI supports it.

example command is here: https://plugins.jenkins.io/azure-cosmosdb/#plugin-content-rbac-setup