I'm using the New-AzureRmResourceGroupDeployment Powershell cmdlet to deploy to a resource group using an Azure Resource Template. This is a test environment, so I want to restore a database from a .bacpac file to seed the database with a realistic volume of data.

The following snippet deploys successfully on the first deployment to this resource group, because there isn't an existing database, but fails on any subsequent deployment.

```
{
                "name": "[variables('databaseName')]",
                "type": "databases",
                "location": "[resourceGroup().location]",
                "apiVersion": "2014-04-01-preview",
                "dependsOn": [
                    "[variables('databaseServerName')]",
                    "[concat('Microsoft.Sql/servers/', variables('databases.ServerName'))]"
                ],
                "tags": {
                    "displayName": "testDatabase"
                },
                "properties": {
                    "collation": "[variables('databaseCollation')]",
                    "edition": "[variables('databaseEdition')]",
                    "maxSizeBytes": "1073741824",
                    "requestedServiceObjectiveName": "[variables('databaseServicePlan')]"
                },
                "resources": [
                    {
                        "name": "Import",
                        "type": "extensions",
                        "apiVersion": "2014-04-01-preview",
                        "dependsOn": [
                            "[variables('databaseName')]"
                        ],
                        "properties": {
                            "storageKeyType": "[variables('databaseBackupStorageKeyType')]",
                            "storageKey": "[parameters('databaseBackupStorageKey')]",
                            "storageUri": "[concat(parameters('databaseBackupStorageLocation'), '/', parameters('backupFileName'))]",
                            "administratorLogin": "[variables('databaseAdminLogin')]",
                            "administratorLoginPassword": "[variables('databaseAdminPassword')]",
                            "operationMode": "Import"
                        }
                    }
                ]
            }

```

The error when failure occurs:

```
Resource Microsoft.Sql/servers/databases/extensions '[resource-group-name]/[database-name]/Import' failed with message 'The ImportExport operation with Request Id 'b1f54bdd-6c98-4feb-a86f-656a5c6f1cc5' failed due to 'Error encountered during the service operation. 

Data cannot be imported into target because it contains one or more user objects. Import should be performed against a new, empty database.

```

Perhaps I've misunderstood how these templates are deployed - I thought ARM patched the environment. Does anyone know of a way I can inform ARM to only create / update the database (and sub-resources) if the configuration for those resources have changed?

Alternatively, if there's a better way to restore a database using a resource template I'd love to hear about it.

Any help or advice greatly appreciated!

Thanks in advance,

Rob