Escape Dollar $ sign in Azure ARM Template Variable - azure

I have an ARM Template to deploy a WebApp in Azure. I also have a AppSettings configuration in WebApp (which is used for sending emails) "EmailPassword" to be deployed along with the ARM Template.
The actual value for variable "EmailPassword" is"Test$am123" in ARM Template.
But when I execute the ARM Template during deployment, the value is stored as "Test123" in the AppSettings of the created WebApp.
I hope this happens because of the $ (dollar) sign in the variable.
How to escape the Dollar sign in the ARM Template variables
Update: With the help of 4c74356b41, I found the Issue is not with ARM Template and its Parameters.Json. Instead, I am using the VSO Deployment and trying to pass the values to Parameters from the Environment Variables. I overriding the Parameters.json using the "Override Template Parameters" input in VSO.
The Issue is with VSO and it removes the "$am" characters while passing the values to the ARM Deployment.

I think that escaping is done using \ character.
update: for me $ doesnt need escaping.

Related

SecureString in ARM template deployment through Terraform does an update in place everytime?

I am using Terraform to provision my Azure resources which works great, however, for some resources such as Logic Apps, doing this natively doesn't really work so I am using the Logic Apps ARM template and doing a Terraform "azurerm_resource_group_template_deployment" in order to provision. I know doing an ARM template deployment within Terraform is a bit of a last resort. It works ok though and deploys fine but I have a Service Bus connection defined and that is of type "securestring". By default, these are not saved as part of ARM deployment so everytime Terraform runs in my pipeline, even if the Logic App ARM template has not changed, it still does the deployment as the top level deployment state Terraform knows about previously did not have the value saved so will always see it as new. Is there any way around this other than changing the "securestring" to "string" which I obviously do not want to do given the endpoint contains the SAS key etc?
Hit same issues today - really limits what is viable. Managed to work around my two scenario's.
For things like keys and connection strings you can use the listkeys function inside of the ARM template - some examples here. I had this exact issue trying to get a log analytics workspace key in to the template - https://github.com/Azure/azure-quickstart-templates/blob/master/demos/arm-template-retrieve-azure-storage-access-keys/azuredeploy.json - Get connection strings in ARM
Another scenario I had was wanting to pass a service principal secret from TF to template as securestring, to get around this I ended up getting the secret from keyvault inside of the ARM template instead.

Updating Set of Values in ARM Templates Automatically

I have an ARM template, which I will be using it to deploy resources (Mentioned as in Azure Portal) via Azure DevOps Pipeline. These ARM templates were created using my Dev Subscription. If I need to use this same ARM template to move to production, I need to manually update the subscription id etc in the ARM template and then run the respective pipelines. Is there any way to automate this manual updation process in ARM template.
I have tried using File Transform Agent job available under Azure DevOps Release pipeline. But since the values are available inside nested loops of ARM templates, it failed. Is there any PowerShell script that will be suitable for this process of updating values.
I don't want to manually update the ids under the ARM Template. Instead, I want to update it automatically.
Set Json Property task might help to set the property with specific value.
First in the marketplace search for "set Json property" task and install it for your organization.
Then you can set the property path and the value accordingly. check here for detail usage
Instead of hard coding in ARM templates you can use parameters file. For dev and prod you can have separate files and while deploying pass ARM Template along with parameter file whichever is required.
You can use AKV (Azure Key Vault) to access your subscription details in parameter file
subscription().subscriptionid will get you the details

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.

Best practice for Azure ARM template parameters

Getting started with ARM templates and trying to get a better understanding of what parameters go in a separate parameters file versus in the parameters section of the template itself. Do I have to have a separate parameters file? Seems like I can 't do a deployment from Visual Studio without identifying the parameters file.
You don't have to have a parameters file to deploy via ARM templates. You can certainly hardcode everything in your ARM template file if you like.
The next part is my opinion only on ARM template construction. I like following naming conventions for resources, such as [resource type]-[app]-[environment]. For example, a Web App for app Foo for the staging environment might be named wa-foo-prod. Following such a convention means that I can look at a resource and pretty much tell exactly what it's for.
That being said, I'm a big proponent of variables for naming resources in ARM templates. I might only pass in the environment and the region as parameters in an ARM template, then use variables to concatenate up all of the necessary resource names.
If every single resource name is passed in as a parameter, parameter management gets unwieldy.
As far as a required parameters file for deploying through VSTS, you may be right. But if you did NOT want any parameters, you could either deploy your ARM template through a Powershell script in VSTS, or just pass in an empty parameters file.

Specifying artifactsLocation in web app deployment to Azure

I am trying to deploy an Azure Resource group via Octopus Deploy (within it a website).
Hyak.Common.CloudException: InvalidTemplate: Deployment template validation failed: 'The value for the template parameter '_artifactsLocation' at line '40' and column '32' is not provided.
How would I specify this in Visual Studio so that the solution can get deployed to Azure?
Thanks
From an Octopus point-of-view, you can use variable substitution on both the Template and Parameter files to sub in whatever values you need to your templates.
If you have a look at the "Template Contained in a Package" section of the Azure Resource Groups documentation, it shows you example JSON templates with variable substitution in place.
Eg.
"databaseName": {
"value": "#{DatabaseName}"
},
So in your project, you'd setup a project variable, then use the variable substitution syntax to address that variable in your template JSON (that's contained in your package), and it will get substituted before being executed at Azure.
Hope this helps

Resources