title: ARM FunctionApp listkeys retrieve previous custom key
body: <p>We've got ARM deployment template which is working fine, the only issue there is, as we're creating FunctionApp and adding custom key to it that will be referenced in API Management to connect API with FunctionApp backend. It looks like, even with <code>dependsOn</code> in backend resource in template referencing to <code>FunctionKeys</code> resource, <code>listkeys()</code> still fetches one from before deployment. Has anyone faced this scenario and is there anything in particular I'm missing? Or is <code>dependsOn</code> thinking that the key has been deployed already, and even tho future deployments update the key, backend isn't actually waiting for the completion of <code>FunctionKeys</code> resource deployment?</p>
  <p>Template snippets:</p>
  <p><code>backends</code></p>
  <pre><code>{
    &quot;type&quot;: &quot;Microsoft.ApiManagement/service/backends&quot;,
    &quot;apiVersion&quot;: &quot;2018-01-01&quot;,
    &quot;name&quot;: &quot;[concat(parameters('apiManagementServiceName'), '/', variables('functionName'))]&quot;,
    &quot;dependsOn&quot;: [
      &quot;[resourceId('Microsoft.ApiManagement/service', parameters('apiManagementServiceName'))]&quot;,
      &quot;[resourceId('Microsoft.Web/sites', variables('functionName'))]&quot;,
      &quot;[resourceId('Microsoft.Web/sites/host/functionKeys', variables('functionName'),'default','apimanagement')]&quot;
    ],
    &quot;properties&quot;: {
      &quot;url&quot;: &quot;[concat('https://', variables('functionName'), '.azurewebsites.net/api')]&quot;,
      &quot;protocol&quot;: &quot;http&quot;,
      &quot;resourceId&quot;: &quot;[concat('https://management.azure.com/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/sites/', variables('functionName'))]&quot;,
      &quot;credentials&quot;: {
        &quot;header&quot;: {
          &quot;x-functions-key&quot;: [
            &quot;[listkeys(concat(variables('functionAppId'), '/host/default/'),'2016-08-01').functionKeys.apimanagement]&quot;
          ]
        }
      }
    }
  }
  </code></pre>
  <p><code>functionKeys</code></p>
  <pre><code>{
    &quot;type&quot;: &quot;Microsoft.Web/sites/host/functionKeys&quot;,
    &quot;apiVersion&quot;: &quot;2018-11-01&quot;,
    &quot;name&quot;: &quot;[concat(variables('functionName'), '/default/apimanagement')]&quot;,
    &quot;dependsOn&quot;: [
      &quot;[resourceId('Microsoft.Web/sites', variables('functionName'))]&quot;
    ],
    &quot;properties&quot;: {
      &quot;name&quot;: &quot;apimanagement&quot;
    }
  },
  </code></pre>