Azure Function App new JSON with only a few properties - json

I am struggling of finding a feasible solution for my Azure Logic App.
A HTTP Request-action call will list the virtual networks of an Azure subscription.
The response look somehow like this:
{
"value": [
{
"name": "virtualNetworkName1",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName1/providers/Microsoft.Network/virtualNetworks/virtualNetworkName1",
"etag": "W/\"11111-1111-111\"",
"type": "Microsoft.Network/virtualNetworks",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "111-1111-11111",
"addressSpace": {
"addressPrefixes": [
"192.168.0.0/25"
]
}
}
},
{
"name": "virtualNetworkName2",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName2/providers/Microsoft.Network/virtualNetworks/virtualNetworkName2",
"etag": "W/\"22222-2222-222\"",
"type": "Microsoft.Network/virtualNetworks",
"location": "westeurope",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "222-2222-22222",
"addressSpace": {
"addressPrefixes": [
"192.168.1.0/24"
]
}
}
}
]
}
The resonse has even more properties which aren't necessary.
Regarding to this, I would like to use the HTTP Response-action in a JSON format with only a few properties:
Name
Id
Location
Like this:
[
{
"name": "virtualNetworkName1",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName1/providers/Microsoft.Network/virtualNetworks/virtualNetworkName1",
"location": "eastus"
},
{
"name": "virtualNetworkName2",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName2/providers/Microsoft.Network/virtualNetworks/virtualNetworkName2",
"location": "westeurope"
}
]
Is it possible to realize it with only Logic App native actions?

I have reproduced in my environment and got expected results as below:
Firstly, I have initialized your output in a variable and then used parse Json and compose to get required output:
Parse Json Schema:
{
"properties": {
"value": {
"items": {
"properties": {
"id": {
"type": "string"
},
"location": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
Output:
First json Output:
Second one:
Code view of Logic app:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"value": [
{
"etag": "W/\"11111-1111-111\"",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName1/providers/Microsoft.Network/virtualNetworks/virtualNetworkName1",
"location": "eastus",
"name": "virtualNetworkName1",
"properties": {
"addressSpace": {
"addressPrefixes": [
"192.168.0.0/25"
]
},
"provisioningState": "Succeeded",
"resourceGuid": "111-1111-11111"
},
"type": "Microsoft.Network/virtualNetworks"
},
{
"etag": "W/\"22222-2222-222\"",
"id": "/subscriptions/111-222-333/resourceGroups/resourceGroupName2/providers/Microsoft.Network/virtualNetworks/virtualNetworkName2",
"location": "westeurope",
"name": "virtualNetworkName2",
"properties": {
"addressSpace": {
"addressPrefixes": [
"192.168.1.0/24"
]
},
"provisioningState": "Succeeded",
"resourceGuid": "222-2222-22222"
},
"type": "Microsoft.Network/virtualNetworks"
}
]
},
"runAfter": {},
"type": "Compose"
},
"For_each": {
"actions": {
"Compose_2": {
"inputs": {
"id": "#items('For_each')?['id']",
"location": "#items('For_each')?['location']",
"name": "#items('For_each')?['name']"
},
"runAfter": {},
"type": "Compose"
}
},
"foreach": "#body('Parse_JSON')?['value']",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Parse_JSON": {
"inputs": {
"content": "#outputs('Compose')",
"schema": {
"properties": {
"value": {
"items": {
"properties": {
"id": {
"type": "string"
},
"location": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Now you will get required fields as I have got.

Related

How to use parameter value inside the siteconfig in ARM template?

I have below code for the create function app :
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"parameters": {
"storage_account_name": {
"type": "string",
"defaultValue": "test"
},
"location": {
"defaultValue": "[resourceGroup().location]",
"type": "string"
},
"App_Plan_Name": {
"type": "string",
"defaultValue": "test1"
},
"Function_App_Name": {
"type": "string",
"defaultValue": "funapwp11"
},
"AI_Name": {
"type": "string",
"defaultValue": "appinsiwghts"
},
"Appsetting_For_Fun_App": {
"type": "object",
"defaultValue": {
"client_id": "",
"client_secret": "",
"subscription_id": "",
"tenant_id": "",
"FUNCTIONS_EXTENSION_VERSION": "~4",
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
},
"variables": {
"unique_Storage_Name": "[concat(parameters('storage_account_name'),uniqueString(resourceGroup().id))]",
//"Unique_App_Service_Name": "[concat(parameters('App_Service_Name'),uniqueString(resourceGroup().id))]",
"Unique_App_Plan_Name": "[concat(parameters('App_Plan_Name'),uniqueString(resourceGroup().id))]",
"Unique_Fun_App_Name": "[concat(parameters('Function_App_Name'),uniqueString(resourceGroup().id))]",
"Unique_AI_Name": "[concat(parameters('AI_Name'),uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2022-03-01",
"location": "[parameters('location')]",
"name": "[variables('Unique_Fun_App_Name')]",
"kind": "functionapp",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('Unique_App_Plan_Name'))]",
"[resourceId('Microsoft.Storage/storageAccounts',variables('unique_Storage_Name'))]",
"[resourceId('Microsoft.Insights/components',variables('Unique_AI_Name'))]"
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms',variables('Unique_App_Plan_Name'))]",
"httpsOnly": true,
"enabled": true,
"adminEnabled": true,
"sku": "Basic",
"siteProperties": {
"properties": [
{
"name": "LinuxFxVersion",
"value": "Python|3.9"
},
{
"name": "WindowsFxVersion",
"value": null
}
]
},
"siteConfig": {
"linuxFxVersion": "Python|3.9",
"alwaysOn": true,
"pythonVersion": "3.9",
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(resourceId('Microsoft.Insights/components', variables('Unique_AI_Name'))).InstrumentationKey]"
},
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"value": "[reference(resourceId('Microsoft.Insights/components',variables('Unique_AI_Name')),'2020-02-02-preview').ConnectionString]"
},
{
"name": "AzureWebJobsStorage",
"value": "[format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('Unique_Storage_Name'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('Unique_Storage_Name')), '2021-08-01').keys[0].value)]"
}
]
}
}
}
]
}
I want use Appsetting_For_Fun_App parameter inside the properties >> siteConfig >> appSettings.
Parameter:
"Appsetting_For_Fun_App": {
"type": "object",
"defaultValue": {
"client_id": "",
"client_secret": "",
"subscription_id": "",
"tenant_id": "",
"FUNCTIONS_EXTENSION_VERSION": "~4",
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
I need like that
"appSettings": [
{
"name": "[parameters('Appsetting_For_Fun_App')]",
"value": "[parameters('Appsetting_For_Fun_App')]"
},
I have tried multiple way but no luck.
You can refer the question: Azure resource manager template website app settings
Two options I can think of:
format the parameter as an object array - then no transform is needed in the template...
"parameters": {
"Appsetting_For_Fun_App": {
"type": "array",
"defaultValue": [
{
"name": "client_id",
"value": ""
},
{
"name": "client_secret",
"value": ""
},
{
"name": "subscription_Id",
"value": ""
}
]
}
And then on the web app:
"siteConfig": {
"linuxFxVersion": "Python|3.9",
"alwaysOn": true,
"pythonVersion": "3.9",
"appSettings": "[parameters('Appsettings_For_Fun_App')]"
but you can also do it via:
transform in the template, simplest to illustrate using a variable:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"myValues": {
"type": "object",
"defaultValue": {
"setting1": "value1",
"setting2": "value2",
"setting3": "value3"
}
}
},
"variables": {
"copy": [
{
"name": "foo",
"count": "[length(items(parameters('myValues')))]",
"input": {
"name": "[items(parameters('myValues'))[copyIndex('foo')].key]",
"value": "[items(parameters('myValues'))[copyIndex('foo')].value]"
}
}
]
},
"resources": [],
"outputs": {
"bar": {
"type": "array",
"value": "[variables('foo')]"
}
}
}

Mapping request body fields in logic apps

We have configured common alert schema for alerts and we are using a ticketing software and whenever we receive alert it should create a ticket.
In the logic app I have to make Post API call for creation of ticket with following json object, some fields are hard coded values:
{
"subject": "",
"Id": "123456789", // Hard code value
"priority": "",
"email": "test#test.com", // Hard code value
"status": "Open" // Hard code value
}
Parse Json sample payload schema for Alert:
{
"data": {
"alertContext": {
},
},
"customProperties": null,
"essentials": {
"alertContextVersion": "123",
"alertId": "123",
"alertRule": "Test Alerts",
"description": "test",
"severity": "Sev4"
}
},
"schemaId": "test"
}
I have to map "subject and "priority" fields with alert json object "description" and "severity":
subject-->description
priority --> severity // sev0 =high ,sev1=medium, sev2 =low
How can I achieve this using logic app?
After Parse JSON You can directly map its objects in the compose connector with the required fields. Below is my logic app flow.
You can use the below Code view to reproduce the same in your Logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"customProperties": null,
"data": {
"alertContext": {}
},
"essentials": {
"alertContextVersion": "123",
"alertId": "123",
"alertRule": "Test Alerts",
"description": "test",
"severity": "Sev4"
},
"schemaId": "test"
},
"runAfter": {},
"type": "Compose"
},
"Compose_2": {
"inputs": {
"Id": "123456789",
"email": "test#test.com",
"priority": "#{body('Parse_JSON')?['essentials']?['severity']}",
"status": "Open",
"subject": "#{body('Parse_JSON')?['essentials']?['description']}"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Compose"
},
"Parse_JSON": {
"inputs": {
"content": "#outputs('Compose')",
"schema": {
"properties": {
"customProperties": {},
"data": {
"properties": {
"alertContext": {
"properties": {},
"type": "object"
}
},
"type": "object"
},
"essentials": {
"properties": {
"alertContextVersion": {
"type": "string"
},
"alertId": {
"type": "string"
},
"alertRule": {
"type": "string"
},
"description": {
"type": "string"
},
"severity": {
"type": "string"
}
},
"type": "object"
},
"schemaId": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

Editing json content with azure logic app

I want to create a logic app which replaces the value of resourcename inside an alert json structure received by a logic app. The alarm structure is as follows:
{
"schemaId": "AzureMonitorMetricAlert",
"data": {
"version": "2.0",
"properties": null,
"status": "Deactivated",
"context": {
"timestamp": "2021-08-21T01:43:09.2000007Z",
"id": "/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/microsoft.insights/metricAlerts/teste%20-%20vpnp2s%20count",
"name": "teste - vpnp2s count",
"description": "",
"conditionType": "SingleResourceMultipleMetricCriteria",
"severity": "3",
"condition": {
"windowSize": "PT1M",
"allOf": [
{
"metricName": "P2SConnectionCount",
"metricNamespace": "Microsoft.Network/p2sVpnGateways",
"operator": "GreaterThanOrEqual",
"threshold": "1",
"timeAggregation": "Total",
"dimensions": [],
"metricValue": 0,
"webTestName": null
}
]
},
"subscriptionId": "<subscription_id>",
"resourceGroupName": "<my_resource_group>",
"resourceName": "some_resource_name",
"resourceType": "Microsoft.Network/p2sVpnGateways",
"resourceId": "/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/Microsoft.Network/p2sVpnGateways/<p2svpngatewayid>",
"portalLink": "https://portal.azure.com/#resource/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/Microsoft.Network/p2sVpnGateways/<theresourceid>"
}
}
}
I've been trying all sorts of mix with 'set variable', 'initialize variable', 'compose' blocks, but still no luck. Anyone has a clue?
Based on the above requirement i have created the logic app which replaces the resource name using HTTP request & replace actions.
Below is the code view of my logic app :
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"ConversionToString": {
"inputs": {
"variables": [
{
"name": "StringConversion",
"type": "string",
"value": "#{json(string(triggerBody()))}"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"FInalJsonOutput": {
"inputs": {
"variables": [
{
"name": "JsonOutput",
"type": "object",
"value": "#json(variables('replaceResouceName'))"
}
]
},
"runAfter": {
"ReplaceResourceName": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"ReplaceResourceName": {
"inputs": {
"variables": [
{
"name": "replaceResouceName",
"type": "string",
"value": "#{replace(variables('StringConversion'),'some_resource_name','newresource')}"
}
]
},
"runAfter": {
"ConversionToString": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"data": {
"properties": {
"context": {
"properties": {
"condition": {
"properties": {
"allOf": {
"items": {
"properties": {
"dimensions": {
"type": "array"
},
"metricName": {
"type": "string"
},
"metricNamespace": {
"type": "string"
},
"metricValue": {
"type": "integer"
},
"operator": {
"type": "string"
},
"threshold": {
"type": "string"
},
"timeAggregation": {
"type": "string"
},
"webTestName": {}
},
"required": [
"metricName",
"metricNamespace",
"operator",
"threshold",
"timeAggregation",
"dimensions",
"metricValue",
"webTestName"
],
"type": "object"
},
"type": "array"
},
"windowSize": {
"type": "string"
}
},
"type": "object"
},
"conditionType": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"portalLink": {
"type": "string"
},
"resourceGroupName": {
"type": "string"
},
"resourceId": {
"type": "string"
},
"resourceName": {
"type": "string"
},
"resourceType": {
"type": "string"
},
"severity": {
"type": "string"
},
"subscriptionId": {
"type": "string"
},
"timestamp": {
"type": "string"
}
},
"type": "object"
},
"properties": {},
"status": {
"type": "string"
},
"version": {
"type": "string"
}
},
"type": "object"
},
"schemaId": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Here is the sample output for reference post running the above logic app

Creating an Arm template to host a php app on azure app service

I am trying to create an app service that is using PHP as it's runtime using ARM templates however the default config always leads to the creation of .Net
Example from my template:
{
"apiVersion": "2018-11-01",
"name": "[concat(parameters('webSiteName'),copyIndex(1))]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"copy": {
"name": "webloop",
"count": 2
},
"identity": {
"type": "SystemAssigned"
},
"dependsOn": [
"[concat(variables('targetResourceId'),copyIndex(1))]",
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
],
"tags": {
"project": "zdemo"
},
"properties": {
"name": "[concat(parameters('webSiteName'),copyIndex(1))]",
"serverFarmId": "[concat(variables('targetResourceId'),copyIndex(1))]",
"siteConfig": {
"phpVersion": "7.3",
"use32BitWorkerProcess": false,
"connectionStrings": [
{
"name": "connstr",
"connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2015-05-01-preview').key1,';EndpointSuffix=core.windows.net')]",
"type": "Custom"
}
]
}
}
}
Here i have chosen php version however upon template deployment i see the default is to .Net
According to my test, you can use the following template to create a PHP web app on Azure.
template.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"type": "string"
},
"name": {
"type": "string"
},
"location": {
"type": "string"
},
"hostingEnvironment": {
"type": "string"
},
"hostingPlanName": {
"type": "string"
},
"serverFarmResourceGroup": {
"type": "string"
},
"alwaysOn": {
"type": "bool"
},
"currentStack": {
"type": "string"
},
"phpVersion": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2018-02-01",
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('location')]",
"tags": {},
"dependsOn": [],
"properties": {
"name": "[parameters('name')]",
"siteConfig": {
"appSettings": [],
"metadata": [
{
"name": "CURRENT_STACK",
"value": "[parameters('currentStack')]"
}
],
"phpVersion": "[parameters('phpVersion')]",
"alwaysOn": "[parameters('alwaysOn')]"
},
"serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"hostingEnvironment": "[parameters('hostingEnvironment')]",
"clientAffinityEnabled": true
}
}
]
}
parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"value": " "
},
"name": {
"value": " "
},
"location": {
"value": "Southeast Asia"
},
"hostingEnvironment": {
"value": ""
},
"hostingPlanName": {
"value": " "
},
"serverFarmResourceGroup": {
"value": " "
},
"alwaysOn": {
"value": true
},
"currentStack": {
"value": "php"
},
"phpVersion": {
"value": "7.3"
}
}
}
For more details, please refer to the document.

Error creating JSON Unexpected Character Sequence

I've been trying to create a basic json for our testes to throw up a machine a and when required. I got most of it done however I am getting the following errors:
Line 158 Unexpected character sequence in member name
Line 167 A member with the name 'Properties' already exists
I understand 67 needs to be unique, but everytime I change and remove the { it creates more errors.
And unexpected character is the { on line 157, which I'm guessing should be either a string, maybe?
My template is below.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"offer": {
"type": "string",
"defaultvalue": "Windows",
"allowedValues": [
"windows",
"centos",
"RHEL"
]
},
"sku": {
"type": "string",
"defaultvalue": "2012-r2-datacenter",
"allowedValues": [
"2012-R2-Datacenter",
"2012-R2",
"68",
"72",
"73",
"74"
]
},
"virtualMachineSize": {
"type": "string",
"defaultvalue": "standard_A0",
"allowedValues": [
"Standard_A0",
"Standard_A1",
"standard_A2"
]
},
"adminUsername": {
"type": "string"
},
"ipaddress": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"storageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"ContainerName": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId('avset','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"stdvhdcontainername": "[concat(parameters('Containername'))]",
"vmosidiskname": "[concat(parameters('virtualMachineName'),'-osdisk')]"
},
"resources": [
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat (parameters('diagnosticsStorageAccountName')), ['blob']]"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"offer": "[concat(parameters('offer'))]",
"sku": "[concat(parameters('offer'))]",
"version": "latest"
}
},
"osDisk": {
"vhd": {
"name": "[variables('vmosidiskname')]",
"uri": "[concat('http://', parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdvhdcontainername'),'/', variables('vmosidiskname'), '.vhd')]"
},
"name": "[parameters('virtualMachineName')]"
},
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"timeInMinutes": "30"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
},
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]"
},
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateipaddress": "[concat(parameters('ipaddress'))]",
"privateIPAllocationMethod": "static"
}
}
]
}
},
"outputs": [
{
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
]
}
]
}
Any pointers would be greatly appreciated.. thanks for your help :)
Params are below:)
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "westeurope"
},
"virtualMachineName": {
"value": "cent-os-vm2"
},
"virtualMachineSize": {
"value": "Standard_A0"
},
"adminUsername": {
"value": "localadmin"
},
"virtualNetworkName": {
"value": "avset-vnet"
},
"networkInterfaceName": {
"value": "cent-os-vm01652"
},
"networkSecurityGroupName": {
"value": "cent-os-vm01-nsg"
},
"storageAccountName": {
"value": "avsetdisks419"
},
"diagnosticsStorageAccountName": {
"value": "avsetdiag112"
},
"diagnosticsStorageAccountId": {
"value": "avsetdiag117"
},
"subnetName": {
"value": "default"
},
"autoShutdownStatus": {
"value": "Enabled"
},
"autoShutdownTime": {
"value": "19:00"
},
"autoShutdownTimeZone": {
"value": "UTC"
},
"autoShutdownNotificationStatus": {
"value": "Disabled"
},
"ContainerName": {
"value": "vhd"
},
"offer": {
"value": "windows"
},
"sku": {
"value": "2012-R2-Datacenter"
},
"ipaddress": {
"value": "10.0.1.9"
}
}
}
There are many mistakes in your template. The following template should work.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"offer": {
"type": "string",
"defaultvalue": "windows",
"allowedValues": [
"windows",
"centos",
"RHEL"
]
},
"sku": {
"type": "string",
"defaultvalue": "2012-R2-Datacenter",
"allowedValues": [
"2012-R2-Datacenter",
"2012-R2",
"68",
"72",
"73",
"74"
]
},
"virtualMachineSize": {
"type": "string",
"defaultvalue": "Standard_A0",
"allowedValues": [
"Standard_A0",
"Standard_A1",
"standard_A2"
]
},
"adminUsername": {
"type": "string"
},
"ipaddress": {
"type": "string"
},
"virtualNetworkName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"storageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"ContainerName": {
"type": "string"
},
"autoShutdownStatus": {
"type": "string"
},
"autoShutdownTime": {
"type": "string"
},
"autoShutdownTimeZone": {
"type": "string"
},
"autoShutdownNotificationStatus": {
"type": "string"
}
},
"variables": {
"vnetId": "[resourceId('avset','Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"stdvhdcontainername": "[concat(parameters('Containername'))]",
"vmosidiskname": "[concat(parameters('virtualMachineName'),'-osdisk')]"
},
"resources": [
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2016-04-30-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat (parameters('diagnosticsStorageAccountName')), ['blob']]"
}
},
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"offer": "[concat(parameters('offer'))]",
"sku": "[concat(parameters('offer'))]",
"version": "latest"
}
},
"osDisk": {
"vhd": {
"name": "[variables('vmosidiskname')]",
"uri": "[concat('http://', parameters('storageAccountName'), '.blob.core.windows.net/', variables('stdvhdcontainername'),'/', variables('vmosidiskname'), '.vhd')]"
},
"name": "[parameters('virtualMachineName')]"
}
}
},
{
"name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
"type": "Microsoft.DevTestLab/schedules",
"apiVersion": "2017-04-26-preview",
"location": "[parameters('location')]",
"properties": {
"status": "[parameters('autoShutdownStatus')]",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "[parameters('autoShutdownTime')]"
},
"timeZoneId": "[parameters('autoShutdownTimeZone')]",
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
"notificationSettings": {
"status": "[parameters('autoShutdownNotificationStatus')]",
"timeInMinutes": "30"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
}
},
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateipaddress": "[concat(parameters('ipaddress'))]",
"privateIPAllocationMethod": "static"
}
}
]
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
In line 162, it lost a ,. Resource Microsoft.Compute/virtualMachines,Microsoft.DevTestLab/schedules,Microsoft.Network/networkInterfaces are in parallel. But in your template, Microsoft.Compute/virtualMachines contains others, so you get error log with the name 'Properties' already exists.
Note: You also need check your default value. Please note that case sensitive.
Update:
Ipconfigurations is wrong, it should like below:
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
Update 2:
The template.json and parameters.json works for me. Maybe you could modify your template according to this example.