Estimated time: 15 minutes
The goal of this task is to create a custom policy and a custom initiative. The policy is created from the command line using a custom json definition file. The custom initiative then combines the custom policy with a built-in policy.
Note: If you are creating a custom purpose-built policy, it is likely easier to add all settings in a single policy rather than creating a separate policy and initiative. Also, the policy that you create for this task can be implemented with a built-in policy but is used to provide a simple example of a custom policy.
You can create a new Azure AD user from the bash cloud shell by running the following command (substitute your values for the domain name and password):
az ad user create --display-name tasks --password <your password> --user-principal-name tasks@<your domain> --force-change-password-next-login false
Example
az ad user create --display-name tasks --password B@dPa55word! --user-principal-name tasks@inedemos.onmicrosoft.com --force-change-password-next-login false
To complete this requirement you must create a custom policy named restrictedVM. The policy must meet the following requirements:
The json for the policy definition is as follows:
{
"if": {
"allof": [
{
"field": "type",
"equals":"Microsoft.Compute/VirtualMachines"
},
{
"not":{
"field":"Microsoft.Compute/virtualMachines/sku.name",
"in":[
"Standard_D2s_v3"
]
}
}
]
},
"then": {
"effect": "deny"
}
}
To fulfill requirement 2, you must create an initiative named location-and-vm in your Azure subscription. Use the General category. The initiative must apply the following policies: - The restrictedVM custom policy. - The Allowed Locations built-in policy. - Set the location restriction to EastUS.
For this requirement you must create a resource group named task-policy-rg in the East US region. Apply the location-and-vm initiative to the resource group.
Finally, you will test the initiative. Attempt to create the following in the task-policy-rg resource group:
When you have finished this task, delete the task-policy-rg resource group, the location-and-vm initiative, and the restrictedVM custom policy.