Escape Single Quotes within Azure Resource Template

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 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 ...
Point to Site VPN Client won’t install To connect an Azure App Service to a on-premise database you can make use of different solutions. Two of those solutions are: Hybrid Connection ...
Invoke Azure Function in your Visual Studio Team Services CI/CD pipeline A utility task is available for Visual Studio Team Services (VSTS) to invoke an http triggered Azure function. The ability to invoke a Function from y...
VSTS Extension for Azure Role Based Access Control Today I published an extension for Visual Studio Team Services (VSTS) that gives you the ability to add and remove role based access assignments in Az...
Listing Azure Services within a CSV file In some situations you will look into a current Azure Environment and the setup/governance of it and need to migrate or move resources around. The ...

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.