DaveVentura
DaveVentura

Reputation: 770

Bicep deployment script ERROR: argument --query: invalid jmespath_type value: '"[?contains(name,'. Please refer to

I want to get the dynamic name of a vmss in bicep via deployment script. There two vmss, i want to filter the name with --query.

var azCommandGetVmmsName = 
'az vmss list --resource-group ${rgMcName} --query "[?contains(name, \'workloadpool\')].name" -o tsv'

resource deploymentScript 'Microsoft.Resources/deploymentScripts@2023-08-01' = {
  name: 'assign-identity-to-nodepool'
  identity:  {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${identityAssginmentIdentity.id}': {}
    }
  }
  location: location
  kind: 'AzureCLI'
  properties: {
    azCliVersion: '2.52.0'
    environmentVariables: [
      {
        name: 'COMMAND'
        value: azCommandGetVmmsName
      }
    ]
    scriptContent: '''
      vmmsName=$COMMAND
      echo "name: $vmssName"
    '''
    retentionInterval: 'PT1H'
    cleanupPreference: 'OnSuccess'
  }

If i run the command locally in powershell and as well in ubuntu wsl, it brings the expected result:

az vmss list --resource-group  MC_(...)_westeurope --query "[?contains(name, 'workloadpool')].name" -o tsv
-> aks-workloadpool-40863341-vmss

but in the script in azure i get this error:

The provided script failed with multiple errors. First error:
ERROR: argument --query: invalid jmespath_type value: 
'"[?contains(name,'. Please refer to https://aka.ms/DeploymentScriptsTroubleshoot 
for more deployment script information. (Code: DeploymentScriptError), 
ERROR: argument --query: invalid jmespath_type value: '"[?contains(name,' (Code: DeploymentScriptError), 
To learn more about --query, 
please visit: 'https://docs.microsoft.com/cli/azure/query-azure-cli' (Code: DeploymentScriptError)

The COMMAND env var is resolved properly: env var of the script in azure

Maybe the single quote is interpreted as the end of the value for --query? How can I get around this?

Upvotes: 0

Views: 139

Answers (1)

DaveVentura
DaveVentura

Reputation: 770

Ok i solved it by bringing the command in to the script content without variable, but maybe some one can tell why that happend before:

resource deploymentScript 'Microsoft.Resources/deploymentScripts@2023-08-01' = {
  name: 'assign-identity-to-nodepool'
  identity:  {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '${identityAssginmentIdentity.id}': {}
    }
  }
  location: location
  kind: 'AzureCLI'
  properties: {
    azCliVersion: '2.52.0'
    environmentVariables: [
      {
        name: 'RG'
        value: resourceGroupName
      }
    ]
    scriptContent: '''
      vmmsName=$(az vmss list --resource-group $RGMC --query "[?contains(name, 'workloadpool')].name" -o tsv)
      echo "name: $vmssName"
    '''
    retentionInterval: 'PT1H'
    cleanupPreference: 'OnSuccess'
  }

Upvotes: 0

Related Questions