0

Escape Single Quotes within Azure Resource Template

Single Quote

In some situations you will get into problems when creating a Azure Resource Template. I was creating a solution for a customer and had to add a Logic App to our template. That isn’t that hard I thought but when adding a Logic App to your template and making it parameterized and depending on other resources you can come into scenario’s were you will have to escape single quotes.

Looking into the documentation about azure resource templates you will not find any solution (I haven’t) so I tried a couple of escape characters and they didn’t work.

The last resort was a solution that isn’t that pretty but it works, I hope that in new releases this will be fixed.

Create a Variable

The first step for the solution is to create a variable in the template that contains a single quote.

"variables": {
  "singlequote": "'"
}

Use the variable

After you created the variable you can use this to combine you string values.

 "uri": "[concat('https://', reference(concat('Microsoft.Web/sites/', parameters('api_Name'))).defaultHostName, '/api/Item/', '@{encodeURIComponent(body(',variables('singlequote'), 'HTTP_GetItem',variables('singlequote'), ')?[', variables('singlequote'),'itemid_value', variables('singlequote'), '])}')]"

As you can see in the above code snip it we set the “uri” property of a Logic App component. In this specific snipt it we dynamically get the hostname of a Azure Web Site the Logic App depends on. Further up in the “uri” we need single quotes as you can see by adding the variable ‘singlequote’.

Related Posts

Azure DevOps Automation A couple of weeks ago the rename / rebranding of Visual Studio Team Services to Azure DevOps was announced. The rebranding is a great step forward int...
AKS (Kubernetes) and no connection could be made because the target machine acti... A client of my had an error while connecting to different resources within their Kubernetes cluster in Azure (AKS). Kubectl error On the kubectl com...
Kubernetes (AKS) attached to Azure Storage (Files) Kubernetes (AKS) can be used for many situations. For a client we needed to make files available trough a Kubernetes Pod. The files needed to be share...
Resource Group deployment via ARM templates When deploying an Azure Resource Manager (ARM) template you have to create a resource group within Azure. To deploy a template via script your script ...
Azure Managed Service Identity and Local Development Instead of storing user credentials of an external system in a configuration file, you should store them in the Azure Key Vault. Before MSI (Managed S...
The securitydata Azure resource group Most of the times companies have rules in place for managing their Azure environment. The main rules that should be in place are “Azure Policies” and ...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.