Open mshorrosh opened 8 years ago
You should be able to do this by specifying the value as a JSON object instead of a simple string.
For example, a variable named abc whose value was a dictionary with keys Key1 = Value1 and Key2 = 123 would look something like:
{
"name": "abc",
"properties": {
"value": "{\"Key1\":\"Value1\", \"Key2\":123}"
}
}
Is it possible to actually pass in an arm object type in as a parameter? For example an param object such as this:
"adSettings": { "type": "object", "metadata": { "Description": "AD settings object" } }
My end goal is to import this into a complex object variable, either by straight import like the above or to a runbook that can do the powershell (New-AzureAutomationVariable) to import it.
Yes, you should be able to pass in a JSON object as a parameter and the use it in the template. See https://azure.microsoft.com/en-us/documentation/articles/resource-group-authoring-templates/#parameters.
From: Matt Shorrosh [mailto:notifications@github.com] Sent: Tuesday, January 19, 2016 8:41 AM To: azureautomation/automation-packs automation-packs@noreply.github.com Subject: Re: [automation-packs] Creating complex object variable in ARM templating (#9)
Is it possible to actually pass in an arm object type in as a parameter? For example an param object such as this:
"adSettings": { "type": "object", "metadata": { "Description": "AD settings object" } }
My end goal is to import this into a complex object variable, either by straight import like the above or to a runbook that can do the powershell (New-AzureAutomationVariable) to import it.
— Reply to this email directly or view it on GitHubhttps://github.com/azureautomation/automation-packs/issues/9#issuecomment-172911022.
As Beth says, yes you can parameterize the value of anything in an ARM template. If you are asking if you can pass that param value as an object for variable assets specifically, the answer is no, because the value property of a variable asset only accepts strings. So you need to pass the JSON representing the object as a string, for the param value. For my example above, this would be:
"{\"Key1\":\"Value1\", \"Key2\":123}"
OK thanks for answering Joe, that was the intent of my question. Sorry I wasn't very clear there.
As an alternative, can I pass the JSON representing the object as a parameter to a Runbook Job? I'm thinking in the runbook I can create the complex object variables in AA that that way via powershell (New-AzureAutomationVariable) instead of ARM. I have some large object JSONs that are used throughout a ARM template solution, and I have this all tied in with Azure Automation, I would like to have the same objects used in my arm template available as variables that I can reference in DSC scripts.
I think that would work, yes
Attempting to pass in a json object to a run book I am getting this error as well:
JSON OBJECT as a variable:
"sqlSettings": { "sqlAlwaysOnAvailabilityGroupName1": "[parameters('sqlAlwaysOnAvailabilityGroupName1')]", "sqlAlwaysOnAvailabilityGroupName2": "[parameters('sqlAlwaysOnAvailabilityGroupName2')]", "sqlAlwaysOnEndpointName": "[parameters('sqlAlwaysOnEndpointName')]", "sqlAlwaysOnListenerName": "[parameters('sqlAlwaysOnListenerName')]", "sqlClusterName": "[parameters('sqlClusterName')]", "databaseEnginePort": "[parameters('databaseEnginePort')]" },
Parameter of object passed down to my linked template where the Runbook Job ARM is located: "sqlSettings": { "type": "object", "metadata": { "Description": "SQL settings object" } },
ARM Code for Runbook Job:
"properties": { "runbook": { "name": "SetupVariables" }, "parameters": { "domainName": "[parameters('adSettings').domainName]", "ResourceGroupName": "[resourceGroup().name]", "AzureAutomationName": "[parameters('commonSettings').aaAccountName]", "sqlSettings": "[parameters('sqlSettings')]" } } },
Error:
14:49:30 - [ERROR] '{"Message":"The request is 14:49:30 - [ERROR] invalid.","ModelState":{"job.properties.parameters.sqlSettings":["Error 14:49:30 - [ERROR] reading string. Unexpected token: StartObject. Path 14:49:30 - [ERROR] 'properties.parameters.sqlSettings', line 1, position 224."]}}'
It seems that only strings can be used as input parameters to runbooks from ARM?
You have:
"sqlSettings": "[parameters('sqlSettings')]"
But I can see sqlSettings is not a parameter, since you are constructing it in the ARM template. Did you mean this?
"sqlSettings": "[variables('sqlSettings')]"
As far as the sqlSettings it is a variable originally in a main deployment template (which is what I showed for reference). It is actually being passed via a parameter to a linked template where the Runbook Job ARM code is living at. So parameters is actually correct in my test case here.
You may want to start with a simple ARM template that just creates a job with a JSON object as a param value, to see if that works, to limit out any other issues causing this. If it does not work, try switching the param value to be a JSON string of the same JSON object, and see if that works.
If that second way works then it appears my dev contact informed me incorrectly that JSON objects could be passed instead of only JSON strings, for job param values
Hi
Is there currently a way to create a complex object Azure Automation Variable via ARM?
Thanks Matt