Skip to content

Test-AzResourceGroupDeployment does not return validation output or error properly #27594

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

Open
AlanWheelwright opened this issue Apr 17, 2025 · 2 comments
Labels
ARM - Templates bug This issue requires a change to an existing behavior in the product in order to be resolved. Service Attention This issue is responsible by Azure service team.

Comments

@AlanWheelwright
Copy link

AlanWheelwright commented Apr 17, 2025

Description

Test-AzResourceGroupDeployment does not return a powershell object of any kind and it's result is not capturable into a powershell variable for some reason.

$TestResult = Test-AzResourceGroupDeployment
Will result in $TestResult containing nothing when the validation test was successful even when set to verbose and a verbose output is displayed:
"VERBOSE: 12:44:15 PM - Template is valid."

$TestResult = Test-AzResourceGroupDeployment
Will result in $TestResult containing a single return character when the validation test was unsuccessful but verbose, no matter what the error or how many.

Even attempting to direct the error output into a variable via -ErrorVariable
Test-AzResourceGroupDeployment -ErrorVariable $TemplateValidationErrorVariable

results in $TemplateValidationErrorVariable being empty.

Issue script & Debug output

$ArmTemplateValidationParameters = @{
        ResourceGroupName = $TargetResourceGroupName
        TemplateFile =  "$FullTemplatePath"
        #Standard Parameters
        Mode = 'Incremental'
        Verbose = $true
        ErrorAction = 'Stop'
        WarningAction = 'Stop'
        ErrorVariable = $TemplateValidationError
    }
    Try {$ValidationResult = Test-AzResourceGroupDeployment @ArmTemplateValidationParameters
    } Catch {
        Write-Error "Template is Invalid!"
        $TemplateValidationSuccess = $false
    }

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     4.0.2                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     9.1.0                 Az.Compute                          {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendContent, Add-AzVMDataDisk…}
Script     7.9.0                 Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}

Error output

HistoryId: 574

Message        : Invalid character after parsing property name. Expected ':' but got: C. Path 'resources[0].type', line 10, position 9.
StackTrace     :    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo
                 capturedException)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : Newtonsoft.Json.JsonReaderException
InvocationInfo : {Test-AzResourceGroupDeployment}
Line           :     $ValidationResult = $(Test-AzResourceGroupDeployment @ArmTemplateValidationParameters)

Position       : At line:23 char:27
                 + … nResult = $(Test-AzResourceGroupDeployment @ArmTemplateValidationPara+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 574

Message        : Template is Invalid!
StackTrace     :
Exception      : Microsoft.PowerShell.Commands.WriteErrorException
InvocationInfo : {If ($null -ne $TemplateContent){
                     #The template variable isn't empty, so validate the template file
                     $TemplateImportSuccess = $true
                     $ArmTemplateValidationParameters = @{
                         ResourceGroupName = $TargetResourceGroupName
                         TemplateFile =  "$FullExportedTemplatePath"
                         #Standard Parameters
                         Mode = 'Incremental'
                         Verbose = $true
                         ErrorAction = 'Stop'
                         WarningAction = 'Stop'
                         ErrorVariable = $TemplateValidationError
                     }
                     Try {$ValidationResult = Test-AzResourceGroupDeployment @ArmTemplateValidationParameters} Catch {
                         Write-Error "Template is Invalid!"
                         $TemplateValidationSuccess = $false
                         $TemplateImportSuccess = $false
                     }

                     #Use the validation result to determine the template validity
                     $ValidationResult = $(Test-AzResourceGroupDeployment @ArmTemplateValidationParameters)

                     IF ($(Test-AzResourceGroupDeployment @ArmTemplateValidationParameters) -match $TemplateValidationResultFailureRegexPattern) {
                         Write-Error "Template is Invalid Regex!"
                         $TemplateImportSuccess = $false
                     }

                 }}
Line           :
Position       :
HistoryId      : 574

Message        : Invalid character after parsing property name. Expected ':' but got: C. Path 'resources[0].type', line 10, position 9.
StackTrace     :    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo
                 capturedException)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : Newtonsoft.Json.JsonReaderException
InvocationInfo : {Test-AzResourceGroupDeployment}
Line           :     Try {$ValidationResult = Test-AzResourceGroupDeployment @ArmTemplateValidationParameters

Position       : At line:15 char:30
                 + … ionResult = Test-AzResourceGroupDeployment @ArmTemplateValidationPara+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 574
@AlanWheelwright AlanWheelwright added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Apr 17, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Apr 17, 2025
@dolauli dolauli added ARM - Templates Service Attention This issue is responsible by Azure service team. and removed customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Apr 24, 2025
Copy link
Contributor

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/deployments-owners.

1 similar comment
Copy link
Contributor

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/deployments-owners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM - Templates bug This issue requires a change to an existing behavior in the product in order to be resolved. Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants