# Managed identity and role assignment Give a workload a user-assigned identity, and grant its role at the narrowest scope. `scope` here is one storage account's id. ```hcl variable "storage_account_id" { type = string } resource "azurerm_user_assigned_identity" "app" { name = "id-app" location = var.location resource_group_name = var.resource_group_name } resource "azurerm_role_assignment" "app_blob_reader" { scope = var.storage_account_id role_definition_name = "Storage Blob Data Reader" principal_id = azurerm_user_assigned_identity.app.principal_id } ```