title: How do you reference a resource name in a deployIfNotExists azure policy?
body: <p>Below is a sample azure policy json that looks at all the storage accounts and deployIfNotExists the allowBlobPublicAccess settings to true. How do you ensure that the name field in every arm template gets the name of storage account resource?</p>
  <p>Some additional context: Template Functions <a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource#resourceid" rel="nofollow noreferrer">1</a> does not seem to work well. If trying to use resourceId().resourceName1, I get an error</p>
  <blockquote>
  <p>InvalidTemplate Message   Deployment template validation failed: 'The
  template resource '[resourceId().resourceName1]' at line '1' and
  column '207' is not valid: Unable to evaluate template language
  function 'resourceId': function requires at least '2' argument(s)
  while '0' were provided. Please see
  <a href="https://aka.ms/arm-template-expressions/#resourceid" rel="nofollow noreferrer">https://aka.ms/arm-template-expressions/#resourceid</a> for usage
  details.. Please see <a href="https://aka.ms/arm-template-expressions" rel="nofollow noreferrer">https://aka.ms/arm-template-expressions</a> for usage
  details.'.</p>
  </blockquote>
  <pre><code>{
        &quot;mode&quot;: &quot;All&quot;,
        &quot;policyRule&quot;: {
          &quot;if&quot;: {
            &quot;allOf&quot;: [
              {
                &quot;field&quot;: &quot;type&quot;,
                &quot;equals&quot;: &quot;Microsoft.Storage/storageAccounts&quot;
              }
            ]
          },
          &quot;then&quot;: {
            &quot;effect&quot;: &quot;deployIfNotExists&quot;,
            &quot;details&quot;: {
              &quot;type&quot;: &quot;Microsoft.Storage/storageAccounts&quot;,
              &quot;existenceCondition&quot;: {
                &quot;allOf&quot;: [
                  {
                    &quot;field&quot;: &quot;Microsoft.Storage/storageAccounts/allowBlobPublicAccess&quot;,
                    &quot;equals&quot;: &quot;true&quot;
                  }
                ]
              },
              &quot;roleDefinitionIds&quot;: [
                &quot;/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c&quot;
              ],
              &quot;deployment&quot;: {
                &quot;properties&quot;: {
                  &quot;mode&quot;: &quot;incremental&quot;,
                  &quot;template&quot;: {
                    &quot;$schema&quot;: &quot;https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#&quot;,
                    &quot;contentVersion&quot;: &quot;1.0.0.0&quot;,
                    &quot;resources&quot;: [
                      {
                        &quot;type&quot;: &quot;Microsoft.Storage/storageAccounts&quot;,
                        &quot;name&quot;: **&quot;[resourceId().name]&quot;,**
                        &quot;apiVersion&quot;: &quot;2022-03-01&quot;,
                        &quot;location&quot;: &quot;canadacentral&quot;,
                        &quot;properties&quot;: {
                           &quot;allowBlobPublicAccess&quot;: &quot;true&quot;
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        &quot;parameters&quot;: {}
      }
  </code></pre>