![Learn Azure Administration](https://wfqqreader-1252317822.image.myqcloud.com/cover/920/36697920/b_36697920.jpg)
上QQ阅读APP看书,第一时间看更新
Getting started with Azure Policy
To get started, we will have to actually create a policy. The process of assigning a policy is quite simple and can be covered by the following steps:
- Search for the Subscriptions blade—the easiest way to do so is to use the search field at the top of the Azure portal, as shown in the following screenshot:
![](https://epubservercos.yuewen.com/61E643/19470370708769406/epubprivate/OEBPS/Images/Chapter_246.png?sign=1739687587-CqLr4cnjvKg8gm8x3NzLtybpRxdSHNHi-0-d95803c19b8b8f6ae8363592f45ce94e)
Figure 1.7 - Searching for the Subscriptions blade
- Select the subscription you are interested in. The last thing you need to do is to click on the Policies blade:
![](https://epubservercos.yuewen.com/61E643/19470370708769406/epubprivate/OEBPS/Images/Chapter_40.png?sign=1739687587-RlIZD9qYyCnNmWIjWstMfHAMY7C9blWl-0-722b86e329ed64ef4535e022edf0698c)
FIgure 1.8 - The Policies blade
- Click on the Assign policy button, which will display a form where you can define how the policy should work:
![](https://epubservercos.yuewen.com/61E643/19470370708769406/epubprivate/OEBPS/Images/Chapter_119.png?sign=1739687587-qijTS9aAkk1gueBOF8FOMCTfCbnnKN3U-0-9736f3fba9401a42ac3ff781de656f0d)
Figure 1.9 - The Assign policy button
- Assign a policy and configure the appropriate fields as follow: set the Scope of your subscription (in my case, it is Pay-As-You-Go) and leave the exclusions empty and the policy definition as Not allowed resource types. Remember that you can select either a built-in or a custom policy (if you have one).
- Initially, the compliance state may be displayed as Not registered as in the following screenshot. Wait a few minutes before proceeding:
![](https://epubservercos.yuewen.com/61E643/19470370708769406/epubprivate/OEBPS/Images/Chapter_20.png?sign=1739687587-FX1DUGr2U1O0NZDl1bQQ4xJLjMLwm3c3-0-f4e8252bbd175c37cf693a6c35b7c095)
Figure 1.10 - Created policies view
- If this status is diplayed longer than a few minutes, make sure a proper resource provider for the policies is registered. To do so, go to the Resource providers blade and check the status of the provider:
![](https://epubservercos.yuewen.com/61E643/19470370708769406/epubprivate/OEBPS/Images/Chapter_160.png?sign=1739687587-puIfMdJ8yJW3IwGhemSSBTD8ERQGqQto-0-fce0ddfc2d16186f936ad7825ef640e3)
Figure 1.11 - Subscription resource providers
- Once the status is displayed as Registered, you can test the results. Try to perform a forbidden action (such as creating a forbidden resource type). If you do so, you will see a result similar to the following:
![](https://epubservercos.yuewen.com/61E643/19470370708769406/epubprivate/OEBPS/Images/Chapter_228.png?sign=1739687587-gDP8bvwHJT37gxlehNnMDvArNx8u8eDz-0-d3a649ea2f29b540f36707aaa3d8dd26)
Figure 1.12 - Validation error
When a policy is enabled and working, it constantly monitors your resources against configured parameters. Depending on its configuration, it may either block deploying particular services or enforce a specific naming convention. An audit policy can report on non-compliant resources and, with enforcement mode enabled, can deny the creation of resources that don't comply with the policy.
Let's now check what a policy validation result may look like.