Azure Resource Manager (ARM) Tools for Visual Studio Code (Preview)The Azure Resource Manager (ARM) Tools for Visual Studio Code provides language support, resource snippets, and resource auto-completion to help you create and validate Azure Resource Manager templates. Getting StartedThe following guides detail how to use the ARM Tools extension features.
SnippetsSnippets are used to create basic templates and add elements such as parameters, resources, and outputs to existing templates. Create a new ARM templateWhen in an empty JSON file, typing Notice that adding scaffolding for an ARM template changes the Visual Studio Code language mode to Azure Resource Manager Template. Add Azure resource to an ARM templateOnce you are working in an ARM template, placing your cursor in the resource and typing Each snippet includes tab stops to help navigate through commonly modified configurations. Press the Snippet ReferenceThe following table lists the available ARM Tools snippets.
Azure schema completion and validationThe ARM Tools extension uses Azure schemas to provide resource completion and validation. These schemas help you verify that Azure resources are configured correctly before deployment time. Schema CompletionsEntering double quotes In the following example, the potential values for an Azure Storage account tier are returned from the Azure Storage schema. Schema ValidationIf an invalid property or property value is specified, a validation warning is shown. In the following example, an invalid value has been provided for the storage account tier (line 19). Notice that the warning message includes a list of valid values. Parameter filesAssociating a parameter file with an ARM template enables full validation across both the parameter file and template. A parameter file association can be made by either creating a new parameter file from an existing template or by associating an existing parameter file to the template. Create a new parameter fileTo create a new parameter file from an existing template, click on the code lens text `Select or create a parameter file to enable full validation... Select New from the context menu. Selecting All parameters adds every parameter from the template into the new parameter file. Selecting Only required parameters adds only parameters that do not have a default value specified in the template file. Select a name and location for the parameter file. Once done, a parameter file has been created. Where needed, remove the TODO comment and add a parameter value. Also, notice that on the template file that the code lens text has been updated to reflect the current parameter file association. This association is also shown on the Visual Studio Code staus bar. Associate an existing parameter fileTo create an association with an existing parameter file, click on the code lens text `Select or create a parameter file to enable full validation'. If a parameter file with a matching name (template name + ".parameter") is found, it can be selected from the list. If a matching file is not found, select Browse from the list and then select the parameter file. Parameter validationOnce a parameter file has been associated with a template, the extension provides parameter validation across both files. In the following example, a parameter is specified with a set of allowed values. In the parameter file, a value is specified that is not part of the allowed values list. Because of this, the extension produces an error. Add missing parametersTo add missing parameters to an existing parameter file, ensure that an association has been created, click somewhere inside "parameters", and then click the light bulb icon. Select the option to add only required or all missing parameters. Enter a value for the added parameters and also remove the 'TODO' comment. Rename a parameterRight-click on the parameter name and select Rename Symbol. This action renames the parameter and all template and parameter file references to the parameter. Remove or update parameter file associationClick on the code lens option for changing a parameter association. Select a new parameter file or create a new parameter file to update the association. Select None to remove the parameter file association. Linked Template SupportWhen a linked template is referenced, it gets validated using the parameter values that are passed in. Linked template support requires that all top-level parameters have a value. This means that a parameter file is associated with the template OR all top-level parameter definitions have a default value. Scenarios supported:
Additional features:
Template navigationThe ARM tools extension for VS Code offers several features for navigating around an ARM template. ARM template outlineThe ARM template outline is used to navigate to and select any element of an ARM template. In addition to navigation, several features such as insert item and template sorting can be engaged using the buttons found on the ARM template outline. Go to DefinitionGo to definition can be used to navigate to parameter, variable and user-defined function definitions. To use go to definition, place your cursor on the parameter, variable or function name and press Find all referencesRight-click on a parameter, variable, or user-defined function name and select Go to References. Double-clicking on any reference moves your cursor to the reference location. CompletionsThe ARM Tools extension provides code completions for many built-in functions, for example Other featuresInsert ItemIn addition to adding snippets from the code editor, the Insert Item feature can be used to insert new parameters, user-defined functions, variables, resources, and outputs. To do so right-click the code editor, select Insert Item and follow the on-screen prompts. You can also right-click on any element in the ARM Template Outline view to initiate the insert item process. Thanks to Nils Hedström @nilshedstrom for implementing this feature! Sort templateTo sort elements of an ARM template alphabetically, right-click on the template and select Sort Template.... Select the element that you want to sort. Template sorting can also be engaged using the ARM template outline. Thanks to Nils Hedström @nilshedstrom for implementing this feature! Extract to variable or parameterSelect a JSON string or a subset of an expression string then select the lightbulb to extract it to a variable or parameter. Thanks to Nils Hedström @nilshedstrom for implementing this feature! Hover to format complex expressions or multi-line stringsTo assist with navigating complex expressions or multi-line strings, VS Code has a "Go to Bracket" command. You can use the command palette or a keyboard shortcut:
Miscellaneous Features
Extension configurationYou may be interested in adjusting the following extension configurations. These can be configured in VS Code User Settings.
Automatic Detection of deployment template filesBy default, the extension recognizes a .json or .jsonc file as a deployment template file based on the $schema specified in the file (for instance, Besides automatic detection, you can also use the
TroubleshootingUse the following wiki article to help troubleshoot these known issues.
Related Links
Visualizing ARM TemplatesAnother helpful extension for authoring ARM templates is the ARM Viewer for VS Code extension. This extension displays a graphical preview of ARM templates. The view will show all resources with the official Azure icons and also linkage between the resources. You can find details on its features and usage by visiting the GitHub repo here: https://github.com/benc-uk/armview-vscode#usage ContributingThere are several ways you can contribute to our repo:
LegalBefore we can accept your pull request you will need to sign a Contribution License Agreement. All you need to do is to submit a pull request, then the PR will get appropriately labeled (e.g. Code of ConductThis project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. TelemetryVS 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 LicenseThe source code in our public repository is licensed under the MIT license and may be locally built and used in accordance with this license. When the extension is published to the VS Code Marketplace, it is bundled with the Azure Resource Manager language service binaries. The extension as bundled and published this way is licensed under a traditional Microsoft product license. |