none
Has there been a change to the "deployment()" function for Azure Resource Manager templates?

    Question

  • Has there been a change to the "deployment()" function for Azure Resource Manager templates?

    https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-deployment#deployment

    Today I got problems with the function "deployment().properties.templateLink.uri". It has worked before. I know, the classic one: "Worked before but not now". It says here (https://docs.microsoft.com/en-us/azure/templates/microsoft.resources/deployments#templatelink-object) that the "uri" property of the "TemplateLink object" is of type "string". But if I do "[concat(deployment().properties.templateLink.uri, '')]", I get the following error:
    Unable to evaluate language function 'concat': all function arguments must be string literals, integer values, boolean values or arrays.

    I also get an exception using "[uri(deployment().properties.templateLink.uri, '')]".

    Seems like deployment().properties.templateLink.uri returns an object of type "uri" and not "string" as it says.

    Regards Hans

    Friday, November 10, 2017 12:02 PM

Answers

  • I have now solved this. "deployment().properties.templateLink.uri" should be a string but to me it seems it is an uri, https://docs.microsoft.com/en-us/azure/templates/microsoft.resources/deployments#templatelink-object.

    Changed from:
    {
        "variables": {
            "deploymentDirectoryUrl": "[concat(substring(variables('deploymentUrl'), 0, indexOf(toLower(variables('deploymentUrl')), '/azure-deploy.json')), '/')]",
            "deploymentUrl": "[deployment().properties.templateLink.uri]"
        }
    }

    to:
    {
        "variables": {
            "deploymentDirectoryUrl": "[concat(substring(variables('deploymentUrl'), 0, indexOf(toLower(variables('deploymentUrl')), '/azure-deploy.json')), '/')]",
            "deploymentUrl": "[string(deployment().properties.templateLink.uri)]"
        }
    }

    With this change it works. So I must answer yes to my own question, there has been a change to the "deployment()" function.

    Regards Hans


    Friday, May 18, 2018 11:52 AM

All replies

  • Same problem here. Was working last week now not working. Cannot find any references to what has changed and if this is a bug or a permanent change.
    Monday, November 13, 2017 1:51 AM
  • I am also facing same issue. 
    Monday, November 13, 2017 2:29 PM
  • I am getting similar errors as well. This is on a public ARM template that has been used for several months without any changes to the `uri` function.

    This is a sample of what I have in my template within the `variables` section:

    {
        "variables": {
            "urls": {
                "storageAccount": "[uri(deployment().properties.templateLink.uri, 'nested/storage-account/storage-account.json')]"
            }
        }
    }

    But when I attempt to run this deployment into Azure using this command:

    az group deployment create -g rjs-1 --no-wait --parameters @local/rjs.automate.paramaters.local --template-uri https://raw.githubusercontent.com/chef-partners/arm-templates/master/solutions/automatecluster.json 

    I get the following error:

    Deployment template validation failed: 'The template variable 'urls' is not valid: The provided arguments for template language function 'uri' is not valid: all function arguments should be string literals. Please see https://aka.ms/arm-template-expressions for
    usage details.. Please see https://aka.ms/arm-template-expressions for usage details.'.

    Like Hans has said this is a classic case of 'it used to work'. However the documentation has not changed to state that the uri function works in any different way.

    Regards, Russell


    Monday, November 13, 2017 5:14 PM
  • We are investigating this issue, at present it looks like the issue may be limited to use of the uri functions in variables, so a workaround is to replace variable references with the value of the variable. Apologies for the inconvenience , I will post an update when I have more information
    Monday, November 13, 2017 10:52 PM
  • Hello,

    Why are this kind of issues not reported in Service Health - Service issues in the Azure portal, that would saved me an hour in finding the cause in my templates.

    Regards, Charl


    Tuesday, November 14, 2017 10:53 AM
  • Some more information

    Two days ago I set up some simple templates for this problem:
    https://github.com/HansKindberg-Lab/Azure-Resource-Manager-Templates-Laboratory#nested-template

    I have set up two simple templates that deploys a Public-IP-Address and using a nested template for it.
    - https://github.com/HansKindberg-Lab/Azure-Resource-Manager-Templates-Laboratory/blob/master/Nested-Template/Deploy-Nested-Template-By-Concat-And-Replace-Function.json
    - https://github.com/HansKindberg-Lab/Azure-Resource-Manager-Templates-Laboratory/blob/master/Nested-Template/Deploy-Nested-Template-By-Uri-Function.json

    At the moment it works.
    Thursday, November 16, 2017 12:39 PM
  • Now the problem is there again. toLower(deployment().properties.templateLink.uri), throws an exception: The template language function 'toLower' expects its parameter to be of type 'String'. The provided value is of type 'Uri'. Please see https://aka.ms/arm-template-expressions for usage details.

    /Hans

    Wednesday, April 4, 2018 10:09 AM
  • I have now solved this. "deployment().properties.templateLink.uri" should be a string but to me it seems it is an uri, https://docs.microsoft.com/en-us/azure/templates/microsoft.resources/deployments#templatelink-object.

    Changed from:
    {
        "variables": {
            "deploymentDirectoryUrl": "[concat(substring(variables('deploymentUrl'), 0, indexOf(toLower(variables('deploymentUrl')), '/azure-deploy.json')), '/')]",
            "deploymentUrl": "[deployment().properties.templateLink.uri]"
        }
    }

    to:
    {
        "variables": {
            "deploymentDirectoryUrl": "[concat(substring(variables('deploymentUrl'), 0, indexOf(toLower(variables('deploymentUrl')), '/azure-deploy.json')), '/')]",
            "deploymentUrl": "[string(deployment().properties.templateLink.uri)]"
        }
    }

    With this change it works. So I must answer yes to my own question, there has been a change to the "deployment()" function.

    Regards Hans


    Friday, May 18, 2018 11:52 AM