How To Add An Arm Template To Visual Studio Solution
title | description | author | ms.date | ms.topic | ms.author | ms.custom |
---|---|---|---|---|---|---|
Create template - Visual Studio Code | Utilize Visual Studio Lawmaking and the Azure Resource Manager tools extension to work on Azure Resource Manager templates (ARM templates). | neilpeterson | 08/09/2020 | quickstart | nepeters | devx-track-azurepowershell, mode-ui |
Quickstart: Create ARM templates with Visual Studio Code
The Azure Resource Director Tools for Visual Studio Code provide linguistic communication support, resource snippets, and resource autocompletion. These tools assist create and validate Azure Resource Manager templates (ARM templates). In this quickstart, you apply the extension to create an ARM template from scratch. While doing so you experience the extensions capabilities such as ARM template snippets, validation, completions, and parameter file support.
To complete this quickstart, you lot need Visual Studio Code, with the Azure Resources Manager tools extension installed. You also demand either the Azure CLI or the Azure PowerShell module installed and authenticated.
If you don't have an Azure subscription, create a free business relationship before you begin.
[!TIP] We recommend Bicep considering it offers the same capabilities as ARM templates and the syntax is easier to use. To acquire more, meet Quickstart: Create Bicep files with Visual Studio Lawmaking.
Create an ARM template
Create and open up with Visual Studio Code a new file named azuredeploy.json. Enter arm
into the code editor, which initiates Azure Resources Manager snippets for scaffolding out an ARM template.
Select arm!
to create a template scoped for an Azure resource group deployment.
This snippet creates the basic building blocks for an ARM template.
Notice that the Visual Studio Lawmaking language mode has changed from JSON to Azure Resources Manager Template. The extension includes a linguistic communication server specific to ARM templates that provides ARM template-specific validation, completion, and other language services.
Add an Azure resource
The extension includes snippets for many Azure resource. These snippets can exist used to easily add together resources to your template deployment.
Place the cursor in the template resources block, type in storage
, and select the arm-storage snippet.
This action adds a storage resource to the template.
The tab key can exist used to tab through configurable properties on the storage account.
Completion and validation
One of the most powerful capabilities of the extension is its integration with Azure schemas. Azure schemas provide the extension with validation and resource-aware completion capabilities. Let'due south modify the storage account to meet validation and completion in action.
Get-go, update the storage account kind to an invalid value such every bit megaStorage
. Discover that this activeness produces a warning indicating that megaStorage
isn't a valid value.
To employ the completion capabilities, remove megaStorage
, identify the cursor inside of the double quotes, and press ctrl
+ space
. This activeness presents a completion listing of valid values.
Add template parameters
Now create and employ a parameter to specify the storage account name.
Place your cursor in the parameters cake, add together a carriage render, blazon "
, and then select the new-parameter
snippet. This action adds a generic parameter to the template.
Update the name of the parameter to storageAccountName
and the clarification to Storage Account Name
.
Azure storage account names take a minimum length of 3 characters and a maximum of 24. Add both minLength
and maxLength
to the parameter and provide appropriate values.
Now, on the storage resource, update the proper name property to apply the parameter. To do then, remove the electric current name. Enter a double quote and an opening square bracket [
, which produces a list of ARM template functions. Select parameters from the listing.
Entering a single quote '
inside of the round brackets produces a list of all parameters divers in the template, in this case, storageAccountName. Select the parameter.
Create a parameter file
An ARM template parameter file allows y'all to store environment-specific parameter values and pass these values in as a group at deployment time. For example, you may take a parameter file with values specific to a test environment and some other for a production environs.
The extension makes it easy to create a parameter file from your existing templates. To practise then, right-click on the template in the code editor and select Select/Create Parameter File
.
Select New
> All Parameters
> Select a proper name and location for the parameter file.
This action creates a new parameter file and maps information technology with the template from which it was created. You can see and modify the electric current template/parameter file mapping in the Visual Studio Code condition bar while the template is selected.
Now that the parameter file has been mapped to the template, the extension validates both the template and parameter file together. To run across this validation in practise, add a two-graphic symbol value to the storageAccountName
parameter in the parameter file and save the file.
Navigate back to the ARM template and find that an mistake has been raised indicating that the value doesn't see the parameter criteria.
Update the value to something advisable, save the file, and navigate back to the template. Detect that the mistake on the parameter has been resolved.
Deploy the template
Open the integrated Visual Studio Code terminal using the ctrl
+ `
key combination and use either the Azure CLI or Azure PowerShell module to deploy the template.
CLI
az group create --name arm-vscode --location eastus az deployment grouping create --resource-group arm-vscode --template-file azuredeploy.json --parameters azuredeploy.parameters.json
PowerShell
New-AzResourceGroup -Name arm-vscode -Location eastus New-AzResourceGroupDeployment -ResourceGroupName arm-vscode -TemplateFile ./azuredeploy.json -TemplateParameterFile ./azuredeploy.parameters.json
Make clean upward resources
When the Azure resources are no longer needed, utilize the Azure CLI or Azure PowerShell module to delete the quickstart resources group.
CLI
az grouping delete --name arm-vscode
PowerShell
Remove-AzResourceGroup -Proper noun arm-vscode
Next steps
[!div class="nextstepaction"] Beginner tutorials
How To Add An Arm Template To Visual Studio Solution,
Source: https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/azure-resource-manager/templates/quickstart-create-templates-use-visual-studio-code.md
Posted by: brottprajectow.blogspot.com
0 Response to "How To Add An Arm Template To Visual Studio Solution"
Post a Comment