Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Azure PolicyNew to Visual Studio Code? Get it now.

Azure Policy

Preview

Microsoft

|
16,840 installs
| (7) | Free
Azure resource, policy, and alias viewer
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Azure Policy Visual Studio Code Extension

Azure Policy enforces standards and evaluates compliance at scale for your Azure environment. This extension is to help streamline the management and authoring of Resource Manager mode policy definitions and assignments.

Overview

Azure Policy Visual Studio Code extension simplifies the experience of finding, understanding, and authoring policies by putting your policy definitions, assignments, and initiatives, and your resources, in JSON format into a convenient tree view allowing fast navigation. You are able to see aliases that apply to a resource, discover available aliases, and even evaluate your policies against a resource. You are able to quickly run a resource compliance evaluation by selecting a definition, assignment and deployed azure resource.

Note: the Azure Policy Visual Studio Code extension supports evaluation of ++Resource Manager mode++ policies only. Some namespaces also support Resource Provider mode policies, but evaluation of those types of policies is not supported by the extension at this time. We are working on an approach to support this scenario.

What's New

We have been working hard to make VSCode an indespensible tool for policy authors. With this release, we are very excited to be bringing you something that many of you have been asking for: live policy evaluation right from VSCode! Using the new Evaluation area in the lower left of the policy extension, you can select a policy definition and a resource and perform policy evaluation with a few mouse clicks.

Another major enhancement in this release is full completion lists for policy aliases. One difficulty faced by policy authors is discovering policy aliases. Previously, you had to have an instance of a given resource type containing the specific property in order to discover the alias for one of its properties or run a Powershell cmdlet from the command line. Now you can discover aliases inline while editing your policy definition. Just start typing after the "field": keywoard and and completion lists will show available matching fields, including aliases.

How to Use the Azure Policy Extension

The Azure Policy VSCode extension is a generally useful tool to help with developing policy definitions. The two primary scenarios are to view the JSON contents of a resource or a policy object, and to see the result of evaluating a policy definition against a resource.

View resources

In the top left 'Resources' tree view, under each subscription there are two folders: 'Resource Providers' and 'Resource Groups'. Under 'Resource Providers', resources are divided by resource provider such as 'Microsoft.Compute' or 'Microsoft.Network' that are registered to that subscription. This view shows all resources, including proxy resources, organized by Resource Provider namespace and resource type hierarchy. Under 'Resource Groups', resources are divided by resource group. The 'Resource Groups' view shows only tracked resources (resources that are members of a resource group). To see proxy resources, you need to browse to the resource type under the 'Resource Providers' folder.

Selecting a resource will display its JSON contents in an editor tab on the right. By default it will be opened in Preview mode, which means that when another node in the treeview is selected, the new resource contents will replace the previous contents in the same editor tab. If you want to keep a tab open to a particular resource even after you navigate away, select the Pin this resource in a tab command on the item in the treeview. If you want to save and/or edit a copy of the resource, use the Save this resource as... command on the item. Editing a resource is useful as a fast way to test policy compliance evaluation on different resource values.

View policy definitions, assignments, and initiatives

In the middle left 'Policies' tree view, under each subscription there are four folders: 'Assignments', 'Built-in Definitions', 'Custom Definitions', and 'Initiatives'. This view shows all of the policy objects for the given subscription divided by those types.

Similar to viewing resources above, select a policy item in the treeview to display its JSON contents in a tab on the right. The policy treeview items have similar commands: Pin this policy item in a tab, and Save this policy item as... for keeping the item in its tab or saving the item to a file for separate storage or editing. When you are satisfied with the contents of a policy definition, you can copy to the clipboard and paste it into the portal to create a new policy or update an existing one.

View the result of evaluating a policy against a resource

In the bottom left 'Evaluation' view, you will see a list of currently open resources and policy items. Commands within that view allow you to select a policy definition and a resource for evaluation. If the policy definition requires parameter values, you will also need to select an assignment to provide the parameter values. If the policy definition effect is DeployIfNotExists or AuditIfNotExists, you will also need to select a related resource for the existence check. After you have selected these items, run the Evaluate policy selection against resource selection command at the top right corner of the Evaluation pane to get the evaluation results. As you make changes to a policy definition or resource, you can immediately reevaluate compliance of the resource without needing to update the policy in Azure and wait for the Azure Policy service to perform a compliance evaluation each time.

Summary of Features

  • View resource and policy contents
    • Select a tree view node to view the contents of a resource or policy object in a read-only tab on the right.
    • 'Save as' treeview commands to save a read-write copy of any item to a file.
    • Pin treeview commands to keep the item in its own editor tab.
  • Test compliance evaluation of policy definitions against a resource
    • Evaluation pane shows currently open items.
    • Select a policy definition and a resource for evaluation.
    • Also select a policy assignment if the definition requires parameter values.
    • Also select a related resource if the definition's effect is DeployIfNotExists or AuditIfNotExists.
    • Run the Evaluate command to see evaluation results right in VSCode.
  • Quick view of aliases
    • Hover over resource property or value to discover a property's alias.
  • Tree view
    • View resources and policy definitions, assignments, and initiatives in hierarchical views at subscription level.
    • Search for resources and policies in the Command Palette.
  • Settings to select four different filtered views for resources
    • Filter By Any Aliases: Under 'Resource Providers' show only namespaces and resource types that have published policy aliases. This is faster than filtering by existing resource, but includes empty folders for types no instances in the subscription.
    • Filter By Existing Resources: In the 'Resources' tree view show only namespaces, resource types, and resource groups that actually contain resources (no empty folders). When only this setting is enabled, opening the 'Resource Providers' folder the first time in a session requires each resource type to be queried for instances. This may take a long time depending on the number and types of resources present in the subscription.
    • Both filters combined together: This is the default setting that shows all namespaces and types with published aliases and instances in the subscription. With both filters enabled, the time to open the 'Resource Providers' folder is likely to fall between applying either filter by itself, since fewer resource types must be queried.
    • Neither of the above filters: With all filtering disabled, the 'Resource Providers' folder will open quickly, but will contain many empty folders. This may be preferrable when looking for resources of known namespace and type.

Notes

  • This extension only displays the objects shown in the tree view, it does not support creating objects or updating existing objects. In some cases, the contents displayed can be used in other Azure interfaces to create or modify resources. For example, policy definition contents can be pasted into the Azure portal or a command line with some modification to create or update existing policies.
  • Treeview nodes that refer to a resource will open in a tab when selected. Others are structural and can be expanded or closed. Below the 'Resource Providers' folder, many nodes do both, since they represent a resource, but may also contain sub types.
  • If you haven’t previously signed into Azure from Visual Studio Code, you will need to sign in. After signing in, you may also filter by subscriptions. To sign in, select 'View' -> 'Command Palette' and select 'Azure: Sign in'. To filter subscriptions select 'Azure: Select Subscriptions' command.
  • The Evaluation pane tracks open tabs. While navigating either treeview, when you select an item it is

Compatibility

This extension requires VSCode build 1.48.0 or newer. Supported operating systems (architectures):

  • Windows (x64)
  • Mac (x64)
  • Ubuntu (x64)

however, see Known issues below for current limitations.

Related links

Visual Studio Code extension documentation: https://docs.microsoft.com/azure/governance/policy/how-to/extension-for-vscode

What we're working on...

  • Known issues:
    • Policy evaluation is currently not working on Mac and Linux. Either the evaluation area remains empty or evaluation fails with a server error.
    • The second (or more) instance of VSCode running the policy extension only works with limited functionality. The first instance remains unaffected.
  • Policy structure syntax highlighting
  • Policy and alias validation

Ideas, feature requests and bugs: Email policy-vscode@microsoft.com! We are open to all ideas and we want to get rid of bugs!

Release History

See the changelog for this extension

Telemetry

Visual Studio Code collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. If you don’t wish to send usage data to Microsoft, you can set the telemetry.enableTelemetry setting to false. Learn more in our FAQ.

License

This extension is licensed under the MIT license. By downloading and using the Visual Studio Azure Policy extension and its related components, you agree to the product license terms and privacy statement.

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2019 Microsoft