title: ARM Template to create SQL Database with a privatendpoint
body: <p>I'm having errors while trying to deploy an ARM deploy with an SQL Database and its private endpoint.
  here is the code below</p>
  <pre><code>{
    &quot;$schema&quot;: &quot;https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#&quot;,
    &quot;contentVersion&quot;: &quot;1.0.0.0&quot;,
    &quot;parameters&quot;: {
      &quot;sqlAdministratorLogin&quot;: {
        &quot;type&quot;: &quot;string&quot;,
        &quot;metadata&quot;: {
          &quot;description&quot;: &quot;The administrator username of the SQL logical server&quot;
        }
      },
      &quot;sqlAdministratorLoginPassword&quot;: {
        &quot;type&quot;: &quot;securestring&quot;,
        &quot;metadata&quot;: {
          &quot;description&quot;: &quot;The administrator password of the SQL logical server.&quot;
        }
      },
     
      &quot;location&quot;: {
        &quot;type&quot;: &quot;string&quot;,
        &quot;defaultValue&quot;: &quot;[resourceGroup().location]&quot;,
        &quot;metadata&quot;: {
          &quot;description&quot;: &quot;Location for all resources.&quot;
        }
      }
    },
    &quot;variables&quot;: {
      &quot;vnetName&quot;: &quot;powerStateManagement-vnet&quot;,
      &quot;subnet1Name&quot;: &quot;default&quot;,
      &quot;sqlServerName&quot;: &quot;[concat('sqlserver', uniqueString(resourceGroup().id))]&quot;,
      &quot;databaseName&quot;: &quot;[concat(variables('sqlServerName'),'/sample-db')]&quot;,
      &quot;privateEndpointName&quot;: &quot;myPrivateEndpoint&quot;,
      &quot;privateDnsZoneName&quot;: &quot;[concat('privatelink', environment().suffixes.sqlServerHostname)]&quot;,
      &quot;pvtendpointdnsgroupname&quot;: &quot;[concat(variables('privateEndpointName'),'/mydnsgroupname')]&quot;,
      &quot;vnetResourceGroup&quot;:&quot;powerStateManagement&quot;
    },
    &quot;resources&quot;: [
      {
        &quot;type&quot;: &quot;Microsoft.Sql/servers&quot;,
        &quot;apiVersion&quot;: &quot;2020-02-02-preview&quot;,
        &quot;name&quot;: &quot;[variables('sqlServerName')]&quot;,
        &quot;location&quot;: &quot;[parameters('location')]&quot;,
        &quot;kind&quot;: &quot;v12.0&quot;,
        &quot;tags&quot;: {
          &quot;displayName&quot;: &quot;[variables('sqlServerName')]&quot;
        },
        &quot;properties&quot;: {
          &quot;administratorLogin&quot;: &quot;[parameters('sqlAdministratorLogin')]&quot;,
          &quot;administratorLoginPassword&quot;: &quot;[parameters('sqlAdministratorLoginPassword')]&quot;,
          &quot;version&quot;: &quot;12.0&quot;,
          &quot;publicNetworkAccess&quot;: &quot;Disabled&quot;
        },
        &quot;resources&quot;: [
        ]
      },
      {
        &quot;type&quot;: &quot;Microsoft.Sql/servers/databases&quot;,
        &quot;apiVersion&quot;: &quot;2020-02-02-preview&quot;,
        &quot;name&quot;: &quot;[variables('databaseName')]&quot;,
        &quot;location&quot;: &quot;[parameters('location')]&quot;,
        &quot;sku&quot;: {
          &quot;name&quot;: &quot;Basic&quot;,
          &quot;tier&quot;: &quot;Basic&quot;,
          &quot;capacity&quot;: 5
        },
        &quot;dependsOn&quot;: [
          &quot;[resourceId('Microsoft.Sql/servers', variables('sqlServerName'))]&quot;
        ],
        &quot;tags&quot;: {
          &quot;displayName&quot;: &quot;[variables('databaseName')]&quot;
        },
        &quot;properties&quot;: {
          &quot;collation&quot;: &quot;SQL_Latin1_General_CP1_CI_AS&quot;,
          &quot;edition&quot;: &quot;Basic&quot;,
          &quot;maxSizeBytes&quot;: 104857600,
          &quot;requestedServiceObjectiveName&quot;: &quot;Basic&quot;,
          &quot;sampleName&quot;: &quot;AdventureWorksLT&quot;
        }
      },
      {
        &quot;type&quot;: &quot;Microsoft.Network/privateEndpoints&quot;,
        &quot;apiVersion&quot;: &quot;2020-06-01&quot;,
        &quot;name&quot;: &quot;[variables('privateEndpointName')]&quot;,
        &quot;location&quot;: &quot;[parameters('location')]&quot;,
        &quot;dependsOn&quot;: [
          &quot;[variables('vnetName')]&quot;,
          &quot;[variables('sqlServerName')]&quot;
        ],
        &quot;properties&quot;: {
          &quot;subnet&quot;: {
            &quot;id&quot;: &quot;[resourceId(variables('vnetResourceGroup'),'/','Microsoft.Network/virtualNetworks','/',variables('vnetName'),'/',variables('subnet1Name'))]&quot;
          },
          &quot;privateLinkServiceConnections&quot;: [
            {
              &quot;name&quot;: &quot;[variables('privateEndpointName')]&quot;,
              &quot;properties&quot;: {
                &quot;privateLinkServiceId&quot;: &quot;[resourceId('Microsoft.Sql/servers',variables('sqlServerName'))]&quot;,
                &quot;groupIds&quot;: [
                  &quot;sqlServer&quot;
                ]
              }
            }
          ]
        }
      },
  
      {
        &quot;type&quot;: &quot;Microsoft.Network/privateDnsZones/virtualNetworkLinks&quot;,
        &quot;apiVersion&quot;: &quot;2020-01-01&quot;,
        &quot;name&quot;: &quot;[concat(variables('privateDnsZoneName'), '/', variables('privateDnsZoneName'), '-link')]&quot;,
        &quot;location&quot;: &quot;global&quot;,
        &quot;dependsOn&quot;: [
          &quot;[resourceId('Microsoft.Network/privateDnsZones', variables('privateDnsZoneName'))]&quot;,
            &quot;[resourceId(variables('vnetResourceGroup'),'Microsoft.Network/virtualNetworks',variables('vnetName'))]&quot;
        ],
        &quot;properties&quot;: {
          &quot;registrationEnabled&quot;: false,
          &quot;virtualNetwork&quot;: {
            &quot;id&quot;: &quot;/subscriptions/*****/resourceGroups/powerStateManagement/providers/Microsoft.Network/virtualNetworks/powerStateManagement-vnet&quot;
          }
        }
      },
      {
        &quot;type&quot;: &quot;Microsoft.Network/privateEndpoints/privateDnsZoneGroups&quot;,
        &quot;apiVersion&quot;: &quot;2020-06-01&quot;,
        &quot;name&quot;: &quot;[variables('pvtendpointdnsgroupname')]&quot;,
        &quot;location&quot;: &quot;[parameters('location')]&quot;,
        &quot;dependsOn&quot;: [
          &quot;[resourceId('Microsoft.Network/privateDnsZones', variables('privateDnsZoneName'))]&quot;,
          &quot;[variables('privateEndpointName')]&quot;
        ],
        &quot;properties&quot;: {
          &quot;privateDnsZoneConfigs&quot;: [
            {
              &quot;name&quot;: &quot;config1&quot;,
              &quot;properties&quot;: {
                &quot;privateDnsZoneId&quot;: &quot;[resourceId('Microsoft.Network/privateDnsZones', variables('privateDnsZoneName'))]&quot;
              }
            }
          ]
        }
      }
    ]
  }
  </code></pre>
  <p>The challenge here is that when I try to run this code I always get this error</p>
  <pre><code>Deployment template validation failed: 'The template reference 'powerStateManagement-vnet' is not valid: could not find template resource or resource copy with this name.
  </code></pre>
  <p>The ''powerStateManagement-vnet' is an existing Virtual Network which has been referenced below</p>
  <pre><code>{
        &quot;type&quot;: &quot;Microsoft.Network/privateDnsZones/virtualNetworkLinks&quot;,
        &quot;apiVersion&quot;: &quot;2020-01-01&quot;,
        &quot;name&quot;: &quot;[concat(variables('privateDnsZoneName'), '/', variables('privateDnsZoneName'), '-link')]&quot;,
        &quot;location&quot;: &quot;global&quot;,
        &quot;dependsOn&quot;: [
          &quot;[resourceId('Microsoft.Network/privateDnsZones', variables('privateDnsZoneName'))]&quot;,
            &quot;[resourceId(variables('vnetResourceGroup'),'Microsoft.Network/virtualNetworks',variables('vnetName'))]&quot;
        ],
        &quot;properties&quot;: {
          &quot;registrationEnabled&quot;: false,
          &quot;virtualNetwork&quot;: {
            &quot;id&quot;: &quot;/subscriptions/*****/resourceGroups/powerStateManagement/providers/Microsoft.Network/virtualNetworks/powerStateManagement-vnet&quot;
          }
        }
      }
  </code></pre>
  <p>Please help</p>