azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

New-AzBlueprintAssignment doesn't allow parameters that are complex objects

Open ChristopherGLewis opened this issue 7 years ago • 6 comments

Description

New-AzBlueprintAssignment doesn't allow parameters that are complex objects. If I have an ARM template with a parameter of type "array", the New-AzBlueprintAssignment command errors on assignment. If I add the object via the Azure Portal as JSON (like you're supposed to do) the blueprint works fine.

Steps to reproduce

Create a blue print with the following -

  • Resource Group
  • ARM resource group named "Network"

*** Removed at request from client

This starts the assignment, but fails with this error:

Artifact 'XXX-XX-XX-XX-XX' of type 'Template' failed to deploy. 

{"error":{"code":"InvalidTemplate","message":"Deployment template validation failed: 'The template resource '[concat(parameters('SubnetArray')[copyIndex()].SubnetName, 'nsg')]' at line '48' and column '9' is not valid: 

The language expression property 'SubnetName' doesn't exist, available properties are 'CliXml'.. Please see https://aka.ms/arm-template-expressions for usage details.'."}}

Environment data

PS C:\> $PSVersionTable

Name                           Value                                                                                                                                 
----                           -----                                                                                                                                 
PSVersion                      5.1.17763.503                                                                                                                         
PSEdition                      Desktop                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                               
BuildVersion                   10.0.17763.503                                                                                                                        
CLRVersion                     4.0.30319.42000                                                                                                                       
WSManStackVersion              3.0                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                   
SerializationVersion           1.1.0.1 

Module versions

PS C:\> Get-Module  -ListAvailable
Script     0.1.0      Az.Blueprint                        {Get-AzBlueprint, 

Error output

No error

ChristopherGLewis avatar May 28 '19 19:05 ChristopherGLewis

@ChristopherGLewis Hi, could you set the $DebugPreference = "Continue" and run the cmdlet so we can get the full debug output?

niander avatar May 28 '19 21:05 niander

Sure - I added to the main issue.

It looks like there's some sort of XML serialization of the object - I've tried passing it in as JSON, but the New-AzBlueprintAssignment won't take it because its not an array.

ChristopherGLewis avatar May 28 '19 21:05 ChristopherGLewis

@niander - looking at the issue. FYI.

filizt avatar May 28 '19 23:05 filizt

Hey Chris,

We looked into this. Instead of using the ConvertFrom/To-Json cmdlet, which turns it into a PSCustomObject, you can pass an array of hash table objects like the following:

$ht1 =@{SubnetName="appsn01";SubnetAddress="10.240.32.0/20";SecurityRules=@();RouteTable=@()}
$ht2 =@{SubnetName="dmzsn01";SubnetAddress="10.240.48.0/20";SecurityRules=@();RouteTable=@()}
$ARMSubnetArray = @($ht1,$ht2)

Can you try this and let us know if it works? We were able to get this to work with the export you gave us.

We are also going to be releasing a new version of our cmdlets which will support passing a JSON file directly instead of declaring the parameters inside of your powershell code as a hashtable. That should make this a lot easier and more similar to how parameters are passed to an ARM template.

alex-frankel avatar May 31 '19 16:05 alex-frankel

Alex - that did it. Not exactly sure what's the issue, maybe how PS serializes an array of hashes vs an Array of PSObjects. The crazy part is that if I run each resulting array through ConvertTo-JSON, they are identical (other then entry order).

In the interim I used the same function to deploy an ARM template outside of the blueprint, and the code worked fine.

Thanks for tracking this down.

ChristopherGLewis avatar May 31 '19 21:05 ChristopherGLewis

You bet. As a result of this, we've taken an object to see if we can handle PSCustomObject as is. We expect this will be the first time, but not the last time that this comes up. Appreciate all back and forth and patience to figure this out.

alex-frankel avatar Jun 03 '19 16:06 alex-frankel