{
  "useCase": "audit/audit-workspace",
  "version": "v1",
  "purpose": "The Log Analytics workspace that holds the audit log. Each EasyLife 365 product has its own app: run the grant once per product app. The role reads every table in the workspace, not only the audit log.",
  "resourceKind": "LogAnalyticsWorkspace",
  "role": {
    "name": "Log Analytics Reader",
    "id": "73c42c96-874c-492b-b04d-ab87d138a893",
    "scope": "workspace",
    "scopeId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}"
  },
  "requiredActions": [
    "Microsoft.OperationalInsights/workspaces/query/read"
  ],
  "whoMayConnect": {
    "roles": [
      "Owner",
      "User Access Administrator",
      "Role Based Access Control Administrator"
    ],
    "action": "Microsoft.Authorization/roleAssignments/write"
  },
  "rules": [
    "Parameters only, no other input",
    "Running a script again changes nothing that exists and lists it as skipped",
    "Never deletes anything and never changes the settings of an existing resource"
  ],
  "files": {
    "create.ps1": {
      "action": "create",
      "shell": "PowerShell 7 or Windows PowerShell 5.1",
      "modules": [
        "Az.Accounts",
        "Az.Resources"
      ],
      "parameters": {
        "workspaceName": {
          "powershell": "-WorkspaceName",
          "cli": "--workspace-name",
          "required": true,
          "description": "The Log Analytics workspace: 4 to 63 letters, digits and hyphens, starting and ending with a letter or digit."
        },
        "region": {
          "powershell": "-Region",
          "cli": "--region",
          "required": true,
          "description": "The Azure region of a new resource, for example westeurope. In the template it defaults to the region of the resource group."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "resourceGroup": {
          "powershell": "-ResourceGroupName",
          "cli": "--resource-group",
          "required": false,
          "default": "rg-easylife365",
          "description": "The resource group of a new workspace, created in the region when it is missing. When several workspaces in the subscription have the name, the resource group of the one you mean."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Without it the script uses the current subscription and asks you to confirm it."
        },
        "yes": {
          "powershell": "-Yes",
          "cli": "--yes",
          "required": false,
          "description": "A switch with no value: uses the current subscription without asking."
        }
      },
      "creates": [
        "Resource group, when the workspace and the group don't exist yet",
        "Log Analytics workspace: PerGB2018, data kept 30 days",
        "Role assignment: Log Analytics Reader for the service principal of the app, at the workspace"
      ],
      "runAs": "Owner, or Contributor together with User Access Administrator or Role Based Access Control Administrator, on the subscription"
    },
    "create.sh": {
      "action": "create",
      "shell": "Bash with the Azure CLI",
      "parameters": {
        "workspaceName": {
          "powershell": "-WorkspaceName",
          "cli": "--workspace-name",
          "required": true,
          "description": "The Log Analytics workspace: 4 to 63 letters, digits and hyphens, starting and ending with a letter or digit."
        },
        "region": {
          "powershell": "-Region",
          "cli": "--region",
          "required": true,
          "description": "The Azure region of a new resource, for example westeurope. In the template it defaults to the region of the resource group."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "resourceGroup": {
          "powershell": "-ResourceGroupName",
          "cli": "--resource-group",
          "required": false,
          "default": "rg-easylife365",
          "description": "The resource group of a new workspace, created in the region when it is missing. When several workspaces in the subscription have the name, the resource group of the one you mean."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Without it the script uses the current subscription and asks you to confirm it."
        },
        "yes": {
          "powershell": "-Yes",
          "cli": "--yes",
          "required": false,
          "description": "A switch with no value: uses the current subscription without asking."
        }
      },
      "creates": [
        "Resource group, when the workspace and the group don't exist yet",
        "Log Analytics workspace: PerGB2018, data kept 30 days",
        "Role assignment: Log Analytics Reader for the service principal of the app, at the workspace"
      ],
      "runAs": "Owner, or Contributor together with User Access Administrator or Role Based Access Control Administrator, on the subscription"
    },
    "template.json": {
      "action": "template",
      "source": "template.bicep",
      "deployToAzure": "https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fdocs.easylife365.cloud%2Fdownloads%2Faudit%2Faudit-workspace%2Fv1%2Ftemplate.json",
      "parameters": {
        "workspaceName": "The Log Analytics workspace: 4 to 63 letters, digits and hyphens, starting and ending with a letter or digit.",
        "region": "The Azure region. Default: the region of the resource group."
      },
      "creates": [
        "Log Analytics workspace: PerGB2018, data kept 30 days"
      ],
      "access": "None. Run grant.ps1 or grant.sh afterwards.",
      "runAs": "Contributor or Owner on the resource group"
    },
    "grant.ps1": {
      "action": "grant",
      "shell": "PowerShell 7 or Windows PowerShell 5.1",
      "modules": [
        "Az.Accounts",
        "Az.Resources"
      ],
      "parameters": {
        "workspaceName": {
          "powershell": "-WorkspaceName",
          "cli": "--workspace-name",
          "required": true,
          "description": "The Log Analytics workspace: 4 to 63 letters, digits and hyphens, starting and ending with a letter or digit."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "resourceGroup": {
          "powershell": "-ResourceGroupName",
          "cli": "--resource-group",
          "required": false,
          "description": "When several workspaces in the subscription have the name, the resource group of the one you mean."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Without it the script uses the current subscription and asks you to confirm it."
        },
        "yes": {
          "powershell": "-Yes",
          "cli": "--yes",
          "required": false,
          "description": "A switch with no value: uses the current subscription without asking."
        }
      },
      "creates": [
        "Role assignment: Log Analytics Reader for the service principal of the app, at the workspace"
      ],
      "runAs": "Owner, User Access Administrator, Role Based Access Control Administrator, at the scope of the role or above"
    },
    "grant.sh": {
      "action": "grant",
      "shell": "Bash with the Azure CLI",
      "parameters": {
        "workspaceName": {
          "powershell": "-WorkspaceName",
          "cli": "--workspace-name",
          "required": true,
          "description": "The Log Analytics workspace: 4 to 63 letters, digits and hyphens, starting and ending with a letter or digit."
        },
        "appId": {
          "powershell": "-AppId",
          "cli": "--app-id",
          "required": true,
          "description": "The application (client) ID of the EasyLife 365 app in your tenant. The role goes to the service principal of this app."
        },
        "resourceGroup": {
          "powershell": "-ResourceGroupName",
          "cli": "--resource-group",
          "required": false,
          "description": "When several workspaces in the subscription have the name, the resource group of the one you mean."
        },
        "subscription": {
          "powershell": "-Subscription",
          "cli": "--subscription",
          "required": false,
          "description": "The subscription ID or name. Without it the script uses the current subscription and asks you to confirm it."
        },
        "yes": {
          "powershell": "-Yes",
          "cli": "--yes",
          "required": false,
          "description": "A switch with no value: uses the current subscription without asking."
        }
      },
      "creates": [
        "Role assignment: Log Analytics Reader for the service principal of the app, at the workspace"
      ],
      "runAs": "Owner, User Access Administrator, Role Based Access Control Administrator, at the scope of the role or above"
    }
  }
}
