Skip to content

New-AzResourceGroupDeployment -AsJob fails if TemplateParameterFile is relative path #18084

@BethanyZhou

Description

@BethanyZhou

Description

Reported from: Azure/bicep#6644

Transferring TemplateParameterFile to absolute path will be wrong if this action is after opening a new thread.

Issue script & Debug output

#Deploy_VM_parameters.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "envname": {
        "value": "testenv"
      }, 
      "location": {
        "value": "East US"
      }
    }
  } 


```bicep
#Deploy_VM.bicep
param envname string
param location string
param now string = utcNow()

resource deploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
  name: 'testparamsasjob'
  location: location
  kind: 'AzurePowerShell'
  properties: {
    azPowerShellVersion: '6.6'
    arguments: ' -envname ${envname}'
    scriptContent: '''
      param (
        [string]$envname
      )
      echo $envname

      $DeploymentScriptOutputs = @{}
      $DeploymentScriptOutputs['envName'] = $envname
    '''
    forceUpdateTag: now
    cleanupPreference: 'OnSuccess'
    retentionInterval: 'P1D'
    timeout: 'PT3M'
  }
}

output deploymentScriptOutput object = deploymentScript.properties.outputs.envName

This one fails:

New-AzResourceGroupDeployment `
-Name 'Deploy_Test_Vms' `
-TemplateFile '.\Deploy_VM.bicep' `
-TemplateParameterFile '.\Deploy_VM_parameters.json' `
-ResourceGroupName 'TestRG' -AsJob


: {14:28:38 - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The value for the template parameter 'envname' at line '14' and column '20' is not provided. Please see https://aka.ms/resource-manager-parameter-files for usage details.'. , The deployment validation failed}

These two successes:

New-AzResourceGroupDeployment `
-Name 'Deploy_Test_Vms' `
-TemplateFile '.\Deploy_VM.bicep' `
-TemplateParameterFile '.\Deploy_VM_parameters.json' `
-ResourceGroupName 'TestRG' 

New-AzResourceGroupDeployment -Name 'Deploy_Test_Vms'
-TemplateFile '.\Deploy_VM.bicep' -TemplateParameterFile 'C:\Bicep\Modules\Deploy_VM_parameters.json'
-ResourceGroupName 'TestRG' -AsJob


### Environment data

```PowerShell
N/A

Module versions

N/A

Error output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ARM - TemplatesbugThis issue requires a change to an existing behavior in the product in order to be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions