Azure Authorization Definition

This page shows how to write Terraform and Azure Resource Manager for Authorization Definition and write them securely.

azurerm_role_definition (Terraform)

The Definition in Authorization can be configured in Terraform with the resource name azurerm_role_definition. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {
roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {
main.tf#L9
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.primary.id
  description = "This is a custom role created via Terraform"

  permissions {
roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {
rbac.tf#L21
resource "azurerm_role_definition" "network_admin" {
  role_definition_id = "00000000-0000-0000-0000-000000000001"
  name               = "network-admin-role"
  scope              = var.network_resource_group_id

  permissions {
roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {
roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {
roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my_custom_role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {
roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {
roles.tf#L3
resource "azurerm_role_definition" "example" {
  name        = "my-custom-role"
  scope       = data.azurerm_subscription.current_subscription.id
  description = "This is a custom role created via Terraform"

  permissions {

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Security Best Practices for azurerm_role_definition

There is 1 setting in azurerm_role_definition that should be taken care of for security reasons. The following section explain an overview and example code.

risk-label

Ensure to grant targeted permissions for roles

It is better to avoid giving too many permissions to a role. By following the principle of least privilege, you can reduce the risk of credential leakage.

Review your Azure Authorization settings

You can check if the azurerm_role_definition setting in your .tf file is correct in 3 min with Shisho Cloud.

Parameters

Explanation in Terraform Registry

Manages a custom Role Definition, used to assign Roles to Users/Principals. See 'Understand role definitions' in the Azure documentation for more details.

Microsoft.Authorization/roleDefinitions (Azure Resource Manager)

The roleDefinitions in Microsoft.Authorization can be configured in Azure Resource Manager with the resource name Microsoft.Authorization/roleDefinitions. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

def.json#L22
    "type": "Microsoft.Authorization/roleDefinitions"
  },
  {
    "assignableScopes": [
      "/"
    ],
AccessControlTest.test_find_definition_by_name.json#L76
                                "type": "Microsoft.Authorization/roleDefinitions",
                                "name": "a7b1b19a-0e83-4fe5-935c-faaefbfd18c3"
                            },
                            {
                                "properties": {
                                    "roleName": "Avere Cluster Runtime Operator",
custom_owner_role_infra.json#L12
      "type": "Microsoft.Authorization/roleDefinitions",
      "apiVersion": "2021-02-01",
      "name": "invalidTopLevel",
      "properties": {
        "permissions": [
          {
AccessControlTest.test_find_definition_by_name.json#L76
                                "type": "Microsoft.Authorization/roleDefinitions",
                                "name": "a7b1b19a-0e83-4fe5-935c-faaefbfd18c3"
                            },
                            {
                                "properties": {
                                    "roleName": "Avere Cluster Runtime Operator",
AccessControlTest.test_find_definition_by_name.json#L76
                                "type": "Microsoft.Authorization/roleDefinitions",
                                "name": "a7b1b19a-0e83-4fe5-935c-faaefbfd18c3"
                            },
                            {
                                "properties": {
                                    "roleName": "Avere Cluster Runtime Operator",
AccessControlTest.test_find_definition_by_name.json#L76
                                "type": "Microsoft.Authorization/roleDefinitions",
                                "name": "a7b1b19a-0e83-4fe5-935c-faaefbfd18c3"
                            },
                            {
                                "properties": {
                                    "roleName": "Avere Cluster Runtime Operator",
AccessControlTest.test_find_definition_by_name.json#L76
                                "type": "Microsoft.Authorization/roleDefinitions",
                                "name": "a7b1b19a-0e83-4fe5-935c-faaefbfd18c3"
                            },
                            {
                                "properties": {
                                    "roleName": "Avere Cluster Runtime Operator",
AccessControlTest.test_find_definition_by_name.json#L76
                                "type": "Microsoft.Authorization/roleDefinitions",
                                "name": "a7b1b19a-0e83-4fe5-935c-faaefbfd18c3"
                            },
                            {
                                "properties": {
                                    "roleName": "Avere Cluster Runtime Operator",
role_definitions.json#L22
    "type": "Microsoft.Authorization/roleDefinitions"
  },
  {
    "assignableScopes": [
      "/"
    ],

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • properties required
      • roleName optional - string

        The role name.

      • description optional - string

        The role definition description.

      • type optional - string

        The role type.

      • permissions optional array
          • actions optional - array

            Allowed actions.

          • notActions optional - array

            Denied actions.

      • assignableScopes optional - array

        Role definition assignable scopes.

Frequently asked questions

What is Azure Authorization Definition?

Azure Authorization Definition is a resource for Authorization of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Authorization Definition?

For Terraform, the dasalebr/azurepipeline_shiftleft, olmorigolo/terraform and prancer-io/prancer-terramerra source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the juggernauthk108/pastebin, harsh4870/cloud-custodian and fugue/regula source code examples are useful. See the Azure Resource Manager Example section for further details.