Az.Resources 2.5 broke ARM template Copy/Arrays vs 2.4
Description
The Recent update to Az.Resources broke the processing of an ARM Template that we use to deploy solutions. It uses a simple ARM template and array to install a list of LogAnalytics solutions.
The error specifically has to do with the concat to build up the resource name.
"name": "[Concat(parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'), ')')]",
InvalidTemplate - Deployment template validation failed: 'The template resource '[concat(parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'),
')')]' at line '46' and column '9' is not valid: The provided parameters for language function 'concat' are invalid. Either all or none of the parameters must be an
array. Please see https://aka.ms/arm-template-expressions/#concat for usage details.. Please see https://aka.ms/arm-template-expressions for usage details.'.
Steps to reproduce
Upgrade to latest Az module.
Install-Module Az -AllowClobber -Force
Deploy/Test an ARM template
Get-Module -ListAvailable | ? {$_.Name -eq 'Az.Resources'}
Directory: C:\Users\UserName\Documents\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 2.5.0 Az.Resources Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignme…
test-AzResourceGroupDeployment -ResourceGroupName prduseaazmrg `
-TemplateFile .\AZMonitorSolutions\AZMonitorSolutions.json `
-TemplateParameterFile .\AZMonitorSolutions\AZMonitorSolutions.parameters.prduseaazmwsa52ecc159d.json
InvalidTemplate - Deployment template validation failed: 'The template resource '[concat(parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'),
')')]' at line '46' and column '9' is not valid: The provided parameters for language function 'concat' are invalid. Either all or none of the parameters must be an
array. Please see https://aka.ms/arm-template-expressions/#concat for usage details.. Please see https://aka.ms/arm-template-expressions for usage details.'.
Note that this same template and parameter file can be deployed via the Microsoft Template blade https://portal.azure.com/#create/Microsoft.Template
and also can be deployed with Az.Resources 2.4 with no issues.
Environment data
PS C:\VSProjects\DevOps\AzureReadyFoundation\LogAnalyticsSolutions> $PSVersionTable
Name Value
---- -----
PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
Get-Module -ListAvailable | ? {$_.Name -eq 'Az.Resources'}
Directory: C:\Users\UserName\Documents\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 2.5.0 Az.Resources Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignme…
Debug output
PS C:\VSProjects\DevOps\AzureReadyFoundation\LogAnalyticsSolutions> test-AzResourceGroupDeployment -ResourceGroupName prduseaazmrg `
>> -TemplateFile .\AZMonitorSolutions\AZMonitorSolutions.json `
>> -TemplateParameterFile .\AZMonitorSolutions\AZMonitorSolutions.parameters.prduseaazmwsa52ecc159d.json
>>
DEBUG: 9:28:01 PM - TestAzureResourceGroupDeploymentCmdlet begin processing with ParameterSet 'ByTemplateFileAndParameterFile'.
DEBUG: 9:28:01 PM - using account id '[email protected]'...
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud', tenant: '<GUID>'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '<GUID>', Endpoint: 'https://login.microsoftonline.com/', ClientId: '<GUID>', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/<GUID>/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: '<GUID>', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '<GUID>', ClientRedirectUri: urn:ietf:wg:oauth:2.0:oob
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3892680Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3893855Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: ADAL PCL.CoreCLR with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3894337Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: === Token Acquisition started:
CacheType: null
Authentication Target: User
, Authority Host: login.microsoftonline.com
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3894586Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: === Token Acquisition started:
Authority: https://login.microsoftonline.com/<GUID>/
Resource: https://management.core.windows.net/
ClientId: <GUID>
CacheType: null
Authentication Target: User
DEBUG: [ADAL]: Verbose: 2020-09-15T02:28:01.3896116Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: Loading from cache.
DEBUG: [ADAL]: Verbose: 2020-09-15T02:28:01.3896348Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: Loading from cache.
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3923333Z: 00000000-0000-0000-0000-000000000000 - LoggerBase.cs: Deserialized 1 items to token cache.
DEBUG: [ADAL]: Verbose: 2020-09-15T02:28:01.3924399Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: Looking up cache for a token...
DEBUG: [ADAL]: Verbose: 2020-09-15T02:28:01.3924635Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: Looking up cache for a token...
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3925413Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: An item matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3925618Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: An item matching the requested resource was found in the cache
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3926722Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: 31.405188948333333 minutes left until token in cache expires
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3926917Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: 31.405188948333333 minutes left until token in cache expires
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3927152Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3927309Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3928475Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 9/15/2020 2:59:25 AM +00:00
DEBUG: [ADAL]: Information: 2020-09-15T02:28:01.3928781Z: d22794d0-2205-47d0-a6eb-8c07f1d98e08 - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 9/15/2020 2:59:25 AM +00:00Access Token Hash: 8Z0yNjJfzLW5tftYKk5zKiH/9Jnep88tNTWQGCJXWOs=
User id: fada3906-2320-43ff-b960-1d2a52681995
DEBUG: [Common.Authentication]: Renewing Token with Type: 'Bearer', Expiry: '09/15/2020 02:59:25 +00:00', MultipleResource? 'True', Tenant: '<GUID>', UserId: '[email protected]'
DEBUG: [Common.Authentication]: User info for token DisplayId: '[email protected]', Name: User Name, IdProvider: 'https://sts.windows.net/7c55576f-e738-4097-8c71-053078eadf3f/', Uid: 'fada3906-2320-43ff-b960-1d2a52681995'
DEBUG: [Common.Authentication]: Checking token expiration, token expires '09/15/2020 02:59:25 +00:00' Comparing to '09/15/2020 02:28:01 +00:00' With threshold '00:05:00', calculated time until token expiry: '00:31:24.2813392'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
POST
Absolute Uri:
https://management.azure.com/subscriptions/<GUID>/resourcegroups/prduseaazmrg/providers/Microsoft.Resources/deployments/7db97c22-35d5-4c4c-b8f5-260a56657c5e/validate?api-version=2020-06-01
Headers:
x-ms-client-request-id : fcf057eb-026a-4337-a684-05f0d0eef940
Accept-Language : en-US
Body:
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": ""
},
"resourcegroupName": {
"type": "string",
"defaultValue": ""
},
"subscriptionId": {
"type": "string",
"defaultValue": ""
},
"workspaceName": {
"type": "string",
"defaultValue": ""
},
"solutionTypes": {
"type": "array",
"defaultValue": []
},
"Tags": {
"defaultValue": {},
"type": "Object"
}
},
"resources": [
{
"apiVersion": "2015-11-01-preview",
"type": "Microsoft.OperationsManagement/solutions",
"location": "[parameters('location')]",
"name": "[concat(parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'), ')')]",
"id": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('resourcegroupName'), '/providers/Microsoft.OperationsManagement/solutions/', parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'), ')')]",
"properties": {
"workspaceResourceId": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('resourcegroupName'), '/providers/Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]"
},
"tags": "[parameters('tags')]",
"plan": {
"name": "[concat(parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'), ')')]",
"product": "[concat('OMSGallery/', parameters('solutionTypes')[copyIndex()])]",
"promotionCode": "",
"publisher": "Microsoft"
},
"copy": {
"name": "solutionsCopy",
"count": "[length(parameters('solutionTypes'))]"
}
}
]
},
"parameters": {
"solutionTypes": {
"value": [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]
},
"resourcegroupName": {
"value": "prduseaazmrg"
},
"workspaceName": {
"value": "prduseaazmwsa52ecc159d"
},
"location": {
"value": "East US"
},
"tags": {
"value": {
"nS_Location": "USEA - East US",
"nS_Environment": "PRD - Production",
"createdBy": "[email protected]",
"createdDate": "2020-09-14 16:26:13 -05:00",
"nS_Application": "AZM - Azure Monitor"
}
},
"subscriptionId": {
"value": "<GUID>"
}
},
"mode": "Incremental"
}
}
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id : 7be2ca55-e0ef-4dac-87a6-a5f232264329
x-ms-correlation-request-id : 7be2ca55-e0ef-4dac-87a6-a5f232264329
x-ms-routing-request-id : NORTHCENTRALUS:20200915T022801Z:7be2ca55-e0ef-4dac-87a6-a5f232264329
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Tue, 15 Sep 2020 02:28:01 GMT
Body:
{
"error": {
"code": "InvalidTemplate",
"message": "Deployment template validation failed: 'The template resource '[concat(parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'), ')')]' at line '46' and column '9' is not valid: The provided parameters for language function 'concat' are invalid. Either all or none of the parameters must be an array. Please see https://aka.ms/arm-template-expressions/#concat for usage details.. Please see https://aka.ms/arm-template-expressions for usage details.'.",
"additionalInfo": [
{
"type": "TemplateViolation",
"info": {
"lineNumber": 46,
"linePosition": 9,
"path": "properties.template.resources[1]"
}
}
]
}
}
InvalidTemplate - Deployment template validation failed: 'The template resource '[concat(parameters('solutionTypes')[copyIndex()], '(', parameters('workspaceName'),
')')]' at line '46' and column '9' is not valid: The provided parameters for language function 'concat' are invalid. Either all or none of the parameters must be an
array. Please see https://aka.ms/arm-template-expressions/#concat for usage details.. Please see https://aka.ms/arm-template-expressions for usage details.'.
DEBUG: AzureQoSEvent: CommandName - Test-AzResourceGroupDeployment; IsSuccess - True; Duration - 00:00:01.5941827;
DEBUG: Finish sending metric.
DEBUG: 9:28:03 PM - TestAzureResourceGroupDeploymentCmdlet end processing.
Error output
PS C:\VSProjects\DevOps\AzureReadyFoundation\LogAnalyticsSolutions> Resolve-AzError
WARNING: Breaking changes in the cmdlet 'Resolve-AzError' :
WARNING: - The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.
WARNING: NOTE : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.
HistoryId: 5
Message : Module 'Az.Accounts' is in currently in use or you don't have the required permissions.
StackTrace :
Exception : System.Exception
InvocationInfo : {Uninstall-Package}
Line : $null = PackageManagement\Uninstall-Package @PSBoundParameters
Position : At C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:12731 char:21
+ … $null = PackageManagement\Uninstall-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 5
HistoryId: 4
Message : Module 'Az.Accounts' is in currently in use or you don't have the required permissions.
StackTrace :
Exception : System.Exception
InvocationInfo : {Uninstall-Package}
Line : $null = PackageManagement\Uninstall-Package @PSBoundParameters
Position : At C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:12731 char:21
+ … $null = PackageManagement\Uninstall-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 4
The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.
@ChristopherGLewis , please check if it is the similar issue #12773. New version should be available in the next week.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @armleads-azure.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @armleads-azure.
+1 It happens in Azure Pipelines with AzurePowerShell@4 (LatestVersion); If I switch back to a previous working pipeline for version "3.8.0" it all works well again.
@ChristopherGLewis , please check if it is the similar issue #12773. New version should be available in the next week.
It very well could be, but this error is thrown on parsing the copy - It looks like the array of strings is being parsed as an array of arrays :
"parameters": {
"solutionTypes": {
"value": [
[],
[],
. . .
[]
]
},
and that referencing parameters('solutionTypes')[copyIndex()] returns an array, not a string. Without code diving, I wouldn't be able to tell.
This is more frustrating that this wasn't caught as part of the release testing - seems that an ARM array of strings should be in your code coverage.
+1 This is still an issue in 2.6 Preview as of today and needs to be addressed please
This is the same issue as https://github.com/Azure/azure-powershell/issues/12773. The fix is included in Az 4.7.0 and it will be released in a couple of days.
@TheAlistairRoss the Az.Resources 2.6.0-preview module is actually behind the master branch, so it's expected that it still contains the regression. The preview versions are usually released by the deployment team to do some testing, and it's not recommended to install them.
Az 4.7.0 was released. Closing the issue.