title: DevOps Pipeline AzureCLI@2 with dynamic azureSubscription
body: <p>I have a DevOps pipeline that gives me this error:</p>
  <blockquote>
  <p><strong>There was a resource authorization issue:</strong> &quot;The pipeline is not valid. Job ExecutionTerraform: Step AzureCLI input connectedServiceNameARM references service connection Azure: $(subscriptionName) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to <a href="https://aka.ms/yamlauthz.%22" rel="nofollow noreferrer">https://aka.ms/yamlauthz.&quot;</a></p>
  </blockquote>
  <p>The configuration I am using is looking up the <em>Subscription</em> name dynamically.</p>
  <p>The step I use for that is:</p>
  <pre class="lang-yaml prettyprint-override"><code>- bash: |
      # pull the subscription data
      # ... read data into local variables
  
      # set the shared variables
      echo &quot;##vso[task.setvariable variable=subscriptionId]${SUBSCRIPTION_ID}&quot;
      echo &quot;##vso[task.setvariable variable=subscriptionName]${SUBSCRIPTION_NAME}&quot;
  </code></pre>
  <p>From there I attempt to call the Azure CLI via a template:</p>
  <pre class="lang-yaml prettyprint-override"><code>- template: execution-cli.yml
    parameters:
      azureSubscriptionId: $(subscriptionId)
      azureSubscriptionName: $(subscriptionName)
  </code></pre>
  <p>Inside the template my CLI step uses:</p>
  <pre class="lang-yaml prettyprint-override"><code>steps:
    - task: AzureCLI@2
      displayName: Test CLI
      inputs:
        azureSubscription: &quot;ARMTest ${{ parameters.azureSubscriptionName }}&quot;
        scriptType: bash
        scriptLocation: inlineScript
        inlineScript: |
          az --version
        addSpnToEnvironment: true
        useGlobalConfig: true
  </code></pre>
  <p>It looks like Pipelines is trying to preemptively check authorization without noticing that there's a variable in there. What am I doing wrong here that is causing Azure to attempt to resolve that at the wrong time?</p>
  <p>I do this in other pipelines without issues and I am not sure what is different in this particular instance.</p>
  <h2>Update 1: Working Template I have Elsewhere</h2>
  <p>Full template:</p>
  <pre class="lang-yaml prettyprint-override"><code>parameters:
    - name: environment
      type: string
  
  jobs:
    - job: AKSCredentials
      displayName: &quot;AKS Credentials Pull&quot;
      steps:
        - task: AzureCLI@2
          displayName: AKS Credentials
          inputs:
            azureSubscription: &quot;Azure: testbed-${{ parameters.environment }}&quot;
            scriptType: bash
            scriptLocation: inlineScript
            inlineScript: az aks get-credentials -g testbed-${{ parameters.environment }} -n testbed-${{ parameters.environment }}-aks
            addSpnToEnvironment: true
            useGlobalConfig: true
  </code></pre>