Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating complex object variable in ARM templating #9

Open
mshorrosh opened this issue Jan 19, 2016 · 10 comments
Open

Creating complex object variable in ARM templating #9

mshorrosh opened this issue Jan 19, 2016 · 10 comments

Comments

@mshorrosh
Copy link

Hi

Is there currently a way to create a complex object Azure Automation Variable via ARM?

Thanks
Matt

@jodoglevy
Copy link
Contributor

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}"
  }
}

@mshorrosh
Copy link
Author

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.

@elcooper
Copy link
Contributor

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:[email protected]]
Sent: Tuesday, January 19, 2016 8:41 AM
To: azureautomation/automation-packs [email protected]
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//issues/9#issuecomment-172911022.

@jodoglevy
Copy link
Contributor

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}"

@mshorrosh
Copy link
Author

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.

@jodoglevy
Copy link
Contributor

I think that would work, yes

@mshorrosh
Copy link
Author

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?

@jodoglevy
Copy link
Contributor

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')]"

@mshorrosh
Copy link
Author

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.

@jodoglevy
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants