Default Values in ARM templates when using Template Specs - azure

We have implemented Template Specs for our ARM deployments to Azure a while ago and we drastically decreased the amount of work by doing that. The next thing we're trying to achieve is to start implementing Default Values in template specs, so we do not have to specify all parameters that are the same in all our projects in the parameter files. In case we do want to override the default, we can of course specify the parameter in the parameter file.
We worked with this already in the past with templates and parameter files, but I can't get this to work with Template Specs.
As an example, I'm trying to deploy an App Service Plan like this:
Template Spec:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "object",
"defaultValue": {
"isHypervContainerPlan": false
}
},
"resourceNameAndTagSettings": {
"type": "object"
}
},
"variables": {
"appServicePlanName": "[concat('o', parameters('appServicePlanSettings').nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr)]"
},
"resources": [
{
"comments": "App Service Plans",
"condition": "[parameters('appServicePlanSettings').deploy]",
"apiVersion": "2020-09-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('appServicePlanName')]",
"location": "[resourceGroup().location]",
"tags": {
"_Purpose": "[parameters('appServicePlanSettings').tagValuePurpose]",
"CostCenter": "[parameters('resourceNameAndTagSettings').tagValueCostCenter]",
"EnvironmentType": "[parameters('resourceNameAndTagSettings').tagValueEnvironmentType]",
"Owner": "[parameters('resourceNameAndTagSettings').tagValueOwner]"
},
"kind": "[parameters('appServicePlanSettings').kind]",
"sku": {
"name": "[parameters('appServicePlanSettings').sku]",
"size": "[parameters('appServicePlanSettings').sku]",
"tier": "[parameters('appServicePlanSettings').skuTier]"
},
"properties": {
"hyperV": "[parameters('appServicePlanSettings').isHypervContainerPlan]",
"perSiteScaling": "[parameters('appServicePlanSettings').perSiteScaling]",
"reserved": "[parameters('appServicePlanSettings').isLinuxOS]"
},
"dependsOn": []
}
],
"outputs": {}
}
Main Template:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "array"
},
"dateTime": {
"type": "string",
"defaultValue": "[utcNow()]"
},
"resourceNameAndTagSettings": {
"type": "object"
},
"templateSpecSettings": {
"type": "object"
}
},
"resources": [
{
"comments": "Apps - App Service Plans",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-06-01",
"name": "[concat('Deploy-', parameters('appServicePlanSettings')[copyIndex()].nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr, '-', parameters('dateTime'))]",
"copy": {
"name": "appServicePlanCopy",
"count": "[length(parameters('appServicePlanSettings'))]"
},
"properties": {
"mode": "Incremental",
"templateLink": {
"id": "[concat('/subscriptions/', parameters('templateSpecSettings').templateSpecSubscriptionId, '/resourceGroups/', parameters('templateSpecSettings').templateSpecResourceGroupName, '/providers/Microsoft.Resources/TemplateSpecs/', parameters('templateSpecSettings').appServicePlan.name, '/versions/', parameters('templateSpecSettings').appServicePlan.version)]"
},
"parameters": {
"appServicePlanSettings": {
"value": "[parameters('appServicePlanSettings')[copyIndex()]]"
},
"resourceNameAndTagSettings": {
"value": "[parameters('resourceNameAndTagSettings')]"
}
}
},
"dependsOn": []
}
],
"outputs": {}
}
Parameter File:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"value": [
{
"comments": "App Service Plan 1",
"deploy": true,
"nameAbbr": "Asp",
"isLinuxOS": false,
"isHypervContainerPlan": false,
"perSiteScaling": false,
"tagValuePurpose": "Test",
"kind": "app",
"sku": "P1v2",
"skuTier": "PremiumV2"
}
]
},
"resourceNameAndTagSettings": {
"value": {
"environmentType": "dev",
"locationAbbr": "europe",
"resourceGroupNumber": "001",
"solutionNameAbbr": "test",
"tagValueCostCenter": "123",
"tagValueEnvironmentType": "Development",
"tagValueOwner": "me"
}
},
"templateSpecSettings": {
"value": {
"templateSpecResourceGroupName": "XXX",
"templateSpecSubscriptionId": "XXX",
"appServicePlan": {
"name": "appServicePlanTest",
"version": "1.2"
}
}
}
}
}
This deploys just fine.
But if I leave out:
"isHypervContainerPlan": false,
in the parameter file, the deployment will fail with this message:
Unable to process template language expressions for resource '...' at
line '24' and column '9'. 'The language expression property
'isHypervContainerPlan' doesn't exist, available properties are
'comments, deploy, nameAbbr, isLinuxOS, perSiteScaling,
tagValuePurpose, kind, sku, skuTier'.
Why would it fail on this error if the defaultValue is set in the Template Spec parameters section?
What am I missing here or are defaultValues not supported with Template Specs?

A defaultValue on a parameter is only used if no value is supplied. Put another way, you can you either use the defaultValue for a parameter or supply a value, not both, nor any combination of the two.
Your templateSpec expects a complex object for the appServicePlanSettings parameter. That object needs to have all of the properties referenced by the serverFarm resource being deployed. You're supplying a value for that param, but you're also omitting one of the properties from that parameter, and that's the property that's being flagged in the error message.
To see this in action in another way, put that property back into your param file and remove a different one, you'll see a similar error... or you could just not supply a param value at all for the ``appServicePlanSettings``` and then the defaultValue will be used.

I've been testing with the 'defaultValue'.
I have also tested with this setup:
Template:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "object",
"defaultValue": {
"isHypervContainerPlan": false,
"isLinuxOS": false,
"perSiteScaling": false
}
},
"resourceNameAndTagSettings": {
"type": "object"
}
},
"variables": {
"appServicePlanName": "[concat('o', parameters('appServicePlanSettings').nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr)]"
},
"resources": [
{
"comments": "App Service Plans",
"condition": "[parameters('appServicePlanSettings').deploy]",
"apiVersion": "2020-09-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('appServicePlanName')]",
"location": "[resourceGroup().location]",
"tags": {
"_Purpose": "[parameters('appServicePlanSettings').tagValuePurpose]",
"CostCenter": "[parameters('resourceNameAndTagSettings').tagValueCostCenter]",
"EnvironmentType": "[parameters('resourceNameAndTagSettings').tagValueEnvironmentType]",
"Owner": "[parameters('resourceNameAndTagSettings').tagValueOwner]"
},
"kind": "[parameters('appServicePlanSettings').kind]",
"sku": {
"name": "[parameters('appServicePlanSettings').sku]",
"size": "[parameters('appServicePlanSettings').sku]",
"tier": "[parameters('appServicePlanSettings').skuTier]"
},
"properties": {
"hyperV": "[parameters('appServicePlanSettings').isHypervContainerPlan]",
"perSiteScaling": "[parameters('appServicePlanSettings').perSiteScaling]",
"reserved": "[parameters('appServicePlanSettings').isLinuxOS]"
},
"dependsOn": []
}
],
"outputs": {}
}
Parameters:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"value": {
"comments": "App Service Plan 1",
"deploy": true,
"nameAbbr": "Asp",
"isLinuxOS": "",
"isHypervContainerPlan": "",
"perSiteScaling": "",
"tagValuePurpose": "Test",
"kind": "app",
"sku": "P1v2",
"skuTier": "PremiumV2"
}
},
"resourceNameAndTagSettings": {
"value": {
"environmentType": "dev",
"locationAbbr": "europe",
"resourceGroupNumber": "001",
"solutionNameAbbr": "test",
"tagValueCostCenter": "123",
"tagValueEnvironmentType": "Development",
"tagValueOwner": "me"
}
},
"templateSpecSettings": {
"value": {
"templateSpecResourceGroupName": "oGen1Weu1PrdMng001",
"templateSpecSubscriptionId": "130176f8-513a-4869-9db3-7c46d0e25159",
"appServicePlan": {
"name": "appServicePlanTest",
"version": "1.2"
}
}
}
}
}
Which also doesn't work when I do not specify "isHypervContainerPlan" in the parameter file, I thought we tested this, but apparently not good enough...
The only thing that works is defining:
"isHypervContainerPlan": "",
in the parameter file, thus not specifying a value. Which is not desirable, because then still all parameters have to be defined, even when I do not want to override the defaults.
So, the solution in the end has become the following (the main template remains the same):
Template Spec:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"type": "object"
},
"resourceNameAndTagSettings": {
"type": "object"
}
},
"variables": {
"appServicePlanName": "[concat('o', parameters('appServicePlanSettings').nameAbbr, parameters('resourceNameAndTagSettings').environmentType, parameters('resourceNameAndTagSettings').resourceGroupNumber, parameters('resourceNameAndTagSettings').solutionNameAbbr, parameters('resourceNameAndTagSettings').locationAbbr)]",
"appServicePlanSettings": {
"isHypervContainerPlan": false,
"isLinuxOS": false,
"kind": "app",
"nameAbbr": "Asp",
"perSiteScaling": false
}
},
"resources": [
{
"comments": "App Service Plans",
"condition": "[parameters('appServicePlanSettings').deploy]",
"apiVersion": "2020-09-01",
"type": "Microsoft.Web/serverfarms",
"name": "[variables('appServicePlanName')]",
"location": "[resourceGroup().location]",
"tags": {
"_Purpose": "[parameters('appServicePlanSettings').tagValuePurpose]",
"CostCenter": "[parameters('resourceNameAndTagSettings').tagValueCostCenter]",
"EnvironmentType": "[parameters('resourceNameAndTagSettings').tagValueEnvironmentType]",
"Owner": "[parameters('resourceNameAndTagSettings').tagValueOwner]"
},
"kind": "[if(contains(parameters('appServicePlanSettings'), 'kind'), parameters('appServicePlanSettings').kind, variables('appServicePlanSettings').kind)]",
"sku": {
"name": "[parameters('appServicePlanSettings').sku]",
"size": "[parameters('appServicePlanSettings').sku]",
"tier": "[parameters('appServicePlanSettings').skuTier]"
},
"properties": {
"hyperV": "[if(contains(parameters('appServicePlanSettings'), 'isHypervContainerPlan'), parameters('appServicePlanSettings').isHypervContainerPlan, variables('appServicePlanSettings').isHypervContainerPlan)]",
"perSiteScaling": "[if(contains(parameters('appServicePlanSettings'), 'perSiteScaling'), parameters('appServicePlanSettings').perSiteScaling, variables('appServicePlanSettings').perSiteScaling)]",
"reserved": "[if(contains(parameters('appServicePlanSettings'), 'isLinuxOS'), parameters('appServicePlanSettings').isLinuxOS, variables('appServicePlanSettings').isLinuxOS)]"
},
"dependsOn": []
}
],
"outputs": {}
}
And if I don't specify these values now in the parameter file, the value configured in the variable section will be used:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanSettings": {
"value": [
{
"comments": "App Service Plan 1",
"deploy": true,
"nameAbbr": "Asp",
"tagValuePurpose": "Test",
"kind": "app",
"sku": "P1v2",
"skuTier": "PremiumV2"
}
]
},
"resourceNameAndTagSettings": {
"value": {
"environmentType": "dev",
"locationAbbr": "europe",
"resourceGroupNumber": "001",
"solutionNameAbbr": "test",
"tagValueCostCenter": "123",
"tagValueEnvironmentType": "Development",
"tagValueOwner": "me"
}
},
"templateSpecSettings": {
"value": {
"templateSpecResourceGroupName": "XXX",
"templateSpecSubscriptionId": "XXX",
"appServicePlan": {
"name": "appServicePlanTest",
"version": "1.2"
}
}
}
}
}

Related

ARM Template : Get the SKU of IOT hub

Using the "reference" keyword I am able to access my iot hub and list its properties. However I cannot find any reference to the SKU. How can I list the sku name/tier of an iot hub to output?
If you want to get the iot hub's sku inarm template, you can use the arm template function "reference" :
[reference(resourceId('Microsoft.Devices/IotHubs', 'hubname'),'2018-04-01','Full')]
for example
template
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"hubname": {
"type": "String"
},
"location": {
"type": "String"
},
"sku_name": {
"type": "String"
},
"sku_units": {
"type": "String"
},
"d2c_partitions": {
"type": "String"
},
"features": {
"type": "String"
},
"tags": {
"type": "Object"
},
"cloudEnvironment": {
"defaultValue": "public",
"allowedValues": [
"public",
"china",
"usgov"
],
"type": "String",
"metadata": {
"description": "Cloud environment to deploy (i.e. usgov/china/ ...)"
}
}
},
"resources": [
{
"type": "Microsoft.Devices/IotHubs",
"apiVersion": "2020-07-10-preview",
"name": "[parameters('hubname')]",
"location": "[parameters('location')]",
"tags": "[parameters('tags')]",
"sku": {
"name": "[parameters('sku_name')]",
"capacity": "[parameters('sku_units')]"
},
"properties": {
"eventHubEndpoints": {
"events": {
"retentionTimeInDays": 1,
"partitionCount": "[parameters('d2c_partitions')]"
}
},
"features": "[parameters('features')]"
}
},
{
"type": "Microsoft.Security/IoTSecuritySolutions",
"apiVersion": "2019-08-01",
"name": "[parameters('hubname')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Devices/IotHubs', parameters('hubname'))]"
],
"properties": {
"status": "Enabled",
"unmaskedIpLoggingStatus": "Enabled",
"disabledDataSources": [],
"displayName": "[parameters('hubname')]",
"iotHubs": [
"[resourceId('Microsoft.Devices/IotHubs', parameters('hubname'))]"
],
"recommendationsConfiguration": []
}
}
],
"outputs": {
"iot": {
"type": "Object",
"value": "[reference(resourceId('Microsoft.Devices/IotHubs', parameters('hubname')),'2018-04-01','Full').sku]"
}
}
}
parameter
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"hubname": {
"value": "testiot05"
},
"location": {
"value": "eastasia"
},
"sku_name": {
"value": "S1"
},
"sku_units": {
"value": "1"
},
"d2c_partitions": {
"value": "4"
},
"features": {
"value": "None"
},
"tags": {
"value": {}
},
"cloudEnvironment": {
"value": "public"
}
}
}

How to tag Current time as a Tag for an ARM Deployment

I am trying to create a Log Analytics Workspace using an ARM template and a parameter files. I am also thinking to tag currrent time as CreatedOn tag for the resource.
Below is my ARM template-
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"LAWName": {
"type": "string"
},
"LocationName": {
"type": "string"
},
"SKUName": {
"type": "string"
},
"Tags": {
"type": "object"
}
},
"resources": [
{
"apiVersion": "2017-03-15-preview",
"name": "[parameters('LAWName')]",
"location": "[parameters('LocationName')]",
"tags": "[parameters('Tags')]",
"type": "Microsoft.OperationalInsights/workspaces",
"properties": {
"sku": {
"name": "[parameters('SKUName')]"
}
}
}
]
}
and here is my param file-
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"LAWName": {
"value": "atifmtest1"
},
"LocationName": {
"value": "westeurope"
},
"SKUName": {
"value": "pergb2018"
}
"Tags": {
"value": {
"CreatedBy": "Atif",
"CreatedOn": "[utcNow()]",
"Purpose": "Monitoring"
}
}
}
}
I read here https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-date#utcnow that there is utcNow() function for ARM template but that is being considered as a string here and the current time does not appear as a tag for the resource.
What is the other way using which this can be achieved ?
Thanks in advance !!
Here is a working example:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"utcShort": {
"type": "string",
"defaultValue": "[utcNow('d')]"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"resources": [
{
"apiVersion": "2019-04-01",
"type": "Microsoft.Storage/storageAccounts",
"name": "[concat('storage', uniqueString(resourceGroup().id))]",
"location": "[parameters('location')]",
"tags": {
"Dept": "Finance",
"Environment": "Production",
"LastDeployed": "[parameters('utcShort')]"
},
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {}
}
]
}
Source.
Please follow the below steps for better results.
Add the utcShort in parameters and give a default value "[utcNow()]", Its not work from the parameters file. add utcShort into variables to make an object type. Follow the below steps.
"utcShort ": {
"type": "string",
"defaultValue": "[utcNow()]"
},
"resourceTags": {
"type": "object"
}
},
"variables":{
"createdDate": {
"createdDate": "[parameters('utcShort ')]"
}
},
Use this variable in Tags like below..
"tags": "[union(parameters('resourceTags'), variables('createdDate'))]"

ARM template: issue with output in nested templates

I'm currently facing an issue with nested template.
When I'm applying my template (detail below), I get this answer from Azure:
Azure Error: InvalidTemplate
Message: Deployment template validation failed: 'The template reference 'sandbox.test.portal' is not valid: could not find template resource or resource copy with this name. Please see https://aka.ms/arm-template-expressions/#reference for usage details.'.
However, I don't really understand why I get this issue, because for the content inside the nested template, I used what they provide in the documentation here: https://github.com/Azure/azure-quickstart-templates/blob/master/101-azure-dns-new-zone/azuredeploy.json
My ARM template:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"newZoneName": {
"type": "string",
"defaultValue": "sandbox.test.portal",
"metadata": {
"description": "The name of the DNS zone to be created. Must have at least 2 segements, e.g. hostname.org"
}
},
"newRecordName": {
"type": "string",
"defaultValue": "www",
"metadata": {
"description": "The name of the DNS record to be created. The name is relative to the zone, not the FQDN."
}
}
},
"variables": {
"publicIPAddressName": "[concat(resourceGroup().name, '-pip')]",
},
"resources": [
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "2017-05-10",
"name": "nestedTemplate",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "my-rg",
"subscriptionId": "[subscription().subscriptionId]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
},
"resources": [
{
"type": "Microsoft.Network/dnszones",
"name": "[parameters('newZoneName')]",
"apiVersion": "2016-04-01",
"location": "global",
"properties": {
}
},
{
"type": "Microsoft.Network/dnszones/a",
"name": "[concat(parameters('newZoneName'), '/', parameters('newRecordName'))]",
"apiVersion": "2016-04-01",
"location": "global",
"dependsOn": [
"[parameters('newZoneName')]"
],
"properties": {
"TTL": 3600,
"ARecords": [
{
"ipv4Address": "1.2.3.4"
},
{
"ipv4Address": "1.2.3.5"
}
]
}
}
],
"outputs": {
"nameServers": {
"type": "array",
"value": "[reference(parameters('newZoneName')).nameServers]"
}
}
}
}
}
]
}
basically, you need to remove the outputs from the nested inline template, so remove this bit:
"outputs": {
"nameServers": {
"type": "array",
"value": "[reference(parameters('newZoneName')).nameServers]"
}
}
long story short, nested inline deployments are bad. dont use them.
alternatively move those to the parent template and do a real lookup:
reference(resourceId('Microsoft.Network/dnszones', parameters('newZoneName')))
You have several minor mistakes in your template:
Comma in variables '-pip')]",
Undefined parameter dnsLabelPrefix
The general mistake in nested outputs. When you use nested templates azure don't find it in your main template. Therefore you must use a reference function with identifier and API: "[reference(resourceId('Microsoft.Network/dnszones', parameters('newZoneName')), '2016-04-01').nameServers]".
I modified your template and validate in my subscription.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"newZoneName": {
"type": "string",
"defaultValue": "sandbox.test.portal",
"metadata": {
"description": "The name of the DNS zone to be created. Must have at least 2 segements, e.g. hostname.org"
}
},
"newRecordName": {
"type": "string",
"defaultValue": "www",
"metadata": {
"description": "The name of the DNS record to be created. The name is relative to the zone, not the FQDN."
}
},
"dnsLabelPrefix": {
"type": "string",
"defaultValue": "[concat('dns',uniqueString(resourceGroup().name))]"
},
"nestedResourceGroup": {
"type": "string",
"defaultValue": "my-rg",
"metadata": {
"description": "my-rg"
}
}
},
"variables": {
"publicIPAddressName": "[concat(resourceGroup().name, '-pip')]"
},
"resources": [
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "2017-05-10",
"name": "nestedTemplate",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('nestedResourceGroup')]",
"subscriptionId": "[subscription().subscriptionId]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
},
"resources": [
{
"type": "Microsoft.Network/dnszones",
"name": "[parameters('newZoneName')]",
"apiVersion": "2016-04-01",
"location": "global",
"properties": {
}
},
{
"type": "Microsoft.Network/dnszones/a",
"name": "[concat(parameters('newZoneName'), '/', parameters('newRecordName'))]",
"apiVersion": "2016-04-01",
"location": "global",
"dependsOn": [
"[resourceId('Microsoft.Network/dnszones', parameters('newZoneName'))]"
],
"properties": {
"TTL": 3600,
"ARecords": [
{
"ipv4Address": "1.2.3.4"
},
{
"ipv4Address": "1.2.3.5"
}
]
}
}
],
"outputs": {
"nameServers": {
"type": "array",
"value": "[reference(resourceId('Microsoft.Network/dnszones', parameters('newZoneName')), '2016-04-01').nameServers]"
}
}
}
}
}
]
}
Have a nice day!

How to print output of linked template using ARM template in Azure

I am using maintemplate and linked template for deployment. I want to print the output of linked template after deployment.
When I deploy the below template. I am getting the below error,
The template output 'vmpublicIPName' is not valid: The language
expression property 'publicIPName' doesn't exist, available properties
are ''.. (Code: DeploymentOutputEvaluationFailed)
How can I print the output of variables present in linked template?
Is there any way to print all the linked template deployment parameters values in main template?
storage.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string"
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS"
}
},
"variables": {
"location": "[resourceGroup().location]",
"resourceGroupName": "[resourceGroup().name]",
"subscriptionId": "[subscription().subscriptionId]"
},
"resources": [
{
"name": "[concat(parameters('storageAccountName'), '1rmtest')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2015-06-15",
"location": "[variables('location')]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
},
"tags": {
"BuildName": "StorageARM"
}
},
{
"apiVersion": "2017-03-01",
"name": "TestTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "incremental",
"templateLink": {
"uri":"https://gist.githubusercontent.com/public-ip-template.json",
"contentVersion":"1.0.0.0"
},
"parameters": {
"publicIpAddressName": {
"value": "public-ip-test"
}
}
}
}
],
"outputs": {
"vmpublicIPName": {
"type": "object",
"value": "[reference('TestTemplate').outputs.publicIPName]"
},
"vmlocation": {
"type": "object",
"value": "[reference('TestTemplate').outputs.location]"
}
}
}
Linked template:-
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"publicIpAddressName": {
"type": "string"
}
},
"variables": {
"location": "[resourceGroup().location]",
"resourceGroupName": "[resourceGroup().name]"
},
"resources": [
{
"name": "[parameters('publicIpAddressName')]",
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "2016-09-01",
"location": "[variables('location')]",
"properties": {
"publicIpAllocationMethod": "Static"
}
}
],
"outputs": {
"publicIPName": {
"type": "string",
"value": "[parameters('publicIpAddressName')]"
},
"location": {
"type": "string",
"value": "[variables('location')]"
}
}
}
Do you ensure your linked template URI is correct and accessible? According to this official document
The URI value for the linked parameter file cannot be a local file,
and must include either http or https.
I test in my lab, I only replace your URI such as below:
"templateLink": {
"uri":"https://gist.githubusercontent.com/Walter-Shui/d5387c0fc92f2e8df1c7157a2d5e54aa/raw/722d4a58107b2f617996ae237ceae445ef4342d9/test.json",
"contentVersion":"1.0.0.0"
},
Your template works for me.
How can I print the output of variables present in linked template?
Yes, this is possible. Just like your template.
Is there any way to print all the linked template deployment
parameters values in main template?
You could use Azure cli 2.0 to get linked parameter values.
az group deployment create --name shuitest1 --resource-group shuitest --template-file test.json --parameters '{"storageAccountName":{"value":"shuitest"}}'
{
"id": "/subscriptions/********/resourceGroups/shuitest/providers/Microsoft.Resources/deployments/shuitest1",
"name": "shuitest1",
"properties": {
"correlationId": "dbe16f35-0807-4627-b4b5-86c0a25c49ba",
"debugSetting": null,
"dependencies": [],
"mode": "Incremental",
"outputs": {
"vmlocation": {
"type": "Object",
"value": {
"type": "String",
"value": "centralus"
}
},
"vmpublicIPName": {
"type": "Object",
"value": {
"type": "String",
"value": "public-ip-test"
}
}
},
"parameters": {
"storageAccountName": {
"type": "String",
"value": "shuitest"
},
"storageAccountType": {
"type": "String",
"value": "Standard_LRS"
}
},
"parametersLink": null,
"providers": [
{
"id": null,
"namespace": "Microsoft.Storage",
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiVersions": null,
"locations": [
"centralus"
],
"properties": null,
"resourceType": "storageAccounts"
}
]
},
{
"id": null,
"namespace": "Microsoft.Resources",
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiVersions": null,
"locations": [
null
],
"properties": null,
"resourceType": "deployments"
}
]
}
],
"provisioningState": "Succeeded",
"template": null,
"templateLink": null,
"timestamp": "2017-04-19T02:09:55.064156+00:00"
},
"resourceGroup": "shuitest"
}
"someName": {
"type": "string",
"value": "[variables('somevar')]"
},
The same way you are outputting parameters.
No there is no way of doing that.
So what is the question, your template looks good. I've tested it and it works
ps. the link on your template is wrong, that's the only thing that doesn't work

Azure Template validation failure , expression is not valid

I've exported a resource group that contains some Logic apps that I want to use in Visual Studio but one Logic App is unable to be opened using the designer-view in VS.
I get this error even thou I haven’t modified the code in any way:
The template validation failed: 'The property 'expression' '[concat('#equals(toLower(triggerBody()?['', parameters('workflows_Booking_name'),'s']?['Event']), 'create')')]'
of template action 'Condition_-_Create_or_UpdateBookings' at line '1' and column '1827' is not a valid template language expression.'.
This is what the Logic App looks like in the portal for better understanding.
As Szymon Wylezol mentioned that it seems that it is wrong with the template itself. From the error message we know that expression [concat('#equals(toLower(triggerBody()?['', parameters('workflows_Booking_name'),'s']?['Event']), 'create')')] is incorrect. More detail about expressions please refer to document.
According to your supplied screenshot that we can get the expression as following in the code view:
"actions": {
"Condition_-_Create_or_UpdateBookings": {
"type": "If",
"expression": "#equals(toLower(triggerBody()?['Bookings']?['Event']), 'create')",
"actions": {},
"runAfter": {}
}
}
Please compare the code view in the VS with code view in the Azure portal.
Then it should be ready for view in the Visual Studio. More details about Design, build, and deploy Azure Logic Apps in Visual Studio please refer to the document
Demo code.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workflows_testlogic_name": {
"defaultValue": "testlogic",
"type": "string"
},
"workflows_tomtestLogicApp_name": {
"defaultValue": "tomtestLogicApp",
"type": "string"
}
},
"variables": {},
"resources": [
{
"comments": "Generalized from resource: '/subscriptions/ed0caab7-c6d4-45e9-9289-c7e5997c9241/resourceGroups/tomtestlogicApp/providers/Microsoft.Logic/workflows/testlogic'.",
"type": "Microsoft.Logic/workflows",
"name": "[parameters('workflows_testlogic_name')]",
"apiVersion": "2016-06-01",
"location": "eastasia",
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
"event": {
"type": "string",
"value": ""
},
"name": {
"type": "string",
"value": ""
},
"participants": {
"type": "integer",
"value": ""
}
},
"type": "object"
}
}
}
},
"actions": {
"Condition": {
"actions": {},
"runAfter": {},
"expression": "#equals(toLower(triggerBody()?['name']), 'test')",
"type": "If"
}
},
"outputs": {}
},
"parameters": {}
},
"dependsOn": []
},
{
"comments": "Generalized from resource: '/subscriptions/ed0caab7-c6d4-45e9-9289-c7e5997c9241/resourceGroups/tomtestlogicApp/providers/Microsoft.Logic/workflows/tomtestLogicApp'.",
"type": "Microsoft.Logic/workflows",
"name": "[parameters('workflows_tomtestLogicApp_name')]",
"apiVersion": "2016-06-01",
"location": "eastasia",
"tags": {
"displayName": "LogicApp"
},
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"properties": {
"Bookings": {
"properties": {
"BookedByEmail": {
"type": "string"
},
"Event": {
"type": "string"
}
}
}
}
}
}
}
},
"actions": {
"Condition_-_Create_or_UpdateBookings": {
"actions": {},
"runAfter": {},
"expression": "#equals(toLower(triggerBody()?['Bookings']?['Event']), 'create')",
"type": "If"
}
},
"outputs": {}
},
"parameters": {}
},
"dependsOn": []
}
]
}

Resources