Create resource group and deploy resources using Arm template and deploy from Visual Studio - azure

I want to create resource group and deploy resource using ARM template from visual Studio
When I tried the following example by copying the script and put it in my Visual Studio. When I try to run the Deployment template comes out blank.
https://learn.microsoft.com/en-us/azure/azure-resource-manager/deploy-to-subscription#create-resource-group-and-deploy-resources
How do i run this the arm template?

Schema that is used in your example uses "subscription level schema"
https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#
As per https://learn.microsoft.com/en-us/azure/azure-resource-manager/deploy-to-subscription
To deploy templates at the subscription level, you use Azure CLI and
Azure PowerShell.
I used this schema "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#" I used this default schema..and it detects that file as "deployment template"

Currently VS doesn't handle subscription level deployment templates. VS won't deploy them via the UI and if the schema is set properly it won't even recognize it as an ARM template.

Related

What is the best approach to update and test Logic App ARM templates after making changes from designer?

We have a CI/CD setup for the deployment of Logic Apps using ARM templates. There are around 20 logic apps we have parameterized and checked in as templates in our code (both template.json and parameters.json) files, and then we can deploy them using our pipelines to any environment we want.
The question I want to ask is how to check/verify the ARM templates after making changes to the Logic Apps. For now what we are doing is editing the logic apps using the designer in azure portal in one of the dev environments and then manually copy and pasting the updated part in the template.json file.
I was wondering if there is a better approach we can take to verify the manually updated template.json files, since we only come to know about an error in the template when we try to deploy it. Also it would be better to have a way to visualize the logic app ARM template using some designer if possible to check all the steps.
I know we have an extension for visual studio that allows you to design and deploy logic app ARM template in the editor itself, but I am unable to find a way to open already existing templates in the visual studio logic app designer, since we only want to update and verify the template in the designer, the deployment is handled by pipelines.
Please let me know if there is a better approach to locally verify/test the logic app ARM templates.
For now what we are doing is editing the logic apps using the designer in azure portal in one of the dev environments and then manually copy and pasting the updated part in the template.json file.
You can use the LogicAppTemplate module in powershell to get the template from your subscription. That way you don't have to copy paste the changed components.
but I am unable to find a way to open already existing templates in the visual studio logic app designer, since we only want to update and verify the template in the designer, the deployment is handled by pipelines.
As I understand, there is no way of importing a template.json for a logic app in Visual Studio or Visual Studio Code. And the only way to view it in designer would be to publish it first. However, if you convert the template.json into a bicep file, Visual Studio Code can validate the converted .bicep file.
To generate the template.json for the existing logic app:
$parameters = #{
Token = (az account get-access-token | ConvertFrom-Json).accessToken
LogicApp = '<logicapp_name>'
ResourceGroup = '<resourceGroupName'
SubscriptionId = "Subscription_ID"
Verbose = $true
}
Get-LogicAppTemplate #parameters | Out-File temp.json
and then you convert it with the following command:
bicep decompile temp.json
Now we load up the generated bicep file in visual studio code for validation. For instance:

Azure Resources Deployment using ARM template removes the existing Application config

I have created a Function App for Containers using ARM template deployment using Azure DevOps Pipeline job (Azure Resource Group Deployment).
After deployment added additional configurations other than default configurations for Function App through portal.
For adding new resources, I have updated my 'template.json' and redeployed again. But this removes all my manual configuration of the existing Function App and set it to the default config settings in the template file. :( . Anyone please tell me a way for sort this problem.
Is there any property that helps to retain the resources and its configuration unchanged while deployment using ARM ? I used the property
"mode":
"Incremental" .
But this didn't work for me. It removes the existing configurations that I have created manually. Please suggest a best way to deploy and manage a resource using ARM. Is there any property or 'key : value' for adding additional settings to site config other than remove the site config and recreate it as inside the template default.
I think your only option is to set those configurations into the ARM template. ARM templates are not always incremental but are some time declarative as in this case.
You can switch to bicep, which has the ability to merge app settings. However, I don't have the details at the moment.
bicep wouldn't be a valid path to take. Except you can generate bicep from your source arm templates if they are 2019 or newer. That way the arm temples still drives the pipeline.
I wonder if terraform has the same options?

Build arm template in VSTS fails with error about 'artifactsLocation'

Normally when i deploy through visual studio _artifactsLocation shows when editing the parameters so what should this be in VSTS and how do I set it?
2018-02-21T08:49:46.1918199Z ##[error]Deployment template validation failed: 'The value for the template parameter '_artifactsLocation' at line '1' and column '182' is not provided. Please see https://aka.ms/arm-deploy/#parameter-file for usage details.'.
2018-02-21T08:49:46.1919769Z ##[error]Task failed while creating or updating the template deployment.
You can specify it in parameters file, then specify the file path in Template parameters input box of Azure Resource Group Deployment task if you are using.
Also, the parameters can be override by specifying in Override template parameters input box of Azure Resource Group Deployment task.
If you are calling script through Azure PowerShell task, you can specify it in the arguments: -ArtifactStagingDirectory, related issue: The value for the template parameter '_artifactsLocation' is not provided
This sounds like you are using the Azure Resource Group deployment template from VS to deploy via VSTS.
It uses MSDeploy as part of the ARM template deployment to deploy your service.
The Powershell script that is generated by the VS project template uploads a ZIP-file containing your service to Blob storage, and puts the URL and other information into _artifactsLocation and other ARM template parameters.
Instead of doing that, you can remove the artifacts related parameters and the MSDeploy resource from the ARM template. Then the template ONLY contains infrastructure related resources.
After this, add a "Deploy to App Service" step in the VSTS Release pipeline after the ARM template deployment. That can then be used to deploy your service code.
If you are using a separate parameters json file, you'll need to initialise the _artifactsLocation and _artifactsLocationSasToken there. You can give them empty strings, like:
"_artifactsLocation": {
"value": ""
},
"_artifactsLocationSasToken": {
"value": ""
},
They should automatically get their values from a PowerShell script. I'm using the AzureResourceManagerTemplateDeployment#3 task, it would probably work with AzureResourceGroupDeployment#2 as well.

How can I divide an existing template into linked Templates

Auto generated arm templates aren't meant to be production ready, they need refinement. that is expected.
How can a Devops staff divide auto generated ARM templates into Linked templates?
References
Linked Templates
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates
Azure ARM template deployment
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview#template-deployment
How can a Devops staff divide auto generated ARM templates into Linked templates?
Per my understanding, you could leverage Azure Resource Group deployment project through visual studio for a simple to divide your ARM template into Linked templates manually.
After you created the deployment project, you could right click your deployment project and click "Add > New Item", choose "Azure Resource Manager Deployment Template", then copy/paste your existed ARM template into your azuredeploy.json, then you could enable JSON Outline window by clicking "View > Other Windows > JSON Outline", then you could choose the resources which would be divided into Linked template, then copy the related resource configurations (resource definition, variables, parameters,etc.) into a new "Azure Resource Manager Deployment Template". Here I divided the HostingPlan into a Linked template, when deploying my azure website, I would use the hosting plan linked template as follows:
Deploying azure website with a host plan linked template
Azure website deployment template: https://brucechen.blob.core.windows.net/arm-templates/websitewithlinkedtemplate.json
Then, check the latest deployment log under "SETTING > Deployments" section of your resource group as follows:

how do i add AzureAutomation Resource to my ARM template project

I create a new ARM template using VS2017 and would like to add Azure Automation resource as part of my template. When I right click and select add New Resource I do not see Azure Automation. How do I go about doing this
Best way to do this - go to the documentation and copy\paste it.
Reference:
https://learn.microsoft.com/en-us/azure/templates/microsoft.automation/automationaccounts

Resources